CI / go (Server) (push) Successful in 12m46s
CI / go (Web-App) (push) Successful in 10m4s
CI / desktop (ubuntu-latest) (push) Failing after 5m33s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
CI / mobile (push) Failing after 36s
CI / docker (push) Successful in 9m13s
CI / frontend (push) Failing after 6m9s
The web and desktop app now ships German, French and Spanish next to English and Polish. Account settings has a language picker kept per device like the theme; without a choice the app follows the browser's languages. The <html lang> follows the chosen language, and a test keeps every language's keys and placeholders in step with English. The mobile reader applies each page's width and font through a new setLayout bridge message, using the web reader's column widths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
2.5 KiB
Dart
85 lines
2.5 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("sends the page's width and font", () async {
|
|
await bridge.setLayout(fullWidth: true, font: 'serif');
|
|
expect(sent.last, {'type': 'setLayout', 'fullWidth': true, 'font': 'serif'});
|
|
});
|
|
|
|
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");
|
|
});
|
|
}
|