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

+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();
}