Files
Docwell/Phone-App/test/widget_test.dart
T
tajniak81andClaude Opus 5.5 4903bb12dd Scaffold Docwell monorepo with PocketBase authentication
Phase 0 foundation for Docwell, an open-source knowledge base:

- Database: PocketBase v0.40.6 with initial schema migrations; users is
  the built-in auth collection, plus a hook for token checks and
  env-driven app URL/SMTP settings
- Server: Go API (health, version, auth endpoints forwarded to
  PocketBase, admin user list) with an embedded Vue admin panel
- Web-App: Go static server and Vue/Tailwind app with Tiptap editor,
  sign-in, sign-up, password reset and email verification (EN/PL)
- Desktop-App: Wails v3 host reusing the web app
- Phone-App: Flutter app with sign-in
- Shared packages (editor, ui, api-client), OpenAPI spec, Docker
  compose (separate services and all-in-one), GitHub Actions CI
- Docs: feature inventory and architecture/build plan

Licensed under AGPL-3.0-or-later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 22:18:25 +01:00

57 lines
2.2 KiB
Dart

import 'dart:convert';
import 'package:docwell_mobile/api/docwell_api.dart';
import 'package:docwell_mobile/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart' as http;
import 'package:http/testing.dart';
const ann = {'id': 'u1', 'email': 'ann@docwell.test', 'name': 'Ann', 'isAdmin': true};
http.Response json(int status, Object body) =>
http.Response(jsonEncode(body), status, headers: {'content-type': 'application/json'});
DocwellApi fakeApi() => DocwellApi('http://server.test/', client: MockClient((req) async {
switch (req.url.path) {
case '/api/v1/auth/login':
final body = jsonDecode(req.body) as Map<String, dynamic>;
if (body['password'] == 'password123') {
return json(200, {'token': 'tok', 'user': ann});
}
return json(401, {'error': 'invalid_credentials'});
case '/api/v1/version':
return req.headers['Authorization'] == 'Bearer tok'
? json(200, {'name': 'docwell-server', 'version': '1.0.0'})
: json(401, {'error': 'unauthorized'});
}
return json(404, {'error': 'not_found'});
}));
Future<void> signIn(WidgetTester tester, String password) async {
await tester.enterText(find.byKey(const Key('email')), 'ann@docwell.test');
await tester.enterText(find.byKey(const Key('password')), password);
await tester.tap(find.widgetWithText(FilledButton, 'Sign in'));
await tester.pumpAndSettle();
}
void main() {
testWidgets('signs in, shows the user, and signs out', (tester) async {
await tester.pumpWidget(DocwellApp(api: fakeApi()));
await signIn(tester, 'password123');
expect(find.text('Hello, Ann'), findsOneWidget);
expect(find.text('Connected · v1.0.0'), findsOneWidget);
await tester.tap(find.text('Sign out'));
await tester.pumpAndSettle();
expect(find.text('Sign in to Docwell'), findsOneWidget);
});
testWidgets('shows an error for a wrong password', (tester) async {
await tester.pumpWidget(DocwellApp(api: fakeApi()));
await signIn(tester, 'wrong');
expect(find.text('Wrong email or password.'), findsOneWidget);
});
}