feat: 统一首页与推荐搜索入口

This commit is contained in:
Zhou Weidong committed 2026-10-22 22:48:21 +08:00
1 parent 933333b0fe
commit 9aa797504b
18 files changed
+325 -107

No files matched your search

-38
View File
@@ -23,44 +23,6 @@ void main() {
logic.dispose();
});
testWidgets('should_focus_search_only_for_new_request_on_active_page', (
tester,
) async {
final logic = DiscoverLogic();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: TextField(
controller: logic.search,
focusNode: logic.searchFocus,
),
),
),
);
logic.syncSearch(
active: false,
request: 1,
previousRequest: 0,
isActive: () => false,
);
await tester.pump();
expect(logic.searchFocus.hasFocus, isFalse);
logic.syncSearch(
active: true,
request: 2,
previousRequest: 1,
isActive: () => true,
);
await tester.pump();
await tester.pump();
expect(logic.searchFocus.hasFocus, isTrue);
await tester.pumpWidget(const SizedBox.shrink());
logic.dispose();
});
testWidgets('should_forward_action_when_embedded_or_pop_when_standalone', (
tester,
) async {
+1 -8
View File
@@ -42,23 +42,17 @@ void main() {
logic.select(1);
expect(logic.tab, 1);
expect(logic.searchRequest, 0);
expect(logic.resumeRequest, 0);
expect(logic.backRequest, 0);
expect(notifications, 1);
logic.dispose();
});
test('should_raise_only_its_own_counter_when_each_select_flag_is_used', () {
test('should_raise_only_resume_counter_when_select_flag_is_used', () {
final logic = HomeLogic(dramas);
logic.select(1, search: true);
expect(logic.searchRequest, 1);
expect(logic.resumeRequest, 0);
logic.select(0, resume: true);
expect(logic.resumeRequest, 1);
expect(logic.searchRequest, 1);
logic.dispose();
});
@@ -161,7 +155,6 @@ void main() {
logic.myAction(MyPageAction.recommend);
expect(logic.tab, 1);
expect(logic.searchRequest, 1);
logic.myAction(MyPageAction.following);
expect(logic.tab, 2);
+20 -1
View File
@@ -118,6 +118,10 @@ void main() {
await _pumpApp(tester);
await tester.tap(find.byKey(const Key('home-search-entry')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('search-page')), findsOneWidget);
expect(find.byKey(const Key('search-back')), findsOneWidget);
expect(find.byKey(const Key('search-cancel')), findsOneWidget);
expect(find.byType(AppBottomNav), findsNothing);
expect(
tester
.widget<TextField>(find.byKey(const Key('discover-search')))
@@ -125,7 +129,7 @@ void main() {
?.hasFocus,
isTrue,
);
await tester.binding.handlePopRoute();
await tester.tap(find.byKey(const Key('search-cancel')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-recommend')));
@@ -133,6 +137,20 @@ void main() {
await tester.tap(find.byKey(const Key('recommend-search')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('discover-search')), findsOneWidget);
await tester.enterText(find.byKey(const Key('discover-search')), 'signal');
await tester.pump(const Duration(milliseconds: 400));
await tester.pumpAndSettle();
expect(find.byKey(const Key('search-results-grid')), findsOneWidget);
final results = tester.widget<GridView>(
find.byKey(const Key('search-results-grid')),
);
final delegate =
results.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount;
expect(delegate.crossAxisCount, 3);
await tester.tap(find.byKey(const Key('search-back')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('recommend-page')), findsOneWidget);
expect(find.byKey(const Key('recommend-tab-recommend')), findsOneWidget);
});
testWidgets('should_open_player_from_home_grid_card', (tester) async {
@@ -188,6 +206,7 @@ Future<void> _pumpApp(
playerFactory: createWidgetPlayer,
catalogRepository: catalog,
categoryRepository: FakeCategoryRepository(catalog: catalog),
searchRepository: catalog,
watchHistoryRepository: InMemoryWatchHistoryRepository(),
favoriteRepository: InMemoryFavoriteRepository(cards: catalog.dramas),
playbackRepository: FakePlaybackRepository(),