feat(app): 剧场页九宫格与极简我的页
This commit is contained in:
1 parent
dc8ca7b743
commit
35338cbfc8
46 files changed
+2353
-4358
No files matched your search
@@ -0,0 +1,19 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/config/app_locale.dart';
|
||||
|
||||
void main() {
|
||||
test('should_resolve_supported_device_languages', () {
|
||||
expect(resolveAppLocale(const Locale('en')), const Locale('en'));
|
||||
expect(resolveAppLocale(const Locale('zh')), const Locale('zh'));
|
||||
expect(resolveAppLocale(const Locale('id')), const Locale('id'));
|
||||
expect(resolveAppLocale(const Locale('in')), const Locale('id'));
|
||||
});
|
||||
|
||||
test('should_fallback_to_indonesian_when_device_language_is_unsupported', () {
|
||||
expect(resolveAppLocale(const Locale('fr')), const Locale('id'));
|
||||
expect(resolveAppLocale(null), const Locale('id'));
|
||||
});
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/config/locale_controller.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
||||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
||||
import 'package:shared_preferences_platform_interface/types.dart';
|
||||
|
||||
void main() {
|
||||
setUp(() {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.empty();
|
||||
});
|
||||
|
||||
test('should_keep_device_locale_when_no_choice_is_stored', () async {
|
||||
final controller = LocaleController();
|
||||
var notifications = 0;
|
||||
controller.addListener(() => notifications++);
|
||||
|
||||
await controller.load();
|
||||
|
||||
expect(controller.locale, isNull);
|
||||
expect(notifications, 1);
|
||||
});
|
||||
|
||||
test('should_restore_chosen_language_when_app_restarts', () async {
|
||||
final first = LocaleController();
|
||||
await first.select('zh');
|
||||
expect(first.locale, const Locale('zh'));
|
||||
|
||||
final reopened = LocaleController();
|
||||
await reopened.load();
|
||||
expect(reopened.locale, const Locale('zh'));
|
||||
});
|
||||
|
||||
test('should_restore_indonesian_when_selected_and_app_restarts', () async {
|
||||
final first = LocaleController();
|
||||
await first.select('id');
|
||||
expect(first.locale, const Locale('id'));
|
||||
|
||||
final reopened = LocaleController();
|
||||
await reopened.load();
|
||||
expect(reopened.locale, const Locale('id'));
|
||||
});
|
||||
|
||||
test('should_fallback_to_indonesian_when_system_language_is_unsupported', () {
|
||||
expect(resolveAppLocale(null, const Locale('en')), const Locale('en'));
|
||||
expect(resolveAppLocale(null, const Locale('id')), const Locale('id'));
|
||||
expect(resolveAppLocale(null, const Locale('fr')), const Locale('id'));
|
||||
expect(resolveAppLocale(null, const Locale('in')), const Locale('id'));
|
||||
expect(
|
||||
resolveAppLocale(const Locale('zh'), const Locale('fr')),
|
||||
const Locale('zh'),
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'should_clear_stored_chinese_preference_when_english_is_selected',
|
||||
() async {
|
||||
await LocaleController().select('zh');
|
||||
|
||||
final reopened = LocaleController();
|
||||
await reopened.load();
|
||||
await reopened.select('en');
|
||||
|
||||
final third = LocaleController();
|
||||
await third.load();
|
||||
expect(third.locale, const Locale('en'));
|
||||
},
|
||||
);
|
||||
|
||||
test('should_clear_locale_when_code_is_unsupported', () async {
|
||||
final controller = LocaleController();
|
||||
await controller.select('zh');
|
||||
expect(controller.locale, const Locale('zh'));
|
||||
|
||||
await controller.select('tlh');
|
||||
|
||||
expect(controller.locale, isNull);
|
||||
});
|
||||
|
||||
test(
|
||||
'should_resolve_to_device_locale_when_stored_code_is_unsupported',
|
||||
() async {
|
||||
await SharedPreferencesAsync().setString('ui.locale', 'fr');
|
||||
|
||||
final controller = LocaleController();
|
||||
await controller.load();
|
||||
|
||||
expect(controller.locale, isNull);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'should_survive_load_and_select_when_preference_store_is_broken',
|
||||
() async {
|
||||
SharedPreferencesAsyncPlatform.instance = _BrokenPreferences();
|
||||
final controller = LocaleController();
|
||||
|
||||
await controller.load();
|
||||
expect(controller.locale, isNull);
|
||||
|
||||
await controller.select('zh');
|
||||
expect(controller.locale, const Locale('zh'));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Stands in for a platform whose preference store is unavailable.
|
||||
base class _BrokenPreferences extends InMemorySharedPreferencesAsync {
|
||||
_BrokenPreferences() : super.empty();
|
||||
|
||||
@override
|
||||
Future<String?> getString(String key, SharedPreferencesOptions options) =>
|
||||
Future<String?>.error(StateError('preferences unavailable'));
|
||||
|
||||
@override
|
||||
Future<bool> setString(
|
||||
String key,
|
||||
String value,
|
||||
SharedPreferencesOptions options,
|
||||
) => Future<bool>.error(StateError('preferences unavailable'));
|
||||
}
|
||||
Reference in new issue
Block a user