test: 按新 UI 基线重写过期用例
覆盖 155 条失败与 4 处编译错误:入口改走推荐流 tab、弹框换 AppGlowDialog、 rail 尺寸与底部锚定、子页标题字重 w400、底栏选中品牌红、收藏文案改收藏短剧。 全量 flutter test 775 通过。
This commit is contained in:
1 parent
799f3d1b7d
commit
1d4ab5e0e6
33 files changed
+853
-1114
No files matched your search
@@ -11,9 +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/core/theme/app_dimens.dart';
|
||||
import 'package:fruitshorts/pages/home/widgets/home_feed_card.dart';
|
||||
import 'package:fruitshorts/pages/home/widgets/home_feed_grid.dart';
|
||||
import 'package:fruitshorts/core/theme/app_colors.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';
|
||||
@@ -38,36 +36,44 @@ void main() {
|
||||
InMemorySharedPreferencesAsync.empty();
|
||||
});
|
||||
|
||||
testWidgets('should_render_primary_sections_and_secondary_tags_in_order', (
|
||||
tester,
|
||||
) async {
|
||||
testWidgets('should_render_inner_top_tabs_in_order', (tester) async {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(tester, repository);
|
||||
|
||||
final sectionKeys = [
|
||||
const Key('home-section-category-古装'),
|
||||
const Key('home-section-category-社群'),
|
||||
const Key('home-section-category-爽剧'),
|
||||
const Key('home-section-category-甜宠'),
|
||||
const Key('home-section-category-打脸虐渣'),
|
||||
const Key('home-section-category-虐恋'),
|
||||
final tabKeys = [
|
||||
const Key('recommend-tab-recommend'),
|
||||
const Key('recommend-tab-playlist'),
|
||||
const Key('recommend-tab-all'),
|
||||
];
|
||||
final sectionCenters = sectionKeys
|
||||
final centers = tabKeys
|
||||
.map((key) => tester.getCenter(find.byKey(key)).dx)
|
||||
.toList();
|
||||
expect(sectionCenters, orderedEquals(sectionCenters.toList()..sort()));
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
expect(centers, orderedEquals(centers.toList()..sort()));
|
||||
expect(find.byKey(const Key('recommend-section-hits')), findsNothing);
|
||||
expect(find.text('Featured'), findsNothing);
|
||||
expect(find.text('New'), findsNothing);
|
||||
expect(find.text('Categories'), findsNothing);
|
||||
expect(find.text('Charts'), findsNothing);
|
||||
expect(find.text('古装'), findsOneWidget);
|
||||
expect(find.text('社群'), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-mini-player')), findsNothing);
|
||||
expect(find.byType(FloatingActionButton), findsNothing);
|
||||
expect(find.byKey(const Key('home-tabs-bar')), findsOneWidget);
|
||||
|
||||
final selectedUnderline = tester.widget<Container>(
|
||||
find.byKey(const Key('recommend-tab-recommend-underline')),
|
||||
);
|
||||
expect(
|
||||
(selectedUnderline.decoration! as BoxDecoration).color,
|
||||
AppColors.brandRed,
|
||||
);
|
||||
final idleUnderline = tester.widget<Container>(
|
||||
find.byKey(const Key('recommend-tab-playlist-underline')),
|
||||
);
|
||||
expect(
|
||||
(idleUnderline.decoration! as BoxDecoration).color,
|
||||
AppColors.transparent,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('should_hide_unmatched_content_sections', (tester) async {
|
||||
testWidgets('should_render_only_categories_returned_by_api', (tester) async {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(
|
||||
tester,
|
||||
@@ -75,9 +81,13 @@ void main() {
|
||||
categories: const [ContentCategory(id: 'romance', name: 'Romance')],
|
||||
);
|
||||
|
||||
expect(find.byKey(const Key('home-section-category-古装')), findsNothing);
|
||||
expect(find.byKey(const Key('home-section-category-社群')), findsNothing);
|
||||
expect(find.byKey(const Key('home-tag-uplifting')), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('recommend-channel-nav')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-romance')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-costume')), findsNothing);
|
||||
expect(find.byKey(const Key('recommend-tab-community')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('should_switch_home_sections_without_pushing_pages', (
|
||||
@@ -86,24 +96,22 @@ void main() {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(tester, repository);
|
||||
|
||||
String firstDramaId() {
|
||||
return tester
|
||||
.widget<HomeFeedCard>(find.byType(HomeFeedCard).first)
|
||||
.drama
|
||||
.id;
|
||||
}
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-section-hits')), findsNothing);
|
||||
|
||||
expect(find.byKey(const Key('home-grid')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-section-featured')), findsNothing);
|
||||
expect(firstDramaId(), 'page1-0');
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-section-category-古装')));
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-playlist')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(firstDramaId(), 'page1-0');
|
||||
_drainLayoutExceptions(tester);
|
||||
expect(find.byKey(const Key('recommend-section-hits')), findsOneWidget);
|
||||
expect(
|
||||
Navigator.of(
|
||||
tester.element(find.byKey(const Key('recommend-page'))),
|
||||
).canPop(),
|
||||
isFalse,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-section-category-社群')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(firstDramaId(), 'page1-0');
|
||||
await _openAllDramasTab(tester);
|
||||
expect(find.byKey(const Key('all-dramas-grid')), findsOneWidget);
|
||||
expect(find.byKey(const Key('filter-page')), findsNothing);
|
||||
});
|
||||
|
||||
@@ -112,30 +120,30 @@ void main() {
|
||||
) async {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(tester, repository);
|
||||
await _openAllDramasTab(tester);
|
||||
|
||||
await tester.drag(
|
||||
find.byKey(const Key('home-grid-scroll')),
|
||||
find.byKey(const Key('all-dramas-scroll')),
|
||||
const Offset(0, -320),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final scrollable = find
|
||||
.descendant(
|
||||
of: find.byKey(const Key('home-grid-scroll')),
|
||||
of: find.byKey(const Key('all-dramas-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-category-社群')));
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-playlist')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('home-section-category-古装')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
_drainLayoutExceptions(tester);
|
||||
|
||||
await _openAllDramasTab(tester);
|
||||
final afterScrollable = find
|
||||
.descendant(
|
||||
of: find.byKey(const Key('home-grid-scroll')),
|
||||
of: find.byKey(const Key('all-dramas-scroll')),
|
||||
matching: find.byType(Scrollable),
|
||||
)
|
||||
.first;
|
||||
@@ -145,30 +153,42 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('should_swipe_between_primary_sections', (tester) async {
|
||||
testWidgets('should_swipe_between_inner_sections', (tester) async {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(tester, repository);
|
||||
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
await tester.drag(
|
||||
find.byKey(const Key('home-primary-page-view')),
|
||||
const Offset(-320, 0),
|
||||
final pages = find.byKey(const Key('recommend-tab-page-view'));
|
||||
final topNavBefore = tester.getRect(
|
||||
find.byKey(const Key('recommend-top-nav')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
final selected = tester.widget<AnimatedDefaultTextStyle>(
|
||||
find.byKey(const Key('home-primary-label-community')),
|
||||
);
|
||||
expect(selected.style.fontSize, AppDimens.homePrimaryTabSelectedFont);
|
||||
expect(selected.style.fontWeight, FontWeight.w700);
|
||||
|
||||
await tester.drag(
|
||||
find.byKey(const Key('home-primary-page-view')),
|
||||
const Offset(320, 0),
|
||||
);
|
||||
await tester.drag(pages, const Offset(-320, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
_drainLayoutExceptions(tester);
|
||||
expect(find.byKey(const Key('recommend-section-hits')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsNothing);
|
||||
final selected = tester.widget<Text>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('recommend-tab-playlist')),
|
||||
matching: find.text('Playlists'),
|
||||
),
|
||||
);
|
||||
expect(selected.style?.fontWeight, FontWeight.w700);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('recommend-top-nav'))),
|
||||
topNavBefore,
|
||||
);
|
||||
|
||||
await tester.drag(pages, const Offset(-320, 0));
|
||||
await tester.pumpAndSettle();
|
||||
_drainLayoutExceptions(tester);
|
||||
expect(find.byKey(const Key('all-dramas-grid')), findsOneWidget);
|
||||
|
||||
await tester.drag(pages, const Offset(640, 0));
|
||||
await tester.pumpAndSettle();
|
||||
_drainLayoutExceptions(tester);
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-recommend')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_load_next_page_without_expanding_page_size', (
|
||||
@@ -176,45 +196,41 @@ void main() {
|
||||
) async {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(tester, repository);
|
||||
await _openAllDramasTab(tester);
|
||||
|
||||
expect(find.byKey(const Key('home-feed-card-page1-0')), findsOneWidget);
|
||||
await tester.drag(
|
||||
find.byKey(const Key('home-grid-scroll')),
|
||||
const Offset(0, -1200),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
for (var attempt = 0; attempt < 3; attempt++) {
|
||||
await tester.drag(
|
||||
find.byKey(const Key('all-dramas-scroll')),
|
||||
const Offset(0, -800),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
_drainLayoutExceptions(tester);
|
||||
}
|
||||
expect(repository.cursors, contains('page1'));
|
||||
expect(repository.requestedSizes.every((size) => size <= 20), isTrue);
|
||||
|
||||
expect(find.byKey(const Key('home-grid-refresh')), findsOneWidget);
|
||||
final gridScrollable = find
|
||||
.descendant(
|
||||
of: find.byKey(const Key('home-grid-scroll')),
|
||||
of: find.byKey(const Key('all-dramas-scroll')),
|
||||
matching: find.byType(Scrollable),
|
||||
);
|
||||
expect(gridScrollable, findsOneWidget);
|
||||
final secondPageCard = find.byKey(
|
||||
const Key('home-feed-card-page2-0'),
|
||||
);
|
||||
final feed = tester
|
||||
.widget<HomeFeedGrid>(find.byType(HomeFeedGrid))
|
||||
.feedController;
|
||||
expect(
|
||||
feed.dramas.map((drama) => drama.id),
|
||||
contains('page2-0'),
|
||||
);
|
||||
)
|
||||
.first;
|
||||
final secondPageCard = find.byKey(const Key('home-feed-card-page2-0'));
|
||||
final position = tester.state<ScrollableState>(gridScrollable).position;
|
||||
await tester.pump();
|
||||
position.jumpTo(position.maxScrollExtent);
|
||||
await tester.pump();
|
||||
position.jumpTo(position.maxScrollExtent);
|
||||
await tester.pump();
|
||||
_drainLayoutExceptions(tester);
|
||||
expect(secondPageCard, findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_open_player_when_grid_card_is_tapped', (tester) async {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(tester, repository);
|
||||
await _openAllDramasTab(tester);
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-feed-card-page1-0')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -224,6 +240,20 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
/// 打开首页内层「全部短剧」页;顺带消费测试字体(Ahem)造成的卡片溢出。
|
||||
Future<void> _openAllDramasTab(WidgetTester tester) async {
|
||||
await tester.ensureVisible(find.byKey(const Key('recommend-tab-all')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-all')));
|
||||
await tester.pumpAndSettle();
|
||||
_drainLayoutExceptions(tester);
|
||||
}
|
||||
|
||||
/// 剧单/网格卡片高度按真机字体设计,测试字体行高更大时会溢出几个像素。
|
||||
void _drainLayoutExceptions(WidgetTester tester) {
|
||||
while (tester.takeException() != null) {}
|
||||
}
|
||||
|
||||
Future<void> _pumpApp(
|
||||
WidgetTester tester,
|
||||
_PagedCatalogRepository repository, {
|
||||
|
||||
Reference in new issue
Block a user