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>
80 lines
2.3 KiB
Dart
80 lines
2.3 KiB
Dart
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:docwell_mobile/editor/bridge.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
/// Decodes what the bridge asked the page to receive.
|
|
Map<String, dynamic> sentMessage(String script) {
|
|
final m = RegExp(
|
|
r'^window\.docwell\.receive\((.*)\)$',
|
|
dotAll: true,
|
|
).firstMatch(script)!;
|
|
return jsonDecode(jsonDecode(m[1]!) as String) as Map<String, dynamic>;
|
|
}
|
|
|
|
void main() {
|
|
const doc = {
|
|
'type': 'doc',
|
|
'content': [
|
|
{'type': 'paragraph'},
|
|
],
|
|
};
|
|
|
|
late List<Map<String, dynamic>> sent;
|
|
late EditorBridge bridge;
|
|
setUp(() {
|
|
sent = [];
|
|
bridge = EditorBridge(
|
|
content: doc,
|
|
evaluate: (js) async => sent.add(sentMessage(js)),
|
|
);
|
|
});
|
|
|
|
test('loads the content once the page is ready, only once', () async {
|
|
bridge.handleMessage('{"type":"ready","version":$editorProtocolVersion}');
|
|
bridge.handleMessage('{"type":"ready","version":$editorProtocolVersion}');
|
|
await bridge.ready;
|
|
expect(bridge.isReady, isTrue);
|
|
expect(sent, [
|
|
{'type': 'setContent', 'content': doc},
|
|
]);
|
|
});
|
|
|
|
test('refuses a page that speaks another protocol version', () {
|
|
bridge.handleMessage('{"type":"ready","version":99}');
|
|
expect(bridge.isReady, isFalse);
|
|
expect(bridge.error, contains('protocol 99'));
|
|
});
|
|
|
|
test('sends commands and tracks content and toolbar state', () async {
|
|
final changes = <Map<String, dynamic>>[];
|
|
bridge.changes.listen(changes.add);
|
|
|
|
await bridge.run(EditorCommand.bold);
|
|
bridge.handleMessage(
|
|
'{"type":"state","state":{"active":["bold","heading2","future"],'
|
|
'"canUndo":true,"canRedo":false,"focused":true}}',
|
|
);
|
|
bridge.handleMessage('{"type":"change","content":{"type":"doc"}}');
|
|
await Future<void>.delayed(Duration.zero);
|
|
|
|
expect(sent.last, {'type': 'command', 'command': 'bold'});
|
|
expect(bridge.state.active, {EditorCommand.bold, EditorCommand.heading2});
|
|
expect(bridge.state.canUndo, isTrue);
|
|
expect(bridge.content, {'type': 'doc'});
|
|
expect(changes, [
|
|
{'type': 'doc'},
|
|
]);
|
|
});
|
|
|
|
test('escapes content safely into the script', () async {
|
|
await bridge.setContent({
|
|
'type': 'doc',
|
|
'text': "it's \"quoted\" </script> \u2028",
|
|
});
|
|
expect(sent.last['content']['text'], "it's \"quoted\" </script> \u2028");
|
|
});
|
|
}
|