feat(flutter): 新增剧场筛选页

This commit is contained in:
Zhou Weidong committed 2026-10-20 15:39:46 +08:00
1 parent 85ba2a4fec
commit 850f8e7c8c
12 files changed
+1012 -52

No files matched your search

+218
View File
@@ -0,0 +1,218 @@
// 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/content_category.dart';
import 'package:fruitshorts/core/data/models/drama.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: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_expand_all_filter_groups_when_expand_is_tapped', (
tester,
) async {
await _pumpFilterPage(tester);
expect(find.byKey(const Key('filter-page')), findsOneWidget);
expect(
find.byKey(const Key('filter-group-label-category')),
findsOneWidget,
);
expect(find.byKey(const Key('filter-group-label-theme')), findsOneWidget);
expect(find.byKey(const Key('filter-group-label-language')), findsNothing);
expect(find.byKey(const Key('filter-group-label-sort')), findsNothing);
await tester.tap(find.byKey(const Key('filter-expand')));
await tester.pumpAndSettle();
expect(
find.byKey(const Key('filter-group-label-language')),
findsOneWidget,
);
expect(find.byKey(const Key('filter-group-label-sort')), findsOneWidget);
});
testWidgets('should_filter_and_sort_dramas_when_options_are_tapped', (
tester,
) async {
await _pumpFilterPage(tester);
await tester.tap(find.byKey(const Key('filter-expand')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('filter-option-category-Romance')));
await tester.pumpAndSettle();
expect(
find.descendant(
of: find.byKey(const Key('filter-group-label-category')),
matching: find.text('Romance'),
),
findsOneWidget,
);
expect(find.byKey(const Key('filter-card-1001')), findsOneWidget);
expect(find.byKey(const Key('filter-card-1003')), findsOneWidget);
expect(find.byKey(const Key('filter-card-1002')), findsNothing);
await tester.tap(find.byKey(const Key('filter-option-sort-hottest')));
await tester.pumpAndSettle();
final hottestFirst = tester.getTopLeft(
find.byKey(const Key('filter-card-1001')),
);
final hottestSecond = tester.getTopLeft(
find.byKey(const Key('filter-card-1003')),
);
expect(hottestFirst.dx, lessThan(hottestSecond.dx));
await tester.tap(find.byKey(const Key('filter-option-sort-newest')));
await tester.pumpAndSettle();
final newestFirst = tester.getTopLeft(
find.byKey(const Key('filter-card-1003')),
);
final newestSecond = tester.getTopLeft(
find.byKey(const Key('filter-card-1001')),
);
expect(newestFirst.dx, lessThan(newestSecond.dx));
});
testWidgets('should_open_player_when_filter_card_is_tapped', (tester) async {
await _pumpFilterPage(tester);
expect(find.byKey(const Key('filter-badge-hot-1001')), findsOneWidget);
expect(find.byKey(const Key('filter-badge-hot-1003')), findsNothing);
final meta = tester.widget<Text>(find.byKey(const Key('filter-meta-1001')));
expect(meta.data, contains('12'));
expect(meta.data, contains('300'));
expect(meta.data, contains('Romance'));
await tester.tap(find.byKey(const Key('filter-card-1001')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('player-scaffold')), findsOneWidget);
});
testWidgets('should_show_empty_state_when_filters_match_nothing', (
tester,
) async {
await _pumpFilterPage(tester);
await tester.tap(find.byKey(const Key('filter-expand')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('filter-option-category-Romance')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('filter-option-language-en')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('filter-empty')), findsOneWidget);
});
}
Future<void> _pumpFilterPage(WidgetTester tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final catalog = FakeCatalogRepository(dramas: _filterDramas);
await tester.pumpWidget(
LumaDramaApp(
playerFactory: createWidgetPlayer,
catalogRepository: catalog,
searchRepository: catalog,
categoryRepository: FakeCategoryRepository(
catalog: catalog,
categories: const [
ContentCategory(id: '1', name: 'Romance'),
ContentCategory(id: '2', name: 'Action'),
],
),
watchHistoryRepository: InMemoryWatchHistoryRepository(),
favoriteRepository: InMemoryFavoriteRepository(cards: catalog.dramas),
playbackRepository: FakePlaybackRepository(),
commentRepository: FakeCommentRepository(),
interactionRepository: FakeInteractionRepository(),
haptics: FakeHaptics(),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-theater')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('theater-toolbar-filter')));
await tester.pumpAndSettle();
}
final List<Drama> _filterDramas = [
_drama(
id: '1001',
title: 'Alpha',
category: 'Romance',
genre: 'Suspense · Mystery',
language: 'id',
viewCount: 300,
isHot: true,
),
_drama(
id: '1002',
title: 'Beta',
category: 'Action',
genre: 'Action · Thriller',
language: 'en',
viewCount: 500,
),
_drama(
id: '1003',
title: 'Gamma',
category: 'Romance',
genre: 'Suspense',
language: 'zh-CN',
viewCount: 100,
),
];
Drama _drama({
required String id,
required String title,
required String category,
required String genre,
required String language,
required int viewCount,
bool isHot = false,
}) {
return Drama(
id: id,
title: title,
synopsis: '$title synopsis',
posterUrl: '',
category: category,
genre: genre,
totalEpisodes: 12,
viewCount: viewCount,
language: language,
isHot: isHot,
detailLoaded: true,
episodes: [
Episode(
id: '$id-1',
number: 1,
title: 'Episode 1',
isFree: true,
videoUrl: 'https://example.test/$id.mp4',
),
],
);
}
+7 -12
View File
@@ -51,25 +51,20 @@ void main() {
expect(tester.takeException(), isNull);
});
testWidgets('should_open_filter_sheet_and_apply_category', (tester) async {
testWidgets('should_open_filter_page_from_theater_toolbar', (tester) async {
await _pumpTheater(tester, categoryRepository: _GridCategoryRepository());
await tester.tap(find.byKey(const Key('theater-toolbar-filter')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('theater-filter-sheet')), findsOneWidget);
await tester.tap(find.byKey(const Key('theater-filter-option-7')));
expect(find.byKey(const Key('filter-page')), findsOneWidget);
expect(find.byKey(const Key('filter-groups')), findsOneWidget);
await tester.tap(find.byKey(const Key('filter-back')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('theater-filter-sheet')), findsNothing);
expect(
find.byKey(const Key('home-drama-card-city-lights-demo')),
findsOneWidget,
);
expect(
find.byKey(const Key('home-drama-card-the-signal-demo')),
findsNothing,
);
expect(find.byKey(const Key('filter-page')), findsNothing);
expect(find.byKey(const Key('discover-search')), findsOneWidget);
});
testWidgets('should_filter_grid_when_category_chip_is_tapped', (