feat(flutter): 重构四 Tab 与浏览页

This commit is contained in:
Zhou Weidong committed 2026-10-20 09:49:42 +08:00
1 parent 99c72e2c32
commit 959edc0a32
41 files changed
+2148 -1179

No files matched your search

+2 -2
View File
@@ -24,7 +24,7 @@ void main() {
InMemorySharedPreferencesAsync.empty();
await _pumpApp(tester);
await tester.tap(find.byKey(const Key('tab-my')));
await tester.tap(find.byKey(const Key('tab-mine')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('mine-settings')));
await tester.pumpAndSettle();
@@ -47,7 +47,7 @@ void main() {
);
await _pumpApp(tester);
await tester.tap(find.byKey(const Key('tab-my')));
await tester.tap(find.byKey(const Key('tab-mine')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('mine-settings')));
await tester.pumpAndSettle();
+5 -7
View File
@@ -7,7 +7,7 @@ import 'package:fruitshorts/core/data/models/home_feed.dart';
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
import 'package:fruitshorts/pages/drama_detail/drama_detail_view.dart';
import 'package:fruitshorts/pages/player/player_view.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';
@@ -23,7 +23,7 @@ void main() {
InMemorySharedPreferencesAsync.withData({});
});
testWidgets('should_open_linked_drama_when_discover_banner_is_tapped', (
testWidgets('should_open_fullscreen_player_when_home_hero_is_tapped', (
tester,
) async {
final catalog = FakeCatalogRepository(
@@ -37,15 +37,13 @@ void main() {
],
);
await _pumpApp(tester, catalog);
await tester.tap(find.byKey(const Key('tab-discover')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('feed-banner-carousel')), findsOneWidget);
await tester.tap(find.byKey(const Key('feed-banner-0')));
await tester.pumpAndSettle();
expect(find.byType(DramaDetailPage), findsOneWidget);
expect(find.text('The Signal'), findsWidgets);
final player = tester.widget<PlayerPage>(find.byType(PlayerPage));
expect(player.homeMode, isFalse);
expect(player.drama.title, 'The Signal');
});
}
+13 -22
View File
@@ -24,37 +24,27 @@ void main() {
InMemorySharedPreferencesAsync.empty();
});
testWidgets('should_show_search_categories_ranking_and_all_dramas', (
testWidgets('should_show_search_category_language_and_drama_grid', (
tester,
) async {
await _pumpTheater(tester, categoryRepository: _GridCategoryRepository());
expect(find.text('Continue Watching'), findsNothing);
expect(find.byKey(const Key('discover-search')), findsOneWidget);
expect(find.byKey(const Key('discover-category-grid')), findsOneWidget);
expect(find.byKey(const Key('discover-ranking-section')), findsOneWidget);
expect(find.byKey(const Key('theater-category-chips')), findsOneWidget);
expect(find.byKey(const Key('theater-language-chips')), findsOneWidget);
expect(find.byKey(const Key('home-all-dramas-grid')), findsOneWidget);
expect(find.byKey(const Key('ranking-tab-hot')), findsOneWidget);
expect(find.byKey(const Key('ranking-tab-new')), findsOneWidget);
final grid = tester.widget<GridView>(
find.byKey(const Key('discover-category-grid')),
);
final delegate =
grid.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount;
expect(delegate.crossAxisCount, 3);
expect(tester.takeException(), isNull);
});
testWidgets('should_open_category_dramas_page_when_tile_is_tapped', (
testWidgets('should_filter_grid_when_category_chip_is_tapped', (
tester,
) async {
await _pumpTheater(tester, categoryRepository: _GridCategoryRepository());
await tester.tap(find.byKey(const Key('discover-category-7')));
await tester.tap(find.byKey(const Key('theater-category-7')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('category-dramas-page')), findsOneWidget);
expect(
find.byKey(const Key('home-drama-card-city-lights-demo')),
findsOneWidget,
@@ -76,22 +66,23 @@ void main() {
);
final headerBefore = tester.getTopLeft(
find.byKey(const Key('discover-search-button')),
find.byKey(const Key('discover-search')),
);
final contentBefore = tester.getTopLeft(
find.byKey(const Key('discover-category-grid')),
final scrollable = find.descendant(
of: find.byKey(const Key('discover-refresh')),
matching: find.byType(Scrollable),
);
await tester.drag(find.byType(ListView), const Offset(0, -140));
await tester.pumpAndSettle();
expect(
tester.getTopLeft(find.byKey(const Key('discover-search-button'))),
tester.getTopLeft(find.byKey(const Key('discover-search'))),
headerBefore,
);
expect(
tester.getTopLeft(find.byKey(const Key('discover-category-grid'))).dy,
lessThan(contentBefore.dy),
tester.state<ScrollableState>(scrollable).position.pixels,
greaterThan(0),
);
});
@@ -172,7 +163,7 @@ Future<void> _pumpTheater(
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-discover')));
await tester.tap(find.byKey(const Key('tab-theater')));
await tester.pumpAndSettle();
}
+12 -8
View File
@@ -66,22 +66,20 @@ void main() {
logic.openProfile();
expect(logic.tab, 2);
expect(logic.tab, 3);
logic.dispose();
});
test('should_return_to_discover_and_handle_immersive_back', () {
test('should_return_home_and_handle_immersive_back', () {
final logic = HomeLogic(dramas);
logic.onSystemBack();
expect(logic.tab, 1);
logic.onSystemBack();
expect(logic.tab, 1);
expect(logic.tab, 0);
expect(logic.backRequest, 0);
logic.select(0);
logic.select(1);
logic.onSystemBack();
expect(logic.tab, 1);
expect(logic.tab, 0);
logic.select(0);
logic.onImmersiveChanged(true);
@@ -91,7 +89,7 @@ void main() {
logic.onImmersiveChanged(false);
logic.onSystemBack();
expect(logic.tab, 1);
expect(logic.tab, 0);
logic.dispose();
});
@@ -130,6 +128,9 @@ void main() {
expect(logic.tab, 1);
expect(logic.searchRequest, 1);
logic.myAction(MyPageAction.create);
expect(logic.tab, 2);
logic.myAction(MyPageAction.resume);
expect(logic.tab, 0);
expect(logic.resumeRequest, 1);
@@ -144,6 +145,9 @@ void main() {
final logic = HomeLogic(dramas);
logic.discoverAction(DiscoverPageAction.my);
expect(logic.tab, 3);
logic.discoverAction(DiscoverPageAction.create);
expect(logic.tab, 2);
logic.discoverAction(DiscoverPageAction.home);
+24 -16
View File
@@ -19,8 +19,9 @@ import '../support/widget_player.dart';
const _keys = [
Key('home-tabs-bar'),
Key('tab-home'),
Key('tab-discover'),
Key('tab-my'),
Key('tab-theater'),
Key('tab-create'),
Key('tab-mine'),
];
void main() {
@@ -33,7 +34,7 @@ void main() {
});
});
testWidgets('should_theme_three_tabs_and_switch_selected_state_when_tapped', (
testWidgets('should_theme_four_tabs_and_switch_selected_state_when_tapped', (
tester,
) async {
final haptics = FakeHaptics();
@@ -68,20 +69,20 @@ void main() {
expect(
find.descendant(
of: find.byKey(const Key('tab-home')),
matching: find.byIcon(Icons.play_circle_fill_rounded),
matching: find.byIcon(Icons.home_rounded),
),
findsOneWidget,
);
await tester.tap(find.byKey(const Key('tab-discover')));
await tester.tap(find.byKey(const Key('tab-theater')));
await tester.pumpAndSettle();
expect(haptics.selectionClicks, 1);
await tester.tap(find.byKey(const Key('tab-discover')));
await tester.tap(find.byKey(const Key('tab-theater')));
await tester.pumpAndSettle();
expect(haptics.selectionClicks, 1);
expect(
find.descendant(
of: find.byKey(const Key('tab-discover')),
of: find.byKey(const Key('tab-theater')),
matching: find.byIcon(Icons.explore_rounded),
),
findsOneWidget,
@@ -89,25 +90,32 @@ void main() {
expect(
find.descendant(
of: find.byKey(const Key('tab-home')),
matching: find.byIcon(Icons.play_circle_outline_rounded),
matching: find.byIcon(Icons.home_outlined),
),
findsOneWidget,
);
});
testWidgets('should_map_three_tabs_to_home_discover_and_me', (tester) async {
testWidgets('should_map_four_tabs_to_home_theater_create_and_me', (
tester,
) async {
await _pumpApp(tester);
expect(find.byKey(const Key('tab-home')), findsOneWidget);
expect(find.byKey(const Key('tab-discover')), findsOneWidget);
expect(find.byKey(const Key('tab-my')), findsOneWidget);
expect(find.byKey(const Key('home-feed-info-card')), findsOneWidget);
expect(find.byKey(const Key('tab-theater')), findsOneWidget);
expect(find.byKey(const Key('tab-create')), findsOneWidget);
expect(find.byKey(const Key('tab-mine')), findsOneWidget);
expect(find.byKey(const Key('home-browse-page')), findsOneWidget);
await tester.tap(find.byKey(const Key('tab-discover')));
await tester.tap(find.byKey(const Key('tab-theater')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('home-all-dramas-grid')), findsOneWidget);
await tester.tap(find.byKey(const Key('tab-my')));
await tester.tap(find.byKey(const Key('tab-create')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('create-page')), findsOneWidget);
await tester.tap(find.byKey(const Key('tab-mine')));
await tester.pumpAndSettle();
expect(find.text('Viewer'), findsOneWidget);
expect(find.byKey(const Key('mine-menu')), findsOneWidget);
@@ -116,7 +124,7 @@ void main() {
await tester.tap(find.byKey(const Key('tab-home')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('home-feed-info-card')), findsOneWidget);
expect(find.byKey(const Key('home-browse-page')), findsOneWidget);
});
testWidgets('should_not_haptic_when_ordinary_list_item_is_opened', (
@@ -124,7 +132,7 @@ void main() {
) async {
final haptics = FakeHaptics();
await _pumpApp(tester, haptics);
await tester.tap(find.byKey(const Key('tab-my')));
await tester.tap(find.byKey(const Key('tab-mine')));
await tester.pumpAndSettle();
haptics.reset();
+21 -33
View File
@@ -7,6 +7,7 @@ import 'package:shared_preferences_platform_interface/shared_preferences_async_p
import 'package:fruitshorts/app.dart';
import 'package:fruitshorts/core/data/models/drama.dart';
import 'package:fruitshorts/core/data/models/home_feed.dart';
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
@@ -22,7 +23,7 @@ import '../support/fake_notice_repository.dart';
import '../support/widget_player.dart';
void main() {
testWidgets('should_render_preview_home_card_without_hot_or_follow_avatar', (
testWidgets('should_render_browse_home_with_header_channels_and_cards', (
tester,
) async {
SharedPreferencesAsyncPlatform.instance =
@@ -32,7 +33,16 @@ void main() {
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final catalog = FakeCatalogRepository();
final catalog = FakeCatalogRepository(
banners: const [
FeedBanner(
id: 'banner-1',
imageUrl: '/files/banner.jpg',
linkType: 'DRAMA',
linkValue: 'the-signal-demo',
),
],
);
await tester.pumpWidget(
LumaDramaApp(
playerFactory: createWidgetPlayer,
@@ -51,40 +61,18 @@ void main() {
await tester.tap(find.byKey(const Key('tab-home')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('home-feed-title')), findsOneWidget);
expect(find.byKey(const Key('home-feed-info-card')), findsOneWidget);
expect(find.byKey(const Key('home-feed-episode')), findsOneWidget);
final cardRect = tester.getRect(
find.byKey(const Key('home-feed-info-card')),
);
final episodeRect = tester.getRect(
find.byKey(const Key('home-feed-episode')),
);
expect(episodeRect.left, lessThan(cardRect.center.dx));
final railCenter = tester.getCenter(find.byKey(const Key('rail-like')));
final railBottom = tester.getBottomLeft(find.byKey(const Key('rail-save')));
expect(railCenter.dy, greaterThan(844 * 0.4));
expect(railBottom.dy, lessThan(cardRect.top));
expect(find.byKey(const Key('home-feed-follow-series')), findsOneWidget);
expect(find.byKey(const Key('home-feed-episodes')), findsOneWidget);
for (final key in const [Key('home-feed-search'), Key('home-feed-more')]) {
expect(tester.getSize(find.byKey(key)), const Size(36, 36));
expect(
tester
.widget<Icon>(
find.descendant(of: find.byKey(key), matching: find.byType(Icon)),
)
.size,
18,
);
expect(find.byKey(const Key('home-search')), findsOneWidget);
expect(find.byKey(const Key('home-profile')), findsOneWidget);
expect(find.byKey(const Key('home-weekday')), findsOneWidget);
for (final channel in ['hot', 'free', 'newReleases', 'ranking']) {
expect(find.byKey(Key('home-channel-$channel')), findsOneWidget);
}
expect(find.byKey(const Key('home-hero-banner')), findsOneWidget);
expect(
tester.getSize(find.byKey(const Key('home-feed-follow-series'))).height,
34,
find.byKey(const Key('home-drama-card-the-signal-demo')),
findsOneWidget,
);
expect(find.text('HOT'), findsNothing);
expect(find.textContaining('Season'), findsNothing);
expect(find.byKey(const Key('home-feed-follow')), findsNothing);
expect(find.byKey(const Key('home-feed-info-card')), findsNothing);
expect(tester.takeException(), isNull);
});
+206
View File
@@ -0,0 +1,206 @@
// Author: fruit.com.cn
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/app.dart';
import 'package:fruitshorts/core/data/models/home_feed.dart';
import 'package:fruitshorts/core/data/models/watch_progress.dart';
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
import 'package:fruitshorts/pages/player/player_view.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 '../support/fake_catalog.dart';
import '../support/fake_category.dart';
import '../support/fake_haptics.dart';
import '../support/fake_interaction_repositories.dart';
import '../support/widget_player.dart';
void main() {
setUp(() {
SharedPreferencesAsyncPlatform.instance =
InMemorySharedPreferencesAsync.empty();
});
testWidgets('should_render_four_tabs_and_open_create_placeholder', (
tester,
) async {
await _pumpApp(tester);
for (final key in _tabKeys) {
expect(find.byKey(key), findsOneWidget);
}
await tester.tap(find.byKey(const Key('tab-create')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('create-page')), findsOneWidget);
expect(find.text('Create'), findsWidgets);
expect(find.text('Stories become short dramas'), findsOneWidget);
});
testWidgets('should_switch_home_channel_when_chip_is_tapped', (tester) async {
await _pumpApp(tester);
expect(_chip(tester, 'home-channel-hot').selected, isTrue);
expect(_chip(tester, 'home-channel-free').selected, isFalse);
await tester.tap(find.byKey(const Key('home-channel-free')));
await tester.pumpAndSettle();
expect(_chip(tester, 'home-channel-hot').selected, isFalse);
expect(_chip(tester, 'home-channel-free').selected, isTrue);
});
testWidgets('should_open_theater_search_when_home_search_is_tapped', (
tester,
) async {
await _pumpApp(tester);
await tester.tap(find.byKey(const Key('home-search')));
await tester.pumpAndSettle();
final field = tester.widget<TextField>(
find.byKey(const Key('discover-search')),
);
expect(field.focusNode?.hasFocus, isTrue);
});
testWidgets('should_select_theater_language_without_filtering_catalog', (
tester,
) async {
await _pumpApp(tester);
await tester.tap(find.byKey(const Key('tab-theater')));
await tester.pumpAndSettle();
expect(_chip(tester, 'theater-language-all').selected, isTrue);
expect(
find.byKey(const Key('home-drama-card-the-signal-demo')),
findsOneWidget,
);
await tester.tap(find.byKey(const Key('theater-language-id')));
await tester.pumpAndSettle();
expect(_chip(tester, 'theater-language-all').selected, isFalse);
expect(_chip(tester, 'theater-language-id').selected, isTrue);
expect(
find.byKey(const Key('home-drama-card-the-signal-demo')),
findsOneWidget,
);
});
testWidgets('should_open_fullscreen_player_when_home_card_is_tapped', (
tester,
) async {
await _pumpApp(tester);
await tester.tap(find.byKey(const Key('home-drama-card-the-signal-demo')));
await tester.pumpAndSettle();
final player = tester.widget<PlayerPage>(find.byType(PlayerPage));
expect(player.homeMode, isFalse);
});
testWidgets('should_open_fullscreen_player_when_theater_card_is_tapped', (
tester,
) async {
await _pumpApp(tester);
await tester.tap(find.byKey(const Key('tab-theater')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('home-drama-card-the-signal-demo')));
await tester.pumpAndSettle();
final player = tester.widget<PlayerPage>(find.byType(PlayerPage));
expect(player.homeMode, isFalse);
});
testWidgets('should_resume_continue_watching_at_saved_episode', (
tester,
) async {
await _pumpApp(
tester,
history: InMemoryWatchHistoryRepository(
seed: const [
WatchProgress(
dramaId: 'the-signal-demo',
episodeId: 'the-signal-demo-3',
position: Duration(minutes: 2),
duration: Duration(minutes: 10),
),
],
),
);
expect(find.byKey(const Key('home-continue-watching')), findsOneWidget);
await tester.tap(
find.byKey(const Key('home-continue-play-the-signal-demo')),
);
await tester.pumpAndSettle();
final player = tester.widget<PlayerPage>(find.byType(PlayerPage));
expect(player.homeMode, isFalse);
expect(player.initialIndex, 2);
});
testWidgets('should_fit_home_and_theater_on_320_width', (tester) async {
await _pumpApp(tester, size: const Size(320, 568));
expect(find.byKey(const Key('home-search')), findsOneWidget);
expect(find.byKey(const Key('home-hero-title-0')), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.tap(find.byKey(const Key('tab-theater')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('theater-language-chips')), findsOneWidget);
expect(tester.takeException(), isNull);
});
}
const _tabKeys = [
Key('tab-home'),
Key('tab-theater'),
Key('tab-create'),
Key('tab-mine'),
];
ChoiceChip _chip(WidgetTester tester, String key) =>
tester.widget<ChoiceChip>(find.byKey(Key(key)));
Future<void> _pumpApp(
WidgetTester tester, {
WatchHistoryRepository? history,
Size size = const Size(390, 844),
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final catalog = FakeCatalogRepository(
banners: const [
FeedBanner(
id: 'banner-1',
imageUrl: '/files/banner.jpg',
linkType: 'DRAMA',
linkValue: 'the-signal-demo',
),
],
);
await tester.pumpWidget(
LumaDramaApp(
playerFactory: createWidgetPlayer,
catalogRepository: catalog,
categoryRepository: FakeCategoryRepository(catalog: catalog),
watchHistoryRepository: history ?? InMemoryWatchHistoryRepository(),
favoriteRepository: InMemoryFavoriteRepository(cards: catalog.dramas),
playbackRepository: FakePlaybackRepository(),
commentRepository: FakeCommentRepository(),
interactionRepository: FakeInteractionRepository(),
haptics: FakeHaptics(),
),
);
await tester.pumpAndSettle();
}
+1 -1
View File
@@ -53,7 +53,7 @@ void main() {
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-my')));
await tester.tap(find.byKey(const Key('tab-mine')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('mine-user-row')), findsOneWidget);
+1 -1
View File
@@ -44,7 +44,7 @@ void main() {
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-my')));
await tester.tap(find.byKey(const Key('tab-mine')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('mine-settings')));
await tester.pumpAndSettle();
+1 -1
View File
@@ -44,7 +44,7 @@ void main() {
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-my')));
await tester.tap(find.byKey(const Key('tab-mine')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('mine-settings')));
await tester.pumpAndSettle();
+15 -207
View File
@@ -29,7 +29,7 @@ void main() {
tester,
) async {
await _pumpApp(tester);
await tester.tap(find.byKey(const Key('tab-discover')));
await tester.tap(find.byKey(const Key('tab-theater')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('home-drama-card-city-lights-demo')));
await tester.pumpAndSettle();
@@ -50,43 +50,9 @@ void main() {
expect(tester.takeException(), isNull);
});
testWidgets('should_open_fullscreen_overlay_from_detail_cta_and_chip', (
tester,
) async {
await _pumpApp(tester);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('drawer-open-series')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('detail-cta')));
await tester.pumpAndSettle();
_expectFullscreenOverlay(tester);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('detail-episode-chip-2')));
await tester.pumpAndSettle();
_expectFullscreenOverlay(tester);
expect(
tester.widget<Text>(find.byKey(const Key('player-title'))).data,
contains('Episode 2'),
);
expect(tester.takeException(), isNull);
});
testWidgets('should_show_center_toggle_only_when_paused', (tester) async {
await _pumpApp(tester);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('drawer-open-series')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('detail-cta')));
await tester.pumpAndSettle();
await _openSeriesPlayer(tester);
expect(find.byKey(const Key('player-play-toggle')), findsNothing);
@@ -118,14 +84,7 @@ void main() {
tester,
) async {
await _pumpApp(tester);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('drawer-open-series')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('detail-cta')));
await tester.pumpAndSettle();
await _openSeriesPlayer(tester);
expect(find.byKey(const Key('player-controls-top')), findsOneWidget);
expect(find.byKey(const Key('player-controls-bottom')), findsOneWidget);
@@ -208,14 +167,7 @@ void main() {
testWidgets('should_fit_player_header_on_320_width', (tester) async {
await _pumpApp(tester, size: const Size(320, 568));
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('drawer-open-series')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('detail-cta')));
await tester.pumpAndSettle();
await _openSeriesPlayer(tester);
expect(
tester.getSize(find.byKey(const Key('player-back'))),
@@ -228,14 +180,7 @@ void main() {
tester,
) async {
await _pumpApp(tester);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('drawer-open-series')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('detail-cta')));
await tester.pumpAndSettle();
await _openSeriesPlayer(tester);
await tester.tap(find.byKey(const Key('player-clear-screen')));
await tester.pump();
@@ -259,14 +204,7 @@ void main() {
tester,
) async {
await _pumpApp(tester);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('drawer-open-series')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('detail-cta')));
await tester.pumpAndSettle();
await _openSeriesPlayer(tester);
await tester.tap(find.byKey(const Key('player-more')));
await tester.pumpAndSettle();
@@ -298,14 +236,7 @@ void main() {
tester,
) async {
await _pumpApp(tester);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('drawer-open-series')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('detail-cta')));
await tester.pumpAndSettle();
await _openSeriesPlayer(tester);
await tester.tap(find.byKey(const Key('player-more')));
await tester.pumpAndSettle();
@@ -349,143 +280,13 @@ void main() {
tester,
) async {
await _pumpApp(tester);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('drawer-open-series')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('detail-cta')));
await tester.pumpAndSettle();
await _openSeriesPlayer(tester);
final bar = tester.widget<SeekProgressBar>(
find.byKey(const Key('player-progress')),
);
expect(bar.showTimes, isTrue);
});
testWidgets('should_clear_and_restore_home_feed_chrome', (tester) async {
await _pumpApp(tester);
await tester.tap(find.byKey(const Key('tab-home')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('home-feed-title')), findsOneWidget);
expect(find.byKey(const Key('home-feed-info-card')), findsOneWidget);
expect(find.byKey(const Key('home-feed-scrim')), findsOneWidget);
expect(find.byKey(const Key('home-feed-center-play')), findsNothing);
await tester.tap(find.byKey(const Key('home-feed-clear-screen')));
await tester.pump();
expect(find.byKey(const Key('home-feed-title')), findsNothing);
expect(find.byKey(const Key('home-feed-info-card')), findsNothing);
expect(find.byKey(const Key('home-feed-scrim')), findsNothing);
expect(find.byKey(const Key('home-feed-video-tap')), findsOneWidget);
expect(
find.byKey(const Key('home-feed-exit-clear-screen')),
findsOneWidget,
);
expect(
tester.getSize(find.byKey(const Key('home-feed-exit-clear-screen'))),
const Size(36, 36),
);
expect(find.byKey(const Key('home-feed-center-play')), findsNothing);
expect(
find.ancestor(
of: find.byKey(const Key('home-feed-exit-clear-screen')),
matching: find.byType(SafeArea),
),
findsWidgets,
);
expect(
tester
.getTopLeft(find.byKey(const Key('home-feed-exit-clear-screen')))
.dy,
greaterThanOrEqualTo(8),
);
await tester.tapAt(const Offset(80, 300));
await tester.pump();
expect(find.byKey(const Key('home-feed-title')), findsNothing);
expect(
find.byKey(const Key('home-feed-exit-clear-screen')),
findsOneWidget,
);
expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget);
expect(
tester
.widget<PlayerCenterToggle>(
find.byKey(const Key('home-feed-center-play')),
)
.playing,
isFalse,
);
await tester.tapAt(const Offset(80, 300));
await tester.pump();
expect(find.byKey(const Key('home-feed-title')), findsNothing);
expect(
find.byKey(const Key('home-feed-exit-clear-screen')),
findsOneWidget,
);
expect(find.byKey(const Key('home-feed-center-play')), findsNothing);
await tester.tap(find.byKey(const Key('home-feed-exit-clear-screen')));
await tester.pump();
expect(find.byKey(const Key('home-feed-title')), findsOneWidget);
expect(find.byKey(const Key('home-feed-info-card')), findsOneWidget);
expect(find.byKey(const Key('home-feed-scrim')), findsOneWidget);
expect(find.byKey(const Key('home-feed-exit-clear-screen')), findsNothing);
expect(find.byKey(const Key('home-feed-center-play')), findsNothing);
});
testWidgets('should_show_home_center_toggle_only_when_paused', (
tester,
) async {
await _pumpApp(tester);
await tester.tap(find.byKey(const Key('tab-home')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('home-feed-center-play')), findsNothing);
await tester.tapAt(const Offset(80, 300));
await tester.pump();
expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget);
expect(
tester
.widget<PlayerCenterToggle>(
find.byKey(const Key('home-feed-center-play')),
)
.playing,
isFalse,
);
await tester.tap(find.byKey(const Key('home-feed-center-play')));
await tester.pump();
expect(find.byKey(const Key('home-feed-center-play')), findsNothing);
});
testWidgets('should_keep_home_clear_state_when_swiping_to_next_page', (
tester,
) async {
await _pumpApp(tester);
await tester.tap(find.byKey(const Key('tab-home')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('home-feed-clear-screen')));
await tester.pump();
expect(find.byKey(const Key('home-feed-title')), findsNothing);
await tester.drag(find.byType(PageView), const Offset(0, -550));
await tester.pumpAndSettle();
expect(find.byKey(const Key('home-feed-title')), findsNothing);
expect(find.byKey(const Key('home-feed-info-card')), findsNothing);
expect(
find.byKey(const Key('home-feed-exit-clear-screen')),
findsOneWidget,
);
expect(find.byKey(const Key('home-feed-center-play')), findsNothing);
});
}
void _expectFullscreenOverlay(WidgetTester tester) {
@@ -505,6 +306,13 @@ void _expectFullscreenOverlay(WidgetTester tester) {
expect(find.byKey(const Key('rail-save')), findsNothing);
}
Future<void> _openSeriesPlayer(WidgetTester tester) async {
await tester.tap(find.byKey(const Key('tab-theater')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('home-drama-card-city-lights-demo')));
await tester.pumpAndSettle();
}
Future<void> _pumpApp(
WidgetTester tester, {
Size size = const Size(390, 844),
+1 -1
View File
@@ -40,7 +40,7 @@ void main() {
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-my')));
await tester.tap(find.byKey(const Key('tab-mine')));
await tester.pumpAndSettle();
await tester.drag(find.byType(ListView), const Offset(0, -520));
await tester.pumpAndSettle();
+189 -505
View File
@@ -5,7 +5,12 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/app.dart';
import 'package:fruitshorts/core/data/models/comment.dart';
import 'package:fruitshorts/core/data/models/interaction.dart';
import 'package:fruitshorts/core/data/repositories/comment_repository.dart';
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
import 'package:fruitshorts/core/data/repositories/interaction_repository.dart';
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
import 'package:fruitshorts/core/data/services/playback_session.dart';
import 'package:fruitshorts/pages/player/player_view.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';
@@ -14,18 +19,8 @@ import 'support/fake_catalog.dart';
import 'support/fake_category.dart';
import 'support/fake_interaction_repositories.dart';
import 'support/widget_player.dart';
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
import 'package:fruitshorts/core/data/repositories/catalog_repository.dart';
import 'package:fruitshorts/core/data/repositories/comment_repository.dart';
import 'package:fruitshorts/core/data/repositories/interaction_repository.dart';
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
import 'package:fruitshorts/core/data/services/playback_session.dart';
void main() {
/// 默认按「已登录」起测:账号体系接上后,"登录"不再是本地演示开关,
/// 而是本地会话(这里直接给 shared_preferences 的内存实现塞一份会话)。
/// 昵称/uid 与演示文案保持一致,避免为显示细节改写既有断言。
void seedSignedInSession() {
SharedPreferencesAsyncPlatform
.instance = InMemorySharedPreferencesAsync.withData({
@@ -35,32 +30,20 @@ void main() {
});
}
void seedSignedOutSession() {
SharedPreferencesAsyncPlatform.instance =
InMemorySharedPreferencesAsync.empty();
}
setUp(seedSignedInSession);
setUp(() {
seedSignedInSession();
});
/// 所有 widget 测试都注入离线仓库:票据 / 进度 / 收藏都不碰网络,
/// 这样断言的是 UI 行为,而不是后端有没有起。
Widget appUnderTest({
PlayerFactory? playerFactory,
CatalogRepository? catalogRepository,
CommentRepository? commentRepository,
InteractionRepository? interactionRepository,
}) {
final catalog = catalogRepository ?? FakeCatalogRepository();
final catalog = FakeCatalogRepository();
return LumaDramaApp(
playerFactory: playerFactory ?? createWidgetPlayer,
catalogRepository: catalog,
categoryRepository: FakeCategoryRepository(catalog: catalog),
watchHistoryRepository: InMemoryWatchHistoryRepository(),
favoriteRepository: InMemoryFavoriteRepository(
cards: FakeCatalogRepository().dramas,
),
favoriteRepository: InMemoryFavoriteRepository(cards: catalog.dramas),
playbackRepository: FakePlaybackRepository(),
commentRepository: commentRepository ?? FakeCommentRepository(),
interactionRepository:
@@ -68,36 +51,48 @@ void main() {
);
}
testWidgets(
'should_promote_next_without_recreating_it_or_showing_loading_when_home_is_swiped',
(tester) async {
final created = <String>[];
await tester.pumpWidget(
appUnderTest(
playerFactory: (episode) {
created.add(episode.id);
return WidgetPlayer();
},
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-home')));
await tester.pumpAndSettle();
expect(created, hasLength(2));
expect(find.byType(CircularProgressIndicator), findsNothing);
await tester.drag(find.byType(PageView), const Offset(0, -550));
await tester.pump();
expect(find.byType(CircularProgressIndicator), findsNothing);
await tester.pumpAndSettle();
expect(find.text('City Lights & Velvet Nights'), findsOneWidget);
expect(created, hasLength(3));
expect(created.toSet(), hasLength(3));
await tester.pumpWidget(const SizedBox.shrink());
await tester.pumpAndSettle();
},
);
testWidgets('should_preload_next_episode_when_fullscreen_player_opens', (
tester,
) async {
final created = <String>[];
await tester.pumpWidget(
appUnderTest(
playerFactory: (episode) {
created.add(episode.id);
return WidgetPlayer();
},
),
);
await tester.pumpAndSettle();
await _openTheaterPlayer(tester);
testWidgets('should_open_series_detail_when_immersive_home_is_tapped', (
expect(created, hasLength(2));
expect(find.byType(CircularProgressIndicator), findsNothing);
await tester.drag(find.byType(PageView), const Offset(0, -550));
await tester.pumpAndSettle();
expect(
tester.widget<Text>(find.byKey(const Key('player-title'))).data,
contains('Episode 2'),
);
expect(created, hasLength(3));
expect(created.toSet(), hasLength(3));
});
testWidgets('should_open_fullscreen_player_when_home_card_is_tapped', (
tester,
) async {
await tester.pumpWidget(appUnderTest());
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('home-drama-card-the-signal-demo')));
await tester.pumpAndSettle();
final player = tester.widget<PlayerPage>(find.byType(PlayerPage));
expect(player.homeMode, isFalse);
expect(find.byKey(const Key('player-controls-top')), findsOneWidget);
});
testWidgets('should_keep_four_root_tabs_on_one_route_and_return_home', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
@@ -107,232 +102,12 @@ void main() {
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);
expect(find.byType(Slider), findsNothing);
expect(find.text('Home'), findsWidgets);
expect(find.byKey(const Key('home-feed-title')), findsOneWidget);
expect(find.byKey(const Key('home-feed-info-card')), findsOneWidget);
expect(find.byKey(const Key('rail-like')), findsOneWidget);
expect(find.byKey(const Key('rail-comments')), findsOneWidget);
expect(find.byKey(const Key('rail-share')), findsOneWidget);
expect(find.byKey(const Key('rail-save')), findsOneWidget);
await tester.tap(find.byKey(const Key('home-feed-more')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('home-feed-download')), findsOneWidget);
expect(find.byKey(const Key('home-feed-pip')), findsOneWidget);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(find.text('Watch Full'), findsNothing);
expect(find.byTooltip('Explore series'), findsNothing);
});
await _openTheaterPlayer(tester);
expect(find.byType(PlayerPage), findsOneWidget);
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();
await tester.tap(find.byKey(const Key('tab-discover')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('home-all-dramas-grid')), 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('7 EPISODES'), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.tap(find.byKey(const Key('drawer-open-series')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('detail-cta')), findsOneWidget);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(
tester
.widget<PlayerPage>(find.byType(PlayerPage, skipOffstage: false))
.active,
isFalse,
);
expect(find.byKey(const Key('home-all-dramas-grid')), findsOneWidget);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('drawer-discover')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('home-all-dramas-grid')), findsOneWidget);
expect(
Navigator.of(
tester.element(find.byKey(const Key('home-all-dramas-grid'))),
).canPop(),
isFalse,
);
},
);
testWidgets('should_follow_system_locale_without_language_switch', (
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.byTooltip('Captions'), findsNothing);
await tester.tap(find.byKey(const Key('tab-my')));
await tester.pumpAndSettle();
expect(find.text('Vicky sheng'), findsOneWidget);
expect(find.text('Coins'), findsOneWidget);
expect(find.text('App Language'), findsNothing);
expect(find.text('简体中文'), findsNothing);
expect(find.byKey(const Key('mine-wallet')), findsOneWidget);
expect(find.text('Home'), findsWidgets);
await tester.tap(find.byKey(const Key('tab-discover')));
await tester.pumpAndSettle();
expect(find.text('Discover'), findsWidgets);
});
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.byKey(const Key('home-drama-card-city-lights-demo')),
);
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.byKey(const Key('tab-home')));
await tester.pumpAndSettle();
expect(find.text('The Signal'), findsOneWidget);
},
);
testWidgets('should_fit_compact_dark_viewport_when_evening_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.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-home')));
await tester.pumpAndSettle();
expect(find.text('The Signal'), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.tap(find.byKey(const Key('tab-my')));
await tester.pumpAndSettle();
expect(find.text('Coins'), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets(
'should_show_three_playable_dramas_and_one_pending_poster_when_discover_is_opened',
(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-discover')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('discover-category-grid')), findsOneWidget);
expect(find.byKey(const Key('discover-ranking-section')), findsOneWidget);
expect(find.byKey(const Key('home-all-dramas-grid')), findsOneWidget);
expect(find.byKey(const Key('discover-profile')), findsOneWidget);
expect(
find.byKey(
const Key('home-drama-genre-city-lights-demo'),
skipOffstage: false,
),
findsOneWidget,
);
expect(
find.byKey(
const Key('home-drama-genre-vengeance-demo'),
skipOffstage: false,
),
findsOneWidget,
);
expect(find.byTooltip('Search'), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.tap(find.byKey(const Key('tab-my')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('mine-menu')), findsOneWidget);
await tester.tap(find.byKey(const Key('tab-home')));
await tester.pumpAndSettle();
expect(find.text('The Signal'), findsOneWidget);
},
);
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.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-discover')));
await tester.tap(find.byKey(const Key('player-back')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('home-all-dramas-grid')), findsOneWidget);
expect(find.byTooltip('Search'), findsOneWidget);
expect(
Navigator.of(
tester.element(find.byKey(const Key('home-all-dramas-grid'))),
@@ -340,278 +115,187 @@ void main() {
isFalse,
);
await tester.tap(find.byKey(const Key('tab-my')));
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(find.byKey(const Key('mine-history')), findsOneWidget);
expect(find.byKey(const Key('home-browse-page')), findsOneWidget);
await tester.tap(find.byKey(const Key('tab-create')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('create-page')), findsOneWidget);
await tester.tap(find.byKey(const Key('tab-mine')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('mine-menu')), findsOneWidget);
expect(
Navigator.of(tester.element(find.byKey(const Key('mine-menu')))).canPop(),
isFalse,
);
await tester.tap(find.byKey(const Key('tab-discover')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('home-all-dramas-grid')), findsOneWidget);
expect(find.byTooltip('Search'), findsOneWidget);
expect(
Navigator.of(
tester.element(find.byKey(const Key('home-all-dramas-grid'))),
).canPop(),
isFalse,
);
await tester.tap(find.byKey(const Key('tab-my')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('mine-menu')), findsOneWidget);
await tester.tap(find.byKey(const Key('tab-home')));
await tester.pumpAndSettle();
expect(find.text('The Signal'), findsOneWidget);
expect(
Navigator.of(tester.element(find.text('The Signal'))).canPop(),
isFalse,
);
});
testWidgets(
'should_change_drama_on_home_swipe_and_episode_on_player_swipe_when_swiping',
(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();
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, -550));
await tester.pumpAndSettle();
expect(find.text('City Lights & Velvet Nights'), findsOneWidget);
expect(
tester
.widget<Text>(find.byKey(const Key('home-feed-episode-title')))
.data,
contains('Episode 1'),
);
await tester.tap(find.byKey(const Key('tab-discover')));
await tester.pumpAndSettle();
await tester.tap(
find.byKey(const Key('home-drama-card-city-lights-demo')),
);
await tester.pumpAndSettle();
expect(find.byType(Slider), findsOneWidget);
await tester.drag(find.byType(PageView), const Offset(0, -550));
await tester.pumpAndSettle();
expect(
tester.widget<Text>(find.byKey(const Key('player-title'))).data,
contains('Episode 2'),
);
expect(find.textContaining('City Lights & Velvet Nights'), findsWidgets);
},
);
testWidgets('should_hide_category_navigation_when_shorts_page_is_shown', (
testWidgets('should_follow_system_locale_without_language_switch', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
await tester.pumpWidget(appUnderTest());
await tester.pumpAndSettle();
expect(find.byTooltip('Captions'), findsNothing);
await tester.tap(find.byKey(const Key('tab-mine')));
await tester.pumpAndSettle();
expect(find.text('Vicky sheng'), findsOneWidget);
expect(find.text('Coins'), findsOneWidget);
expect(find.text('App Language'), findsNothing);
expect(find.byKey(const Key('mine-wallet')), findsOneWidget);
await tester.tap(find.byKey(const Key('tab-theater')));
await tester.pumpAndSettle();
expect(find.text('Theater'), findsWidgets);
});
testWidgets('should_fit_compact_viewport_when_player_is_opened', (
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 _openTheaterPlayer(tester);
expect(find.byType(Slider), findsOneWidget);
await tester.drag(find.byType(PageView), const Offset(0, -500));
await tester.pumpAndSettle();
expect(find.text('Following'), findsNothing);
expect(find.text('Animated'), findsNothing);
expect(find.text('Live Action'), findsNothing);
expect(find.text('Recommended'), findsNothing);
expect(find.text('The Signal'), findsOneWidget);
await tester.drag(find.byType(PageView), const Offset(0, -550));
await tester.pumpAndSettle();
expect(find.text('City Lights & Velvet Nights'), findsOneWidget);
expect(
tester.widget<Text>(find.byKey(const Key('player-title'))).data,
contains('Episode 2'),
);
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,
),
);
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-comments'),
const Key('rail-share'),
const Key('rail-save'),
];
final tops = keys
.map((key) => tester.getTopLeft(find.byKey(key)).dy)
.toList();
expect(tops, orderedEquals(tops.toList()..sort()));
testWidgets('should_render_theater_with_filters_and_same_route_tabs', (
tester,
) async {
tester.view.physicalSize = const Size(360, 720);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
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.pumpWidget(appUnderTest());
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-theater')));
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);
},
);
expect(find.byKey(const Key('discover-search')), findsOneWidget);
expect(find.byKey(const Key('theater-category-chips')), findsOneWidget);
expect(find.byKey(const Key('theater-language-chips')), findsOneWidget);
expect(find.byKey(const Key('home-all-dramas-grid')), findsOneWidget);
expect(find.byKey(const Key('discover-profile')), findsOneWidget);
expect(
find.byKey(const Key('home-drama-card-city-lights-demo')),
findsOneWidget,
);
expect(tester.takeException(), isNull);
});
testWidgets('should_save_comment_like_and_share_from_player_more', (
tester,
) async {
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 _openTheaterPlayer(tester);
await tester.tap(find.byKey(const Key('player-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 _tapPlayerMore(tester, const Key('player-more-like'));
expect(interactions.likeTargets, contains('DRAMA:city-lights-demo'));
await _tapPlayerMore(tester, const Key('player-more-favorite'));
await _tapPlayerMore(tester, const Key('player-more-share'));
expect(sharedText, contains('City Lights & Velvet Nights'));
expect(sharedText, contains('FruitShorts'));
expect(tester.takeException(), isNull);
});
testWidgets('should_open_auth_gate_without_liking_when_signed_out', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
seedSignedOutSession();
SharedPreferencesAsyncPlatform.instance =
InMemorySharedPreferencesAsync.empty();
final interactions = FakeInteractionRepository();
await tester.pumpWidget(appUnderTest(interactionRepository: interactions));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-home')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('rail-like')));
await tester.pumpAndSettle();
await _openTheaterPlayer(tester);
await _tapPlayerMore(tester, const Key('player-more-like'));
expect(find.text('Sign in to continue'), findsOneWidget);
expect(interactions.likeTargets, isEmpty);
});
testWidgets('should_report_drama_from_detail_more_menu_when_submitted', (
tester,
) async {
testWidgets('should_show_saved_player_drama_in_favorites', (tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final interactions = FakeInteractionRepository();
await tester.pumpWidget(appUnderTest(interactionRepository: interactions));
await tester.pumpWidget(appUnderTest());
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-discover')));
await _openTheaterPlayer(tester);
await _tapPlayerMore(tester, const Key('player-more-favorite'));
await tester.tap(find.byKey(const Key('player-back')));
await tester.pumpAndSettle();
await tester.binding.handlePopRoute();
await tester.tap(find.byKey(const Key('tab-mine')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('drawer-open-series')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('detail-more')));
await tester.pumpAndSettle();
await tester.tap(find.text('Report drama'));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('report-submit')));
await tester.tap(find.byKey(const Key('mine-watchlist')));
await tester.pumpAndSettle();
expect(interactions.reports.single.targetType, InteractionTargetType.drama);
expect(find.text('Report submitted. Thank you.'), findsOneWidget);
expect(find.text('City Lights & Velvet Nights'), findsWidgets);
});
}
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();
Future<void> _openTheaterPlayer(WidgetTester tester) async {
await tester.tap(find.byKey(const Key('tab-theater')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('home-drama-card-city-lights-demo')));
await tester.pumpAndSettle();
}
await tester.tap(find.byKey(const Key('tab-discover')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('home-all-dramas-grid')), 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.byKey(const Key('home-all-dramas-grid')), 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();
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')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('mine-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.byKey(const Key('detail-cta')), findsOneWidget);
},
);
Future<void> _tapPlayerMore(WidgetTester tester, Key action) async {
await tester.tap(find.byKey(const Key('player-more')));
await tester.pumpAndSettle();
await tester.ensureVisible(find.byKey(action));
await tester.pumpAndSettle();
await tester.tap(find.byKey(action));
await tester.pumpAndSettle();
}