2026-06-23 09:35:26 +08:00
|
|
|
// 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),
|
2026-06-23 10:03:02 +08:00
|
|
|
Text(l.themeSystem),
|
|
|
|
|
Text(l.searchHint),
|
2026-06-23 09:35:26 +08:00
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2026-06-23 10:03:02 +08:00
|
|
|
expect(find.text('System'), findsOneWidget);
|
|
|
|
|
expect(find.text('Search notes and documents...'), findsOneWidget);
|
2026-06-23 09:35:26 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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);
|
2026-06-23 10:03:02 +08:00
|
|
|
expect(find.text('跟随系统'), findsOneWidget);
|
|
|
|
|
expect(find.text('搜索笔记和文档…'), findsOneWidget);
|
2026-06-23 09:35:26 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('both locales are supported', () {
|
|
|
|
|
final langs =
|
|
|
|
|
AppLocalizations.supportedLocales.map((l) => l.languageCode).toSet();
|
|
|
|
|
expect(langs.containsAll({'en', 'zh'}), isTrue);
|
|
|
|
|
});
|
|
|
|
|
}
|