feat(app): 客户端展示多语言并支持筛选分页
This commit is contained in:
1 parent
8481611372
commit
8b50b5bd06
68 files changed
+2742
-1120
No files matched your search
@@ -63,7 +63,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('should_use_the_configured_local_address_for_device_default', () {
|
||||
expect(AppConfig.devHostBaseUrl, 'http://10.43.47.1:8081');
|
||||
expect(AppConfig.devHostBaseUrl, 'http://192.168.31.243:8081');
|
||||
});
|
||||
|
||||
test('should_skip_probe_when_compiled_override_is_set', () async {
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/models/content_category.dart';
|
||||
import 'package:fruitshorts/core/data/models/drama.dart';
|
||||
import 'package:fruitshorts/core/data/models/page_result.dart';
|
||||
import 'package:fruitshorts/core/data/services/all_dramas_controller.dart';
|
||||
|
||||
void main() {
|
||||
test('should_replace_first_page_when_refresh_succeeds', () async {
|
||||
final remote = _ScriptedRemote(
|
||||
pages: [
|
||||
PageResult(total: 2, list: [_drama('a'), _drama('b')]),
|
||||
],
|
||||
);
|
||||
final controller = AllDramasController(api: remote);
|
||||
|
||||
await controller.refresh();
|
||||
|
||||
expect(controller.dramas.map((item) => item.id), ['a', 'b']);
|
||||
expect(controller.hasMore, isFalse);
|
||||
expect(controller.error, isNull);
|
||||
expect(remote.pagesRequested, [1]);
|
||||
});
|
||||
|
||||
test('should_append_next_page_when_more_dramas_remain', () async {
|
||||
final remote = _ScriptedRemote(
|
||||
pages: [
|
||||
PageResult(total: 3, list: [_drama('a'), _drama('b')]),
|
||||
PageResult(total: 3, list: [_drama('c')]),
|
||||
],
|
||||
);
|
||||
final controller = AllDramasController(api: remote);
|
||||
await controller.refresh();
|
||||
|
||||
await controller.loadMore();
|
||||
|
||||
expect(controller.dramas.map((item) => item.id), ['a', 'b', 'c']);
|
||||
expect(controller.hasMore, isFalse);
|
||||
expect(remote.pagesRequested, [1, 2]);
|
||||
});
|
||||
|
||||
test('should_keep_loaded_dramas_when_next_page_fails', () async {
|
||||
final remote = _ScriptedRemote(
|
||||
pages: [PageResult(total: 3, list: [_drama('a')])],
|
||||
failOnPage: 2,
|
||||
);
|
||||
final controller = AllDramasController(api: remote);
|
||||
await controller.refresh();
|
||||
|
||||
await controller.loadMore();
|
||||
|
||||
expect(controller.dramas.map((item) => item.id), ['a']);
|
||||
expect(controller.error, isNotNull);
|
||||
});
|
||||
|
||||
test('should_clear_selected_type_when_all_is_chosen', () {
|
||||
final controller = AllDramasController.preview(
|
||||
categories: const [ContentCategory(id: '2', name: '甜宠')],
|
||||
);
|
||||
|
||||
controller.toggleCategory('2');
|
||||
controller.toggleCategory('');
|
||||
|
||||
expect(controller.selectedCategories, isEmpty);
|
||||
});
|
||||
|
||||
test('should_send_selected_ids_when_loading_a_page', () async {
|
||||
final remote = _ScriptedRemote(
|
||||
pages: [PageResult(total: 0, list: const [])],
|
||||
);
|
||||
final controller = AllDramasController(api: remote);
|
||||
controller.toggleCategory('2');
|
||||
controller.toggleClassification('3');
|
||||
controller.toggleTag('4');
|
||||
|
||||
await controller.refresh();
|
||||
|
||||
expect(remote.lastCategoryIds, ['2']);
|
||||
expect(remote.lastClassificationIds, ['3']);
|
||||
expect(remote.lastTagIds, ['4']);
|
||||
});
|
||||
}
|
||||
|
||||
Drama _drama(String id) {
|
||||
return Drama(id: id, title: id, synopsis: '', posterUrl: '');
|
||||
}
|
||||
|
||||
class _ScriptedRemote implements AllDramasRemote {
|
||||
_ScriptedRemote({required this.pages, this.failOnPage});
|
||||
|
||||
final List<PageResult<Drama>> pages;
|
||||
final int? failOnPage;
|
||||
final List<int> pagesRequested = [];
|
||||
List<String> lastCategoryIds = const [];
|
||||
List<String> lastClassificationIds = const [];
|
||||
List<String> lastTagIds = const [];
|
||||
|
||||
@override
|
||||
Future<List<ContentCategory>> classifications() async => const [
|
||||
ContentCategory(id: '3', name: '精选'),
|
||||
];
|
||||
|
||||
@override
|
||||
Future<List<ContentCategory>> categories() async => const [
|
||||
ContentCategory(id: '2', name: '甜宠'),
|
||||
];
|
||||
|
||||
@override
|
||||
Future<List<ContentCategory>> tags() async => const [
|
||||
ContentCategory(id: '4', name: '热剧'),
|
||||
];
|
||||
|
||||
@override
|
||||
Future<PageResult<Drama>> dramas({
|
||||
required List<String> categoryIds,
|
||||
required List<String> classificationIds,
|
||||
required List<String> tagIds,
|
||||
required int pageIndex,
|
||||
}) async {
|
||||
lastCategoryIds = categoryIds;
|
||||
lastClassificationIds = classificationIds;
|
||||
lastTagIds = tagIds;
|
||||
pagesRequested.add(pageIndex);
|
||||
if (pageIndex == failOnPage) throw StateError('page failed');
|
||||
return pages[pageIndex - 1];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/models/page_result.dart';
|
||||
import 'package:fruitshorts/core/data/models/playlist_detail.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/playlist_repository.dart';
|
||||
import 'package:fruitshorts/core/data/services/playlist_controller.dart';
|
||||
|
||||
void main() {
|
||||
test('should_append_the_next_page_when_more_playlists_remain', () async {
|
||||
final repository = _PagedPlaylists(total: 12);
|
||||
final controller = PlaylistController(repository);
|
||||
|
||||
await controller.load();
|
||||
expect(controller.items, hasLength(PlaylistController.pageSize));
|
||||
expect(controller.hasMore, isTrue);
|
||||
|
||||
await controller.loadMore();
|
||||
expect(controller.items, hasLength(12));
|
||||
expect(controller.items.last.id, '11');
|
||||
expect(controller.hasMore, isFalse);
|
||||
|
||||
controller.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
class _PagedPlaylists implements PlaylistRepository {
|
||||
_PagedPlaylists({required this.total});
|
||||
|
||||
final int total;
|
||||
|
||||
@override
|
||||
Future<PageResult<PlaylistDetail>> fetchPlaylists({
|
||||
int pageIndex = 1,
|
||||
int pageSize = 10,
|
||||
}) async {
|
||||
final start = (pageIndex - 1) * pageSize;
|
||||
if (start >= total) {
|
||||
return PageResult(total: total);
|
||||
}
|
||||
final end = start + pageSize > total ? total : start + pageSize;
|
||||
return PageResult(
|
||||
total: total,
|
||||
list: [
|
||||
for (var index = start; index < end; index++)
|
||||
PlaylistDetail(
|
||||
id: '$index',
|
||||
name: '剧单$index',
|
||||
description: '',
|
||||
dramaCount: 0,
|
||||
dramas: const [],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<PlaylistDetail> fetchPlaylist(
|
||||
String id, {
|
||||
int pageIndex = 1,
|
||||
int pageSize = 20,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/models/playlist_detail.dart';
|
||||
|
||||
void main() {
|
||||
test('should_parse_playlist_cards_when_detail_json_arrives', () {
|
||||
final playlist = PlaylistDetail.fromJson({
|
||||
'id': '2112807182243336196',
|
||||
'name': '本周必看',
|
||||
'locales': {'zh': '本周必看', 'en': 'Weekly Hits', 'id': 'Hits Mingguan'},
|
||||
'description': '编辑精选',
|
||||
'descriptionLocales': {
|
||||
'zh': '编辑精选',
|
||||
'en': 'Editor picks',
|
||||
'id': 'Pilihan editor',
|
||||
},
|
||||
'dramaCount': 1,
|
||||
'list': [
|
||||
{
|
||||
'id': '5',
|
||||
'title': '命运的相遇',
|
||||
'cover': '/files/cover.jpg',
|
||||
'synopsis': '一次意外',
|
||||
'totalEpisodes': 12,
|
||||
'viewCount': '20',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(playlist.id, '2112807182243336196');
|
||||
expect(playlist.name, '本周必看');
|
||||
expect(playlist.description, '编辑精选');
|
||||
expect(playlist.localizedName('en'), 'Weekly Hits');
|
||||
expect(playlist.localizedDescription('id'), 'Pilihan editor');
|
||||
expect(playlist.localizedName('zh'), '本周必看');
|
||||
expect(playlist.dramaCount, 1);
|
||||
expect(playlist.dramas.single.title, '命运的相遇');
|
||||
expect(playlist.dramas.single.posterUrl, '/files/cover.jpg');
|
||||
expect(playlist.dramas.single.totalEpisodes, 12);
|
||||
});
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart
|
||||
import 'package:fruitshorts/core/theme/app_colors.dart';
|
||||
import 'package:fruitshorts/core/widgets/app_pull_to_refresh.dart';
|
||||
import 'package:fruitshorts/pages/discover/discover_view.dart';
|
||||
import 'package:fruitshorts/pages/discover/widgets/discover_category_tab.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';
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ void main() {
|
||||
title: 'A very long home grid drama title that must wrap',
|
||||
dramaType: 'ANIME',
|
||||
viewCount: 444500,
|
||||
tag: '漫剧',
|
||||
tagLocales: const {'zh': '漫剧', 'en': 'Anime', 'id': 'Anime'},
|
||||
),
|
||||
onTap: () => taps++,
|
||||
);
|
||||
@@ -52,7 +54,7 @@ void main() {
|
||||
BorderRadius.circular(AppDimens.cardCoverRadius),
|
||||
);
|
||||
final badge = find.byKey(
|
||||
const Key('drama-cover-badge-ribbon-anime-card-anime'),
|
||||
const Key('drama-cover-badge-ribbon-anime-card-tag'),
|
||||
);
|
||||
expect(badge, findsOneWidget);
|
||||
expect(
|
||||
@@ -120,10 +122,7 @@ void main() {
|
||||
expect(taps, 1);
|
||||
});
|
||||
|
||||
testWidgets('should_choose_anime_new_and_hot_badges_from_real_data', (
|
||||
tester,
|
||||
) async {
|
||||
final now = DateTime(2026, 10, 22, 12);
|
||||
testWidgets('should_show_cover_badge_from_tag_locale', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.dark(),
|
||||
@@ -134,18 +133,18 @@ void main() {
|
||||
body: Row(
|
||||
children: [
|
||||
for (final drama in [
|
||||
_drama(id: 'anime', title: 'Anime', dramaType: 'ANIME'),
|
||||
_drama(
|
||||
id: 'new',
|
||||
title: 'New',
|
||||
createdAt: now.subtract(const Duration(days: 2)),
|
||||
id: 'tagged',
|
||||
title: 'Tagged',
|
||||
tag: '新剧',
|
||||
tagLocales: const {'zh': '新剧', 'en': 'New', 'id': 'Baru'},
|
||||
),
|
||||
_drama(id: 'hot', title: 'Hot', isHot: true),
|
||||
_drama(id: 'plain', title: 'Plain'),
|
||||
])
|
||||
SizedBox(
|
||||
width: 130,
|
||||
height: 240,
|
||||
child: HomeFeedCard(drama: drama, onTap: () {}, now: now),
|
||||
child: HomeFeedCard(drama: drama, onTap: () {}),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -154,18 +153,10 @@ void main() {
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
find.byKey(const Key('drama-cover-badge-ribbon-anime-anime')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.byKey(const Key('drama-cover-badge-ribbon-new-newRelease')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.byKey(const Key('drama-cover-badge-ribbon-hot-hot')),
|
||||
findsOneWidget,
|
||||
);
|
||||
final badge = find.byKey(const Key('drama-cover-badge-ribbon-tagged-tag'));
|
||||
expect(badge, findsOneWidget);
|
||||
expect(find.text('New'), findsOneWidget);
|
||||
expect(find.byKey(const Key('drama-cover-badge-ribbon-plain-tag')), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -176,6 +167,8 @@ Drama _drama({
|
||||
int viewCount = 0,
|
||||
bool isHot = false,
|
||||
DateTime? createdAt,
|
||||
String tag = '',
|
||||
Map<String, String> tagLocales = const {},
|
||||
}) {
|
||||
return Drama(
|
||||
id: id,
|
||||
@@ -188,6 +181,8 @@ Drama _drama({
|
||||
isHot: isHot,
|
||||
dramaType: dramaType,
|
||||
createdAt: createdAt,
|
||||
tag: tag,
|
||||
tagLocales: tagLocales,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -210,7 +205,6 @@ Future<void> _pumpCard(
|
||||
child: HomeFeedCard(
|
||||
drama: drama,
|
||||
onTap: onTap,
|
||||
now: DateTime(2026, 10, 22, 12),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -45,24 +45,24 @@ void main() {
|
||||
await _pumpApp(tester, repository);
|
||||
|
||||
final sectionKeys = [
|
||||
const Key('home-section-featured'),
|
||||
const Key('home-section-new'),
|
||||
const Key('home-section-categories'),
|
||||
const Key('home-section-ranking'),
|
||||
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 sectionCenters = sectionKeys
|
||||
.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(find.text('Featured'), findsOneWidget);
|
||||
expect(find.text('New'), findsOneWidget);
|
||||
expect(find.text('Categories'), findsOneWidget);
|
||||
expect(find.text('Charts'), findsOneWidget);
|
||||
expect(find.text('Costume'), findsOneWidget);
|
||||
expect(find.text('Community'), findsOneWidget);
|
||||
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);
|
||||
});
|
||||
@@ -94,31 +94,9 @@ void main() {
|
||||
}
|
||||
|
||||
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-new')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('new-releases-page')), findsNothing);
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
expect(firstDramaId(), 'page1-9');
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-section-ranking')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('ranking-page')), findsOneWidget);
|
||||
expect(find.byKey(const Key('ranking-hero')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-grid-cards')), findsNothing);
|
||||
final home = tester.widget<DecoratedBox>(find.byKey(const Key('home-grid')));
|
||||
expect(
|
||||
(home.decoration as BoxDecoration).gradient,
|
||||
AppTheme.pageGradient,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-section-categories')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('filter-page')), findsNothing);
|
||||
expect(find.byKey(const Key('home-secondary-tags')), 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');
|
||||
@@ -149,9 +127,9 @@ void main() {
|
||||
final before = tester.state<ScrollableState>(scrollable).position.pixels;
|
||||
expect(before, greaterThan(0));
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-section-new')));
|
||||
await tester.tap(find.byKey(const Key('home-section-category-社群')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('home-section-featured')));
|
||||
await tester.tap(find.byKey(const Key('home-section-category-古装')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
|
||||
@@ -180,7 +158,7 @@ void main() {
|
||||
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
final selected = tester.widget<AnimatedDefaultTextStyle>(
|
||||
find.byKey(const Key('home-primary-label-newReleases')),
|
||||
find.byKey(const Key('home-primary-label-community')),
|
||||
);
|
||||
expect(selected.style.fontSize, AppDimens.homePrimaryTabSelectedFont);
|
||||
expect(selected.style.fontWeight, FontWeight.w700);
|
||||
|
||||
@@ -87,10 +87,7 @@ void main() {
|
||||
expect(delegate.crossAxisCount, 3);
|
||||
expect(delegate.crossAxisSpacing, AppDimens.homeGridGap);
|
||||
expect(delegate.mainAxisSpacing, AppDimens.homeGridRowGap);
|
||||
expect(find.byKey(const Key('home-section-featured')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-section-new')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-section-categories')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-section-ranking')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-section-featured')), findsNothing);
|
||||
expect(find.byKey(const Key('home-section-category-古装')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-section-category-社群')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
@@ -111,10 +108,10 @@ void main() {
|
||||
expect(placeholder.style?.fontSize, AppDimens.searchPlaceholderFont);
|
||||
expect(placeholder.style?.color, AppColors.textSecondary);
|
||||
final selectedPrimary = tester.widget<AnimatedDefaultTextStyle>(
|
||||
find.byKey(const Key('home-primary-label-featured')),
|
||||
find.byKey(const Key('home-primary-label-costume')),
|
||||
);
|
||||
final unselectedPrimary = tester.widget<AnimatedDefaultTextStyle>(
|
||||
find.byKey(const Key('home-primary-label-newReleases')),
|
||||
find.byKey(const Key('home-primary-label-community')),
|
||||
);
|
||||
expect(
|
||||
selectedPrimary.style.fontSize,
|
||||
@@ -128,19 +125,19 @@ void main() {
|
||||
expect(unselectedPrimary.style.color, AppColors.textTabInactive);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('home-section-featured')),
|
||||
of: find.byKey(const Key('home-section-category-古装')),
|
||||
matching: find.byType(Container),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
final primaryStart = tester.getTopLeft(find.text('Featured'));
|
||||
final primaryStart = tester.getTopLeft(find.text('古装'));
|
||||
final pageStart = tester.getTopLeft(searchBox);
|
||||
expect(primaryStart.dx, pageStart.dx);
|
||||
final primaryGap =
|
||||
tester.getTopLeft(find.text('New')).dx -
|
||||
tester.getBottomRight(find.text('Featured')).dx;
|
||||
tester.getTopLeft(find.text('社群')).dx -
|
||||
tester.getBottomRight(find.text('古装')).dx;
|
||||
expect(primaryGap, closeTo(AppDimens.homePrimaryCategoryGap, 0.1));
|
||||
expect(find.byType(PageView), findsNothing);
|
||||
expect(find.byKey(const Key('home-primary-page-view')), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-all')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('all-dramas-grid')), findsOneWidget);
|
||||
for (var row = 0; row < 4; row++) {
|
||||
for (var row = 0; row < 3; row++) {
|
||||
expect(find.byKey(Key('all-filter-row-$row')), findsOneWidget);
|
||||
}
|
||||
_expectNoFloatingOverlays();
|
||||
|
||||
@@ -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),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user