58 lines
2 KiB
Dart
58 lines
2 KiB
Dart
|
|
import 'package:flutter_test/flutter_test.dart';
|
||
|
|
import 'package:halkyon_app/halkyon_app.dart';
|
||
|
|
import 'package:material_ui/material_ui.dart';
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
/// The languages a Halkyon app speaks: British English (the template, as
|
||
|
|
/// `en` and `en-GB`), American English and German.
|
||
|
|
const supported = [
|
||
|
|
Locale('en'),
|
||
|
|
Locale('de'),
|
||
|
|
Locale('en', 'GB'),
|
||
|
|
Locale('en', 'US'),
|
||
|
|
];
|
||
|
|
|
||
|
|
Locale resolved(List<Locale>? preferred) =>
|
||
|
|
resolveAppLocale(preferred, supported);
|
||
|
|
|
||
|
|
test('the language asked for, where the app speaks it', () {
|
||
|
|
expect(resolved(const [Locale('en', 'US')]), const Locale('en', 'US'));
|
||
|
|
expect(resolved(const [Locale('en', 'GB')]), const Locale('en', 'GB'));
|
||
|
|
expect(resolved(const [Locale('de', 'DE')]), const Locale('de'));
|
||
|
|
expect(resolved(const [Locale('de')]), const Locale('de'));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('British English for any other English', () {
|
||
|
|
expect(resolved(const [Locale('en')]), const Locale('en', 'GB'));
|
||
|
|
expect(resolved(const [Locale('en', 'AU')]), const Locale('en', 'GB'));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('the next language the device prefers, where the first is none the '
|
||
|
|
'app speaks', () {
|
||
|
|
expect(
|
||
|
|
resolved(const [Locale('fr', 'FR'), Locale('de', 'AT')]),
|
||
|
|
const Locale('de'),
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('British English where the app speaks none of them', () {
|
||
|
|
expect(resolved(const [Locale('fr', 'FR')]), const Locale('en', 'GB'));
|
||
|
|
expect(resolved(const []), const Locale('en', 'GB'));
|
||
|
|
expect(resolved(null), const Locale('en', 'GB'));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('never a language picked by the country alone', () {
|
||
|
|
// Spanish in the United States isn't American English.
|
||
|
|
expect(resolved(const [Locale('es', 'US')]), const Locale('en', 'GB'));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('every language this package speaks is one it resolves to', () {
|
||
|
|
for (final locale in HalkyonAppLocalizations.supportedLocales) {
|
||
|
|
expect(
|
||
|
|
resolveAppLocale([locale], HalkyonAppLocalizations.supportedLocales),
|
||
|
|
isIn(HalkyonAppLocalizations.supportedLocales),
|
||
|
|
reason: '$locale',
|
||
|
|
);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|