feat(app): 客户端展示多语言并支持筛选分页

This commit is contained in:
Zhou Weidong committed 2026-10-24 17:20:24 +08:00
1 parent 8481611372
commit 8b50b5bd06
68 files changed
+2742 -1120

No files matched your search

@@ -2,7 +2,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/core/data/services/home_feed_controller.dart';
import 'package:fruitshorts/core/data/models/content_category.dart';
import 'package:fruitshorts/core/data/services/all_dramas_controller.dart';
import 'package:fruitshorts/core/theme/app_dimens.dart';
import 'package:fruitshorts/l10n/app_localizations.dart';
import 'package:fruitshorts/pages/recommend/widgets/all_dramas_filter_grid.dart';
@@ -12,9 +13,21 @@ import '../support/fake_catalog.dart';
void main() {
testWidgets('all filter rows start at the same left edge', (tester) async {
final catalog = FakeCatalogRepository();
final controller = HomeFeedController(catalog)
..seedRecommend(catalog.dramas);
addTearDown(controller.dispose);
final controller = AllDramasController.preview(
classifications: const [
ContentCategory(id: 'local', name: 'Local'),
ContentCategory(id: 'asia', name: 'Asia'),
],
categories: const [
ContentCategory(id: 'subtitles', name: 'Subtitles'),
ContentCategory(id: 'dubbed', name: 'Dubbed'),
],
tags: const [
ContentCategory(id: 'reversal', name: 'Reversal'),
ContentCategory(id: 'uplifting', name: 'Uplifting'),
],
dramas: catalog.dramas,
);
await tester.pumpWidget(
MaterialApp(
@@ -23,7 +36,7 @@ void main() {
localizationsDelegates: AppLocalizations.localizationsDelegates,
home: Scaffold(
body: AllDramasFilterGrid(
feedController: controller,
controller: controller,
onOpenDrama: (_) {},
),
),
@@ -33,19 +46,9 @@ void main() {
expect(AppDimens.allDramasHorizontal, 12);
final firstChips = [
find.descendant(
of: find.byKey(const Key('all-filter-row-0')),
matching: find.byKey(const Key('all-filter-all')),
),
find.descendant(
of: find.byKey(const Key('all-filter-row-1')),
matching: find.byKey(const Key('all-filter-all')),
),
find.descendant(
of: find.byKey(const Key('all-filter-row-2')),
matching: find.byKey(const Key('all-filter-all')),
),
find.byKey(const Key('all-sort-hot')),
find.byKey(const Key('all-filter-classification-all')),
find.byKey(const Key('all-filter-category-all')),
find.byKey(const Key('all-filter-tag-all')),
];
final starts = firstChips
.map((finder) => tester.getTopLeft(finder).dx)
@@ -57,9 +60,9 @@ void main() {
}
final rowZeroChips = [
find.byKey(const Key('all-filter-all')).first,
find.byKey(const Key('all-filter-local')),
find.byKey(const Key('all-filter-asia')),
find.byKey(const Key('all-filter-classification-all')),
find.byKey(const Key('all-filter-classification-local')),
find.byKey(const Key('all-filter-classification-asia')),
];
final rowZeroRects = rowZeroChips.map(tester.getRect).toList();
final rowZeroGaps = [
@@ -69,12 +72,9 @@ void main() {
expect(rowZeroGaps[0], closeTo(10, 0.5));
expect(rowZeroGaps[1], closeTo(rowZeroGaps[0], 0.5));
final rowOneAll = find.descendant(
of: find.byKey(const Key('all-filter-row-1')),
matching: find.byKey(const Key('all-filter-all')),
);
final rowOneSubtitles = find.byKey(const Key('all-filter-subtitles'));
final rowOneDubbed = find.byKey(const Key('all-filter-dubbed'));
final rowOneAll = find.byKey(const Key('all-filter-category-all'));
final rowOneSubtitles = find.byKey(const Key('all-filter-category-subtitles'));
final rowOneDubbed = find.byKey(const Key('all-filter-category-dubbed'));
final rowOneGap =
tester.getTopLeft(rowOneSubtitles).dx -
tester.getTopRight(rowOneAll).dx;
@@ -85,12 +85,9 @@ void main() {
closeTo(rowOneGap, 0.5),
);
final rowTwoAll = find.descendant(
of: find.byKey(const Key('all-filter-row-2')),
matching: find.byKey(const Key('all-filter-all')),
);
final rowTwoReversal = find.byKey(const Key('all-filter-reversal'));
final rowTwoUplifting = find.byKey(const Key('all-filter-uplifting'));
final rowTwoAll = find.byKey(const Key('all-filter-tag-all'));
final rowTwoReversal = find.byKey(const Key('all-filter-tag-reversal'));
final rowTwoUplifting = find.byKey(const Key('all-filter-tag-uplifting'));
final rowTwoGap =
tester.getTopLeft(rowTwoReversal).dx - tester.getTopRight(rowTwoAll).dx;
expect(rowTwoGap, closeTo(10, 0.5));
@@ -99,11 +96,5 @@ void main() {
tester.getTopRight(rowTwoReversal).dx,
closeTo(rowTwoGap, 0.5),
);
expect(
tester.getTopLeft(find.byKey(const Key('all-sort-new'))).dx -
tester.getTopRight(find.byKey(const Key('all-sort-hot'))).dx,
closeTo(10, 0.5),
);
});
}
+29 -130
View File
@@ -34,7 +34,7 @@ void main() {
expect(find.byKey(const Key('recommend-tab-recommend')), findsOneWidget);
expect(find.byKey(const Key('recommend-tab-playlist')), findsOneWidget);
expect(find.byKey(const Key('recommend-tab-all')), findsOneWidget);
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
expect(find.byKey(const Key('recommend-feed-player'), skipOffstage: false), findsOneWidget);
expect(find.byKey(const Key('recommend-top-gradient')), findsOneWidget);
final recommendText = tester.widget<Text>(
find.descendant(
@@ -81,12 +81,12 @@ void main() {
tester
.getRect(find.byKey(const Key('recommend-top-nav')))
.overlaps(
tester.getRect(find.byKey(const Key('recommend-feed-player'))),
tester.getRect(find.byKey(const Key('recommend-feed-player'), skipOffstage: false)),
),
isTrue,
);
final player = tester.widget<PlayerPage>(
find.byKey(const Key('recommend-feed-player')),
find.byKey(const Key('recommend-feed-player'), skipOffstage: false),
);
expect(player.homeMode, isTrue);
expect(player.embedded, isTrue);
@@ -227,15 +227,9 @@ void main() {
);
expect(viewIcon, findsOneWidget);
final badge = find.byKey(
const Key('drama-cover-badge-ribbon-hits-the-signal-demo-hot'),
const Key('drama-cover-badge-ribbon-hits-the-signal-demo-tag'),
);
expect(badge, findsOneWidget);
final badgeText = tester.widget<Text>(
find.descendant(of: badge, matching: find.byType(Text)),
);
expect(badgeText.data, 'Hit');
expect(badgeText.style?.fontSize, AppDimens.cardBadgeFont);
expect(badgeText.style?.color, AppColors.textPrimary);
expect(badge, findsNothing);
final tagsFinder = find.byKey(
const Key('recommend-tags-hits-the-signal-demo'),
);
@@ -309,7 +303,7 @@ void main() {
expect(delegate.crossAxisCount, 3);
expect(delegate.crossAxisSpacing, AppDimens.allDramasGridGap);
expect(delegate.mainAxisSpacing, AppDimens.allDramasGridRowGap);
for (var row = 0; row < 4; row++) {
for (var row = 0; row < 3; row++) {
expect(find.byKey(Key('all-filter-row-$row')), findsOneWidget);
final scroll = tester.widget<SingleChildScrollView>(
find.byKey(Key('all-filter-scroll-$row')),
@@ -318,7 +312,7 @@ void main() {
expect(scroll.physics, isA<BouncingScrollPhysics>());
}
final filterStarts = [
for (var row = 0; row < 4; row++)
for (var row = 0; row < 3; row++)
tester.getRect(find.byKey(Key('all-filter-row-$row'))).left,
];
expect(
@@ -326,7 +320,7 @@ void main() {
everyElement(closeTo(AppDimens.allDramasHorizontal, 0.1)),
);
final pageRect = tester.getRect(find.byKey(const Key('recommend-page')));
for (var row = 0; row < 4; row++) {
for (var row = 0; row < 3; row++) {
final rowRect = tester.getRect(find.byKey(Key('all-filter-row-$row')));
expect(
rowRect.left,
@@ -347,10 +341,6 @@ void main() {
of: find.byKey(const Key('all-filter-row-2')),
matching: find.byType(Text),
),
find.descendant(
of: find.byKey(const Key('all-filter-row-3')),
matching: find.byType(Text),
),
];
final firstTextX = firstTexts
.map((finder) => tester.getTopLeft(finder.first).dx)
@@ -365,14 +355,14 @@ void main() {
0.1,
),
);
for (var row = 0; row < 3; row++) {
for (var row = 0; row < 2; row++) {
expect(
tester.getSize(find.byKey(Key('all-filter-row-$row'))).height,
AppDimens.filterChipHeight + AppDimens.filterRowGap,
);
}
expect(
tester.getSize(find.byKey(const Key('all-filter-row-3'))).height,
tester.getSize(find.byKey(const Key('all-filter-row-2'))).height,
AppDimens.filterChipHeight,
);
expect(
@@ -406,112 +396,31 @@ void main() {
tester.getRect(find.byKey(const Key('all-dramas-filters'))).top,
closeTo(fixedFilterTop, 0.1),
);
expect(find.byKey(const Key('all-filter-local')), findsOneWidget);
expect(_textStyle(tester, 'Local').color, AppColors.filterChipTextInactive);
expect(find.byKey(const Key('all-filter-subtitles')), findsOneWidget);
for (final key in [
'all-filter-reversal',
'all-filter-uplifting',
'all-filter-modern',
'all-filter-sweet',
'all-filter-angst',
]) {
expect(find.byKey(Key(key)), findsOneWidget);
}
final rowZero = find.byKey(const Key('all-filter-row-0'));
final rowZeroAll = find.descendant(
of: rowZero,
matching: find.byKey(const Key('all-filter-all')),
);
final rowZeroLocal = find.descendant(
of: rowZero,
matching: find.byKey(const Key('all-filter-local')),
);
expect(find.byKey(const Key('all-filter-classification-all')), findsOneWidget);
expect(find.byKey(const Key('all-filter-category-all')), findsOneWidget);
expect(find.byKey(const Key('all-filter-tag-all')), findsOneWidget);
expect(
tester.getTopLeft(rowZeroAll).dx,
closeTo(pageRect.left + AppDimens.allDramasHorizontal, 0.1),
);
expect(
tester.getTopLeft(rowZeroLocal).dx - tester.getTopRight(rowZeroAll).dx,
AppDimens.filterItemGap,
);
final rowOne = find.byKey(const Key('all-filter-row-1'));
final rowTwo = find.byKey(const Key('all-filter-row-2'));
for (final row in [rowOne, rowTwo]) {
final all = find.descendant(
of: row,
matching: find.byKey(const Key('all-filter-all')),
);
final next = find.descendant(
of: row,
matching: row == rowOne
? find.byKey(const Key('all-filter-subtitles'))
: find.byKey(const Key('all-filter-reversal')),
);
expect(
tester.getTopLeft(next).dx - tester.getTopRight(all).dx,
AppDimens.filterItemGap,
);
}
expect(
tester.getTopLeft(find.byKey(const Key('all-sort-new'))).dx -
tester.getTopRight(find.byKey(const Key('all-sort-hot'))).dx,
AppDimens.filterItemGap,
);
await tester.tap(find.byKey(const Key('all-filter-local')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('all-dramas-empty')), findsOneWidget);
expect(_textStyle(tester, 'Local').fontWeight, FontWeight.w600);
expect(_textStyle(tester, 'Local').fontSize, AppDimens.filterChipFont);
expect(_textStyle(tester, 'Local').color, AppColors.filterChipTextSelected);
final selectedChip = tester.widget<Container>(
find
.descendant(
of: find.byKey(const Key('all-filter-local')),
matching: find.byType(Container),
tester
.widget<Text>(
find.descendant(
of: find.byKey(const Key('all-filter-classification-all')),
matching: find.text('All'),
),
)
.first,
);
expect(
(selectedChip.decoration! as BoxDecoration).color,
AppColors.filterChipSelected,
);
expect(
tester.getSize(find.byKey(const Key('all-filter-local'))).height,
AppDimens.filterChipHeight,
);
await tester.tap(find.byKey(const Key('all-filter-all')).first);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('all-sort-new')));
await tester.pump();
expect(_textStyle(tester, 'New').fontWeight, FontWeight.w600);
expect(_textStyle(tester, 'New').fontSize, AppDimens.filterChipFont);
expect(_textStyle(tester, 'New').color, AppColors.filterChipTextSelected);
expect(
tester.getSize(find.byKey(const Key('all-sort-new'))).height,
AppDimens.filterChipHeight,
);
final chipContainer = tester.widget<Container>(
find.descendant(
of: find.byKey(const Key('all-sort-new')),
matching: find.byType(Container),
),
);
expect(
(chipContainer.decoration! as BoxDecoration).borderRadius,
BorderRadius.circular(AppDimens.filterChipRadius),
.style
?.color,
AppColors.filterChipTextSelected,
);
expect(find.byKey(const Key('all-dramas-filter-page')), findsNothing);
await tester.tap(find.byKey(const Key('recommend-tab-playlist')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('recommend-section-hits')), findsOneWidget);
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
expect(find.byKey(const Key('recommend-feed-player'), skipOffstage: false), findsOneWidget);
expect(find.byType(AppBottomNav), findsOneWidget);
await tester.tap(find.byKey(const Key('recommend-tab-all')));
await tester.pumpAndSettle();
expect(_textStyle(tester, 'New').fontWeight, FontWeight.w700);
expect(find.byKey(const Key('all-dramas-grid')), findsOneWidget);
});
@@ -527,7 +436,7 @@ void main() {
await tester.drag(pages, const Offset(-320, 0));
await tester.pumpAndSettle();
expect(find.byKey(const Key('recommend-section-hits')), findsOneWidget);
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
expect(find.byKey(const Key('recommend-feed-player'), skipOffstage: false), findsOneWidget);
expect(
tester
.widget<Text>(
@@ -551,7 +460,7 @@ void main() {
await tester.drag(pages, const Offset(640, 0));
await tester.pumpAndSettle();
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
expect(find.byKey(const Key('recommend-feed-player'), skipOffstage: false), findsOneWidget);
expect(find.byKey(const Key('recommend-tab-recommend')), findsOneWidget);
});
@@ -585,7 +494,7 @@ void main() {
await _pumpRecommend(tester);
final gesture = await tester.startGesture(
tester.getCenter(find.byKey(const Key('recommend-feed-player'))),
tester.getCenter(find.byKey(const Key('recommend-feed-player'), skipOffstage: false)),
);
await gesture.moveBy(const Offset(0, 80));
await tester.pump();
@@ -593,7 +502,7 @@ void main() {
final feedScroll = tester.state<ScrollableState>(
find
.descendant(
of: find.byKey(const Key('recommend-feed-player')),
of: find.byKey(const Key('recommend-feed-player'), skipOffstage: false),
matching: find.byType(Scrollable),
)
.first,
@@ -621,7 +530,8 @@ void main() {
final player = tester.widget<PlayerPage>(find.byType(PlayerPage).last);
expect(player.homeMode, isFalse);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
await tester.tap(find.byKey(const Key('recommend-search')));
await tester.pumpAndSettle();
@@ -632,17 +542,6 @@ void main() {
});
}
TextStyle _textStyle(WidgetTester tester, String text) {
return tester
.widget<Text>(
find.descendant(
of: find.byKey(const Key('all-sort-new')),
matching: find.text(text),
),
)
.style!;
}
Future<void> _pumpRecommend(WidgetTester tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;