fix(home): 修正首页分类与卡片布局
This commit is contained in:
1 parent
10477562d4
commit
aa4870cce6
14 files changed
+573
-459
No files matched your search
@@ -11,6 +11,7 @@ import 'package:fruitshorts/core/data/repositories/catalog_repository.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/home/widgets/home_feed_card.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';
|
||||
@@ -88,29 +89,82 @@ void main() {
|
||||
expect(find.byKey(const Key('home-tag-uplifting')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('should_open_existing_pages_from_home_sections', (tester) async {
|
||||
testWidgets('should_switch_home_sections_without_pushing_pages', (
|
||||
tester,
|
||||
) async {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(tester, repository);
|
||||
|
||||
String firstDramaId() {
|
||||
return tester
|
||||
.widget<HomeFeedCard>(find.byType(HomeFeedCard).first)
|
||||
.drama
|
||||
.id;
|
||||
}
|
||||
|
||||
expect(find.byKey(const Key('home-grid')), findsOneWidget);
|
||||
expect(firstDramaId(), 'page1-0');
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-section-new')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('new-releases-page')), findsOneWidget);
|
||||
await tester.pageBack();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('new-releases-page')), findsNothing);
|
||||
expect(firstDramaId(), 'page1-9');
|
||||
|
||||
await tester.ensureVisible(find.byKey(const Key('home-section-ranking')));
|
||||
await tester.tap(find.byKey(const Key('home-section-ranking')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('ranking-page')), findsOneWidget);
|
||||
await tester.pageBack();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('ranking-page')), findsNothing);
|
||||
expect(firstDramaId(), 'page1-0');
|
||||
|
||||
await tester.ensureVisible(
|
||||
find.byKey(const Key('home-section-categories')),
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('home-section-categories')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('filter-page')), findsOneWidget);
|
||||
expect(find.byKey(const Key('filter-page')), findsNothing);
|
||||
expect(find.byKey(const Key('home-grid-cards')), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-section-category-古装')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(firstDramaId(), 'page1-0');
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-section-category-社群')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('home-grid-empty')), findsOneWidget);
|
||||
expect(find.byKey(const Key('filter-page')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('should_keep_scroll_position_when_switching_sections', (
|
||||
tester,
|
||||
) async {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(tester, repository);
|
||||
|
||||
await tester.drag(
|
||||
find.byKey(const Key('home-grid-scroll')),
|
||||
const Offset(0, -320),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final scrollable = find
|
||||
.descendant(
|
||||
of: find.byKey(const Key('home-grid-scroll')),
|
||||
matching: find.byType(Scrollable),
|
||||
)
|
||||
.first;
|
||||
final before = tester.state<ScrollableState>(scrollable).position.pixels;
|
||||
expect(before, greaterThan(0));
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-section-new')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('home-section-featured')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final afterScrollable = find
|
||||
.descendant(
|
||||
of: find.byKey(const Key('home-grid-scroll')),
|
||||
matching: find.byType(Scrollable),
|
||||
)
|
||||
.first;
|
||||
expect(
|
||||
tester.state<ScrollableState>(afterScrollable).position.pixels,
|
||||
closeTo(before, 0.1),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('should_load_next_page_without_expanding_page_size', (
|
||||
@@ -232,14 +286,16 @@ class _PagedCatalogRepository implements CatalogRepository {
|
||||
}
|
||||
|
||||
Drama _drama(String id) {
|
||||
final index = int.tryParse(id.split('-').last) ?? 0;
|
||||
return Drama(
|
||||
id: id,
|
||||
title: 'Grid Drama $id',
|
||||
synopsis: 'synopsis',
|
||||
posterUrl: '',
|
||||
genre: 'Romance',
|
||||
category: 'Urban',
|
||||
viewCount: 200000,
|
||||
category: index.isEven ? '古装' : 'Urban',
|
||||
viewCount: (10 - index) * 10000,
|
||||
createdAt: DateTime(2026, 10, 1).add(Duration(days: index)),
|
||||
detailLoaded: true,
|
||||
episodes: [
|
||||
Episode(
|
||||
|
||||
Reference in new issue
Block a user