Parcourir la source

fix: add simple test for l10n

Lucas.Xu il y a 2 ans
Parent
commit
8137769edd

+ 3 - 0
frontend/app_flowy/packages/appflowy_editor/pubspec.yaml

@@ -29,6 +29,9 @@ dev_dependencies:
     sdk: flutter
   flutter_lints: ^2.0.1
   network_image_mock: ^2.1.1
+  flutter_localizations:
+    sdk: flutter
+
 
 # For information on the generic Dart part of this file, see the
 # following page: https://dart.dev/tools/pub/pubspec

+ 8 - 1
frontend/app_flowy/packages/appflowy_editor/test/infra/test_editor.dart

@@ -3,6 +3,7 @@ import 'dart:collection';
 import 'package:appflowy_editor/appflowy_editor.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
+import 'package:flutter_localizations/flutter_localizations.dart';
 import 'package:flutter_test/flutter_test.dart';
 
 import 'test_raw_key_event.dart';
@@ -22,12 +23,18 @@ class EditorWidgetTester {
   Selection? get documentSelection =>
       _editorState.service.selectionService.currentSelection.value;
 
-  Future<EditorWidgetTester> startTesting() async {
+  Future<EditorWidgetTester> startTesting({
+    Locale locale = const Locale('en'),
+  }) async {
     final app = MaterialApp(
       localizationsDelegates: const [
+        GlobalMaterialLocalizations.delegate,
+        GlobalCupertinoLocalizations.delegate,
+        GlobalWidgetsLocalizations.delegate,
         AppFlowyEditorLocalizations.delegate,
       ],
       supportedLocales: AppFlowyEditorLocalizations.delegate.supportedLocales,
+      locale: locale,
       home: Scaffold(
         body: AppFlowyEditor(
           editorState: _editorState,

+ 19 - 0
frontend/app_flowy/packages/appflowy_editor/test/l10n/l10n_test.dart

@@ -0,0 +1,19 @@
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:flutter_test/flutter_test.dart';
+import '../infra/test_editor.dart';
+
+void main() async {
+  setUpAll(() {
+    TestWidgetsFlutterBinding.ensureInitialized();
+  });
+
+  group('l10n.dart', () {
+    for (final locale
+        in AppFlowyEditorLocalizations.delegate.supportedLocales) {
+      testWidgets('test localization', (tester) async {
+        final editor = tester.editor..insertTextNode('');
+        await editor.startTesting(locale: locale);
+      });
+    }
+  });
+}