feat(app): 增加首页榜单 tab
This commit is contained in:
1 parent
136ee74618
commit
2b95c79931
13 files changed
+859
-6
No files matched your search
@@ -0,0 +1,74 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/models/drama.dart';
|
||||
import 'package:fruitshorts/core/data/models/home_feed.dart';
|
||||
import 'package:fruitshorts/pages/ranking/ranking_logic.dart';
|
||||
|
||||
void main() {
|
||||
test('should_use_backend_hot_order_when_hot_board_is_selected', () {
|
||||
final logic = RankingLogic(
|
||||
sections: [
|
||||
FeedSection(
|
||||
code: 'hot',
|
||||
title: 'Hot',
|
||||
dramas: [_drama('first'), _drama('second')],
|
||||
),
|
||||
FeedSection(code: 'new', title: 'New', dramas: [_drama('fresh')]),
|
||||
],
|
||||
fallback: [_drama('fallback')],
|
||||
);
|
||||
|
||||
expect(logic.board, RankingBoard.hot);
|
||||
expect(logic.entries.map((entry) => entry.drama.id), ['first', 'second']);
|
||||
expect(logic.entries.map((entry) => entry.rank), [1, 2]);
|
||||
logic.dispose();
|
||||
});
|
||||
|
||||
test('should_switch_to_new_releases_when_new_board_is_selected', () {
|
||||
final logic = RankingLogic(
|
||||
sections: [
|
||||
FeedSection(code: 'hot', title: 'Hot', dramas: [_drama('hot')]),
|
||||
FeedSection(code: 'new', title: 'New', dramas: [_drama('fresh')]),
|
||||
],
|
||||
fallback: const [],
|
||||
);
|
||||
|
||||
logic.select(RankingBoard.newReleases);
|
||||
|
||||
expect(logic.board, RankingBoard.newReleases);
|
||||
expect(logic.entries.single.drama.id, 'fresh');
|
||||
logic.dispose();
|
||||
});
|
||||
|
||||
test(
|
||||
'should_deduplicate_and_fall_back_when_requested_section_is_missing',
|
||||
() {
|
||||
final logic = RankingLogic(
|
||||
sections: [
|
||||
FeedSection(
|
||||
code: 'hot',
|
||||
title: 'Hot',
|
||||
dramas: [_drama('a'), _drama('a')],
|
||||
),
|
||||
],
|
||||
fallback: [_drama('b'), _drama('a')],
|
||||
);
|
||||
|
||||
expect(logic.entries.map((entry) => entry.drama.id), ['a']);
|
||||
|
||||
logic.select(RankingBoard.newReleases);
|
||||
|
||||
expect(logic.entries.map((entry) => entry.drama.id), ['b', 'a']);
|
||||
expect(logic.entries.last.rank, 2);
|
||||
logic.dispose();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Drama _drama(String id) => Drama(
|
||||
id: id,
|
||||
title: 'Drama $id',
|
||||
synopsis: 'Synopsis $id',
|
||||
posterUrl: '/files/$id.jpg',
|
||||
);
|
||||
@@ -0,0 +1,88 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/app.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/drama_detail/drama_detail_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';
|
||||
|
||||
import '../support/fake_catalog.dart';
|
||||
import '../support/fake_category.dart';
|
||||
import '../support/fake_haptics.dart';
|
||||
import '../support/fake_interaction_repositories.dart';
|
||||
import '../support/widget_player.dart';
|
||||
|
||||
void main() {
|
||||
setUp(() {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.withData({});
|
||||
});
|
||||
|
||||
testWidgets('should_render_real_section_order_when_ranking_tab_is_opened', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester);
|
||||
|
||||
await tester.tap(find.byKey(const Key('tab-ranking')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('ranking-page')), findsOneWidget);
|
||||
expect(find.byKey(const Key('ranking-tab-hot')), findsOneWidget);
|
||||
expect(find.byKey(const Key('ranking-tab-new')), findsOneWidget);
|
||||
expect(
|
||||
find.byKey(const Key('ranking-entry-the-signal-demo')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.byKey(const Key('ranking-entry-city-lights-demo')),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(const Key('ranking-tab-new')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.byKey(const Key('ranking-entry-the-signal-demo')),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('should_open_the_selected_drama_when_ranking_entry_is_tapped', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester);
|
||||
await tester.tap(find.byKey(const Key('tab-ranking')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const Key('ranking-entry-city-lights-demo')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(DramaDetailPage), findsOneWidget);
|
||||
expect(find.text('City Lights & Velvet Nights'), findsWidgets);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _pumpApp(WidgetTester tester) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final catalog = FakeCatalogRepository();
|
||||
await tester.pumpWidget(
|
||||
LumaDramaApp(
|
||||
playerFactory: createWidgetPlayer,
|
||||
catalogRepository: catalog,
|
||||
categoryRepository: FakeCategoryRepository(catalog: catalog),
|
||||
watchHistoryRepository: InMemoryWatchHistoryRepository(),
|
||||
favoriteRepository: InMemoryFavoriteRepository(cards: catalog.dramas),
|
||||
playbackRepository: FakePlaybackRepository(),
|
||||
commentRepository: FakeCommentRepository(),
|
||||
interactionRepository: FakeInteractionRepository(),
|
||||
haptics: FakeHaptics(),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
Reference in new issue
Block a user