Files
BadNote/test/l10n_test.dart

62 lines
2.0 KiB
Dart
Raw Normal View History

// Proves i18n is real, not just wired: the SAME widget resolves English under
// Locale('en') and Chinese under Locale('zh'), through the generated
// AppLocalizations delegates. Guards against ARB keys drifting out of sync.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:badnote/l10n/app_localizations.dart';
class _Probe extends StatelessWidget {
const _Probe();
@override
Widget build(BuildContext context) {
final l = AppLocalizations.of(context);
return Directionality(
textDirection: TextDirection.ltr,
child: Column(children: [
Text(l.settings),
Text(l.toolEraser),
Text(l.importPdf),
Text(l.themeSystem),
Text(l.searchHint),
]),
);
}
}
Future<void> _pump(WidgetTester tester, Locale locale) {
return tester.pumpWidget(MaterialApp(
locale: locale,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: const _Probe(),
));
}
void main() {
testWidgets('English locale resolves English strings', (tester) async {
await _pump(tester, const Locale('en'));
expect(find.text('Settings'), findsOneWidget);
expect(find.text('Eraser'), findsOneWidget);
expect(find.text('Import PDF'), findsOneWidget);
expect(find.text('System'), findsOneWidget);
expect(find.text('Search notes and documents...'), findsOneWidget);
});
testWidgets('Chinese locale resolves Chinese strings', (tester) async {
await _pump(tester, const Locale('zh'));
expect(find.text('设置'), findsOneWidget);
expect(find.text('橡皮擦'), findsOneWidget);
expect(find.text('导入 PDF'), findsOneWidget);
expect(find.text('跟随系统'), findsOneWidget);
expect(find.text('搜索笔记和文档…'), findsOneWidget);
});
test('both locales are supported', () {
final langs =
AppLocalizations.supportedLocales.map((l) => l.languageCode).toSet();
expect(langs.containsAll({'en', 'zh'}), isTrue);
});
}