feat(flutter): 应用克莱因蓝主题与印尼语适配
This commit is contained in:
1 parent
e1147cfcba
commit
10d448c8ba
31 files changed
+891
-521
No files matched your search
@@ -32,18 +32,42 @@ void main() {
|
||||
expect(reopened.locale, const Locale('zh'));
|
||||
});
|
||||
|
||||
test('should_clear_stored_chinese_preference_when_english_is_selected', () async {
|
||||
await LocaleController().select('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();
|
||||
await reopened.select('en');
|
||||
|
||||
final third = LocaleController();
|
||||
await third.load();
|
||||
expect(third.locale, const Locale('en'));
|
||||
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');
|
||||
@@ -54,25 +78,31 @@ void main() {
|
||||
expect(controller.locale, isNull);
|
||||
});
|
||||
|
||||
test('should_resolve_to_device_locale_when_stored_code_is_unsupported', () async {
|
||||
await SharedPreferencesAsync().setString('ui.locale', 'fr');
|
||||
test(
|
||||
'should_resolve_to_device_locale_when_stored_code_is_unsupported',
|
||||
() async {
|
||||
await SharedPreferencesAsync().setString('ui.locale', 'fr');
|
||||
|
||||
final controller = LocaleController();
|
||||
await controller.load();
|
||||
final controller = LocaleController();
|
||||
await controller.load();
|
||||
|
||||
expect(controller.locale, isNull);
|
||||
});
|
||||
expect(controller.locale, isNull);
|
||||
},
|
||||
);
|
||||
|
||||
test('should_survive_load_and_select_when_preference_store_is_broken', () async {
|
||||
SharedPreferencesAsyncPlatform.instance = _BrokenPreferences();
|
||||
final controller = LocaleController();
|
||||
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.load();
|
||||
expect(controller.locale, isNull);
|
||||
|
||||
await controller.select('zh');
|
||||
expect(controller.locale, const Locale('zh'));
|
||||
});
|
||||
await controller.select('zh');
|
||||
expect(controller.locale, const Locale('zh'));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Stands in for a platform whose preference store is unavailable.
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/formatting/localized_date_time.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'should_use_indonesian_material_date_and_time_when_locale_is_id',
|
||||
(tester) async {
|
||||
final value = DateTime(2026, 10, 17, 12, 30);
|
||||
late String formatted;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
locale: const Locale('id'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Builder(
|
||||
builder: (context) {
|
||||
formatted = formatLocalizedDateTime(context, value);
|
||||
final localizations = MaterialLocalizations.of(context);
|
||||
final expectedDate = localizations.formatCompactDate(
|
||||
value.toLocal(),
|
||||
);
|
||||
final expectedTime = localizations.formatTimeOfDay(
|
||||
TimeOfDay.fromDateTime(value.toLocal()),
|
||||
alwaysUse24HourFormat: MediaQuery.alwaysUse24HourFormatOf(
|
||||
context,
|
||||
),
|
||||
);
|
||||
expect(formatted, '$expectedDate $expectedTime');
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -32,35 +32,41 @@ Drama _drama(String id, {List<int> numbers = const [1, 2, 3]}) => Drama(
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
test('should_keep_requested_section_and_read_episode_one_when_constructed', () async {
|
||||
final history = FakeWatchHistory()..saved = const Duration(seconds: 7);
|
||||
final logic = MineLogic(
|
||||
history: history,
|
||||
drama: _drama('signal'),
|
||||
initialSection: 1,
|
||||
);
|
||||
test(
|
||||
'should_keep_requested_section_and_read_episode_one_when_constructed',
|
||||
() async {
|
||||
final history = FakeWatchHistory()..saved = const Duration(seconds: 7);
|
||||
final logic = MineLogic(
|
||||
history: history,
|
||||
drama: _drama('signal'),
|
||||
initialSection: 1,
|
||||
);
|
||||
|
||||
expect(logic.section, 1);
|
||||
expect(logic.filter, 0);
|
||||
expect(await logic.position, const Duration(seconds: 7));
|
||||
expect(history.reads, ['signal']);
|
||||
logic.dispose();
|
||||
});
|
||||
expect(logic.section, 1);
|
||||
expect(logic.filter, 0);
|
||||
expect(await logic.position, const Duration(seconds: 7));
|
||||
expect(history.reads, ['signal']);
|
||||
logic.dispose();
|
||||
},
|
||||
);
|
||||
|
||||
test('should_resume_from_last_watch_when_list_card_has_no_episodes', () async {
|
||||
final history = FakeWatchHistory()
|
||||
..saved = const Duration(seconds: 7)
|
||||
..lastEpisode = 'signal-3';
|
||||
final logic = MineLogic(
|
||||
history: history,
|
||||
drama: _drama('signal', numbers: const []),
|
||||
initialSection: 1,
|
||||
);
|
||||
test(
|
||||
'should_resume_from_last_watch_when_list_card_has_no_episodes',
|
||||
() async {
|
||||
final history = FakeWatchHistory()
|
||||
..saved = const Duration(seconds: 7)
|
||||
..lastEpisode = 'signal-3';
|
||||
final logic = MineLogic(
|
||||
history: history,
|
||||
drama: _drama('signal', numbers: const []),
|
||||
initialSection: 1,
|
||||
);
|
||||
|
||||
expect(await logic.position, const Duration(seconds: 7));
|
||||
expect(history.reads, ['signal']);
|
||||
logic.dispose();
|
||||
});
|
||||
expect(await logic.position, const Duration(seconds: 7));
|
||||
expect(history.reads, ['signal']);
|
||||
logic.dispose();
|
||||
},
|
||||
);
|
||||
|
||||
test('should_notify_when_section_and_filter_are_selected', () {
|
||||
final logic = MineLogic(
|
||||
@@ -114,7 +120,12 @@ void main() {
|
||||
expect(logic.drama.id, 'city');
|
||||
|
||||
history.reads.clear();
|
||||
sync(_drama('vengeance'), active: true, wasActive: true, dramaChanged: true);
|
||||
sync(
|
||||
_drama('vengeance'),
|
||||
active: true,
|
||||
wasActive: true,
|
||||
dramaChanged: true,
|
||||
);
|
||||
expect(logic.drama.id, 'vengeance');
|
||||
expect(history.reads, ['vengeance']);
|
||||
|
||||
@@ -125,26 +136,29 @@ void main() {
|
||||
logic.dispose();
|
||||
});
|
||||
|
||||
test('should_reset_section_when_section_request_arrives_while_page_is_inactive', () {
|
||||
final logic = MineLogic(
|
||||
history: FakeWatchHistory(),
|
||||
drama: _drama('s'),
|
||||
initialSection: 0,
|
||||
);
|
||||
test(
|
||||
'should_reset_section_when_section_request_arrives_while_page_is_inactive',
|
||||
() {
|
||||
final logic = MineLogic(
|
||||
history: FakeWatchHistory(),
|
||||
drama: _drama('s'),
|
||||
initialSection: 0,
|
||||
);
|
||||
|
||||
logic.syncPage(
|
||||
active: false,
|
||||
wasActive: false,
|
||||
nextDrama: logic.drama,
|
||||
dramaChanged: false,
|
||||
sectionRequest: 1,
|
||||
previousSectionRequest: 0,
|
||||
initialSection: 1,
|
||||
);
|
||||
logic.syncPage(
|
||||
active: false,
|
||||
wasActive: false,
|
||||
nextDrama: logic.drama,
|
||||
dramaChanged: false,
|
||||
sectionRequest: 1,
|
||||
previousSectionRequest: 0,
|
||||
initialSection: 1,
|
||||
);
|
||||
|
||||
expect(logic.section, 1);
|
||||
logic.dispose();
|
||||
});
|
||||
expect(logic.section, 1);
|
||||
logic.dispose();
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('should_return_choice_and_forward_it_when_act_runs_embedded', (
|
||||
tester,
|
||||
@@ -197,7 +211,9 @@ void main() {
|
||||
logic.dispose();
|
||||
});
|
||||
|
||||
testWidgets('should_switch_app_locale_when_language_sheet_is_used', (tester) async {
|
||||
testWidgets('should_switch_app_locale_when_language_sheet_is_used', (
|
||||
tester,
|
||||
) async {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.empty();
|
||||
final locale = LocaleController();
|
||||
@@ -231,7 +247,14 @@ void main() {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
expect(find.text(l10n.english), findsOneWidget);
|
||||
expect(find.text(l10n.simplifiedChinese), findsOneWidget);
|
||||
expect(find.text('Bahasa Indonesia'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Bahasa Indonesia'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(locale.locale, const Locale('id'));
|
||||
|
||||
unawaited(logic.showLanguage(context));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(l10n.simplifiedChinese));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/theme/app_colors.dart';
|
||||
import 'package:fruitshorts/core/theme/app_theme.dart';
|
||||
|
||||
double _contrast(Color foreground, Color background) {
|
||||
final first = foreground.computeLuminance();
|
||||
final second = background.computeLuminance();
|
||||
return (max(first, second) + 0.05) / (min(first, second) + 0.05);
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('should_expose_approved_klein_blue_tokens', () {
|
||||
expect(AppColors.blue, const Color(0xFF002FA7));
|
||||
expect(AppColors.bluePressed, const Color(0xFF00227A));
|
||||
expect(AppColors.blueSoft, const Color(0xFF5B7BE0));
|
||||
expect(AppColors.onPrimary, const Color(0xFFFFFFFF));
|
||||
});
|
||||
|
||||
test('should_meet_text_and_icon_contrast_when_using_theme_tokens', () {
|
||||
expect(
|
||||
_contrast(AppColors.onPrimary, AppColors.blue),
|
||||
greaterThanOrEqualTo(4.5),
|
||||
);
|
||||
expect(_contrast(AppColors.blue, Colors.white), greaterThanOrEqualTo(4.5));
|
||||
expect(
|
||||
_contrast(AppColors.blueSoft, AppColors.ink),
|
||||
greaterThanOrEqualTo(3),
|
||||
);
|
||||
});
|
||||
|
||||
test('should_use_klein_blue_in_light_and_dark_color_schemes', () {
|
||||
for (final theme in [AppTheme.light(), AppTheme.dark()]) {
|
||||
expect(theme.colorScheme.primary, AppColors.blue);
|
||||
expect(theme.colorScheme.onPrimary, AppColors.onPrimary);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('should_expose_klein_blue_through_widget_theme', (tester) async {
|
||||
late ThemeData applied;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.dark(),
|
||||
home: Builder(
|
||||
builder: (context) {
|
||||
applied = Theme.of(context);
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(applied.colorScheme.primary, AppColors.blue);
|
||||
expect(applied.colorScheme.onPrimary, AppColors.onPrimary);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('should_use_theme_tokens_when_lib_code_is_scanned_for_legacy_blue', () {
|
||||
final pattern = RegExp(
|
||||
r'0xFF2F7BFF|0xff2F7BFF|0xFF8FB4FF|0xff8FB4FF|(?<!App)Colors\.blue\b',
|
||||
);
|
||||
final violations = <String>[];
|
||||
for (final entity in Directory('lib').listSync(recursive: true)) {
|
||||
if (entity is! File || !entity.path.endsWith('.dart')) continue;
|
||||
final lines = entity.readAsLinesSync();
|
||||
for (var index = 0; index < lines.length; index++) {
|
||||
if (pattern.hasMatch(lines[index])) {
|
||||
violations.add('${entity.path}:${index + 1}: ${lines[index].trim()}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expect(violations, isEmpty, reason: violations.join('\n'));
|
||||
});
|
||||
}
|
||||
+252
-240
@@ -27,13 +27,12 @@ void main() {
|
||||
/// 而是本地会话(这里直接给 shared_preferences 的内存实现塞一份会话)。
|
||||
/// 昵称/uid 与演示文案保持一致,避免为显示细节改写既有断言。
|
||||
void seedSignedInSession() {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.withData({
|
||||
'auth.accessToken': 'test-access',
|
||||
'auth.refreshToken': 'test-refresh',
|
||||
'auth.user':
|
||||
'{"uid":"M1CZWVYE","nickname":"Vicky sheng","avatarUrl":""}',
|
||||
});
|
||||
SharedPreferencesAsyncPlatform
|
||||
.instance = InMemorySharedPreferencesAsync.withData({
|
||||
'auth.accessToken': 'test-access',
|
||||
'auth.refreshToken': 'test-refresh',
|
||||
'auth.user': '{"uid":"M1CZWVYE","nickname":"Vicky sheng","avatarUrl":""}',
|
||||
});
|
||||
}
|
||||
|
||||
void seedSignedOutSession() {
|
||||
@@ -98,15 +97,15 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('should_open_series_detail_when_immersive_home_is_tapped', (tester) async {
|
||||
testWidgets('should_open_series_detail_when_immersive_home_is_tapped', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(),
|
||||
);
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -131,9 +130,7 @@ void main() {
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(),
|
||||
);
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -148,60 +145,60 @@ void main() {
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('should_open_current_series_and_switch_root_tabs_when_quick_drawer_is_used', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(360, 720);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
testWidgets(
|
||||
'should_open_current_series_and_switch_root_tabs_when_quick_drawer_is_used',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(360, 720);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Continue Watching'), findsOneWidget);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester
|
||||
.widget<PlayerPage>(find.byType(PlayerPage, skipOffstage: false))
|
||||
.active,
|
||||
isFalse,
|
||||
);
|
||||
expect(find.text('Quick access'), findsOneWidget);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byType(Drawer),
|
||||
matching: find.text('7 EPISODES'),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Continue Watching'), findsOneWidget);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester
|
||||
.widget<PlayerPage>(find.byType(PlayerPage, skipOffstage: false))
|
||||
.active,
|
||||
isFalse,
|
||||
);
|
||||
expect(find.text('Quick access'), findsOneWidget);
|
||||
expect(find.text('Bahasa Indonesia'), findsOneWidget);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byType(Drawer),
|
||||
matching: find.text('7 EPISODES'),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
await tester.tap(find.byKey(const Key('drawer-open-series')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Watch episode 1'), findsOneWidget);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester
|
||||
.widget<PlayerPage>(find.byType(PlayerPage, skipOffstage: false))
|
||||
.active,
|
||||
isFalse,
|
||||
);
|
||||
expect(find.text('Continue Watching'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('drawer-open-series')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Watch episode 1'), findsOneWidget);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester
|
||||
.widget<PlayerPage>(find.byType(PlayerPage, skipOffstage: false))
|
||||
.active,
|
||||
isFalse,
|
||||
);
|
||||
expect(find.text('Continue Watching'), findsOneWidget);
|
||||
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('drawer-discover')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Continue Watching'), findsOneWidget);
|
||||
expect(
|
||||
Navigator.of(tester.element(find.text('Continue Watching'))).canPop(),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('drawer-discover')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Continue Watching'), findsOneWidget);
|
||||
expect(
|
||||
Navigator.of(tester.element(find.text('Continue Watching'))).canPop(),
|
||||
isFalse,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('should_change_interface_language_when_locale_is_picked', (
|
||||
tester,
|
||||
@@ -211,9 +208,7 @@ void main() {
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(),
|
||||
);
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byTooltip('Captions'), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('tab-my')));
|
||||
@@ -234,51 +229,74 @@ void main() {
|
||||
expect(find.text('热门'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_fit_compact_android_viewport_when_home_controls_are_shown', (tester) async {
|
||||
tester.view.physicalSize = const Size(360, 720);
|
||||
testWidgets(
|
||||
'should_fit_compact_android_viewport_when_home_controls_are_shown',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(360, 720);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('The Signal'), findsOneWidget);
|
||||
await tester.drag(find.byType(PageView), const Offset(0, -500));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('City Lights & Velvet Nights'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('tab-discover')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('City Lights & Velvet Nights'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(Slider), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'should_fit_compact_android_viewport_and_return_home_when_my_page_is_shown',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(360, 720);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-my')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.text('Vicky sheng'), findsOneWidget);
|
||||
expect(find.text('Coins'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.tap(find.text('Shorts'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('The Signal'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('should_fit_compact_dark_viewport_when_klein_theme_is_used', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(320, 568);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
|
||||
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(),
|
||||
);
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('The Signal'), findsOneWidget);
|
||||
await tester.drag(find.byType(PageView), const Offset(0, -500));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('City Lights & Velvet Nights'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('tab-discover')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('City Lights & Velvet Nights'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(Slider), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('should_fit_compact_android_viewport_and_return_home_when_my_page_is_shown', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(360, 720);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-my')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.text('Vicky sheng'), findsOneWidget);
|
||||
expect(find.text('Coins'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.tap(find.text('Shorts'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('The Signal'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
@@ -289,9 +307,7 @@ void main() {
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(),
|
||||
);
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Home'));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -317,15 +333,15 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('should_stay_on_one_route_when_bottom_tabs_are_used', (tester) async {
|
||||
testWidgets('should_stay_on_one_route_when_bottom_tabs_are_used', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(),
|
||||
);
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Home'));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -375,9 +391,7 @@ void main() {
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(),
|
||||
);
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -400,15 +414,15 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('should_hide_category_navigation_when_shorts_page_is_shown', (tester) async {
|
||||
testWidgets('should_hide_category_navigation_when_shorts_page_is_shown', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(),
|
||||
);
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -422,74 +436,76 @@ void main() {
|
||||
expect(find.text('City Lights & Velvet Nights'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('should_save_comment_like_and_share_in_order_when_right_rail_is_used', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
String? sharedText;
|
||||
final interactions = FakeInteractionRepository();
|
||||
final comments = FakeCommentRepository(
|
||||
pages: [const CommentPage()],
|
||||
);
|
||||
const channel = MethodChannel('com.stormg.lumadrama/share');
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
|
||||
call,
|
||||
) async {
|
||||
sharedText = (call.arguments as Map)['text'] as String;
|
||||
return null;
|
||||
});
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
channel,
|
||||
null,
|
||||
),
|
||||
);
|
||||
testWidgets(
|
||||
'should_save_comment_like_and_share_in_order_when_right_rail_is_used',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
String? sharedText;
|
||||
final interactions = FakeInteractionRepository();
|
||||
final comments = FakeCommentRepository(pages: [const CommentPage()]);
|
||||
const channel = MethodChannel('com.stormg.lumadrama/share');
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
|
||||
call,
|
||||
) async {
|
||||
sharedText = (call.arguments as Map)['text'] as String;
|
||||
return null;
|
||||
});
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
channel,
|
||||
null,
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(
|
||||
commentRepository: comments,
|
||||
interactionRepository: interactions,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
final keys = [
|
||||
const Key('rail-like'),
|
||||
const Key('rail-save'),
|
||||
const Key('rail-comments'),
|
||||
const Key('rail-share'),
|
||||
];
|
||||
final tops = keys
|
||||
.map((key) => tester.getTopLeft(find.byKey(key)).dy)
|
||||
.toList();
|
||||
expect(tops, orderedEquals(tops.toList()..sort()));
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(
|
||||
commentRepository: comments,
|
||||
interactionRepository: interactions,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
final keys = [
|
||||
const Key('rail-like'),
|
||||
const Key('rail-save'),
|
||||
const Key('rail-comments'),
|
||||
const Key('rail-share'),
|
||||
];
|
||||
final tops = keys
|
||||
.map((key) => tester.getTopLeft(find.byKey(key)).dy)
|
||||
.toList();
|
||||
expect(tops, orderedEquals(tops.toList()..sort()));
|
||||
|
||||
await tester.tap(find.byKey(const Key('rail-save')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('rail-comments')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('No comments yet.'), findsOneWidget);
|
||||
await tester.enterText(find.byKey(const Key('comment-input')), 'Nice demo');
|
||||
await tester.tap(find.byKey(const Key('comment-post')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Nice demo'), findsOneWidget);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('rail-save')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('rail-comments')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('No comments yet.'), findsOneWidget);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('comment-input')),
|
||||
'Nice demo',
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('comment-post')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Nice demo'), findsOneWidget);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const Key('rail-like')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(interactions.likeTargets, contains('DRAMA:the-signal-demo'));
|
||||
await tester.tap(find.byKey(const Key('rail-share')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(sharedText, contains('The Signal'));
|
||||
expect(sharedText, contains('A demo series for vertical playback'));
|
||||
expect(sharedText, contains('FruitShorts'));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
await tester.tap(find.byKey(const Key('rail-like')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(interactions.likeTargets, contains('DRAMA:the-signal-demo'));
|
||||
await tester.tap(find.byKey(const Key('rail-share')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(sharedText, contains('The Signal'));
|
||||
expect(sharedText, contains('A demo series for vertical playback'));
|
||||
expect(sharedText, contains('FruitShorts'));
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('should_open_auth_gate_without_liking_when_signed_out', (
|
||||
tester,
|
||||
@@ -501,9 +517,7 @@ void main() {
|
||||
seedSignedOutSession();
|
||||
final interactions = FakeInteractionRepository();
|
||||
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(interactionRepository: interactions),
|
||||
);
|
||||
await tester.pumpWidget(appUnderTest(interactionRepository: interactions));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -523,9 +537,7 @@ void main() {
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final interactions = FakeInteractionRepository();
|
||||
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(interactionRepository: interactions),
|
||||
);
|
||||
await tester.pumpWidget(appUnderTest(interactionRepository: interactions));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
@@ -542,63 +554,63 @@ void main() {
|
||||
expect(find.text('Report submitted. Thank you.'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_open_drawer_and_stay_on_home_when_system_back_is_pressed', (tester) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
testWidgets(
|
||||
'should_open_drawer_and_stay_on_home_when_system_back_is_pressed',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Continue Watching'), findsOneWidget);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Quick access'), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-tabs-bar')), findsOneWidget);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Quick access'), findsNothing);
|
||||
expect(find.text('Continue Watching'), findsOneWidget);
|
||||
expect(
|
||||
Navigator.of(
|
||||
tester.element(find.byKey(const Key('home-tabs-bar'))),
|
||||
).canPop(),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
expect(find.text('Continue Watching'), findsOneWidget);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Quick access'), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-tabs-bar')), findsOneWidget);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Quick access'), findsNothing);
|
||||
expect(find.text('Continue Watching'), findsOneWidget);
|
||||
expect(
|
||||
Navigator.of(
|
||||
tester.element(find.byKey(const Key('home-tabs-bar'))),
|
||||
).canPop(),
|
||||
isFalse,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('should_list_saved_dramas_across_home_feed_when_watchlist_is_opened', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
// 收藏要求登录态:沿用本文件已有的"假登录"初始化
|
||||
seedSignedInSession();
|
||||
await tester.pumpWidget(
|
||||
appUnderTest(),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
testWidgets(
|
||||
'should_list_saved_dramas_across_home_feed_when_watchlist_is_opened',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
// 收藏要求登录态:沿用本文件已有的"假登录"初始化
|
||||
seedSignedInSession();
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const Key('rail-save')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.drag(find.byType(PageView), const Offset(0, -550));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('rail-save')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-my-list')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Watchlist'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('The Signal'), findsOneWidget);
|
||||
expect(find.text('City Lights & Velvet Nights'), findsWidgets);
|
||||
await tester.tap(find.text('The Signal'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Watch episode 1'), findsOneWidget);
|
||||
});
|
||||
await tester.tap(find.byKey(const Key('rail-save')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.drag(find.byType(PageView), const Offset(0, -550));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('rail-save')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-my-list')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Watchlist'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('The Signal'), findsOneWidget);
|
||||
expect(find.text('City Lights & Velvet Nights'), findsWidgets);
|
||||
await tester.tap(find.text('The Signal'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Watch episode 1'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user