Repository basics: - CONTRIBUTING.md and CODE_OF_CONDUCT.md (Contributor Covenant 2.1) - SPDX AGPL-3.0-or-later headers on all hand-written sources, checked in CI - golangci-lint (shared .golangci.yml), ESLint and Prettier, all run in CI API codegen from api/openapi.yaml (npm run generate, drift fails CI): - Go types via oapi-codegen in Server/internal/api - a contract test that the router and the spec list the same routes - Dart models via Phone-App/tool/generate_api.dart; the app uses them Spike: shared Tiptap editor in a Flutter WebView (ADR-4) - @docwell/editor-bridge builds the editor into one HTML page with a versioned JSON protocol; Phone-App hosts it with webview_flutter and a native toolbar. Integration test passes on an Android API 35 emulator. - flutter_inappwebview dropped: its Android plugin fails on AGP 9. Spike: Wails v3 desktop (ADR-11) - system tray, docwell:// deep links (page and space only) with single-instance hand-off, and the built-in updater with a required ed25519 signing key. Verified on Windows. - regenerated build assets register the scheme and drop template placeholders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
79 lines
2.4 KiB
Dart
79 lines
2.4 KiB
Dart
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
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',
|
|
'avatar': '',
|
|
'locale': 'en',
|
|
'theme': 'system',
|
|
'status': 'active',
|
|
'verified': true,
|
|
'created': '2026-10-01 09:00:00.000Z',
|
|
'role': 'admin',
|
|
'organization': 'o1',
|
|
'organizationName': 'Acme',
|
|
};
|
|
|
|
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('Admin · Acme'), 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);
|
|
});
|
|
}
|