fix(home): 首切频道预取并保留播放画面

This commit is contained in:
Zhou Weidong committed 2026-10-21 17:53:58 +08:00
1 parent dfa79bed88
commit 677e49fa6e
5 files changed
+242 -27

No files matched your search

@@ -27,6 +27,67 @@ void main() {
},
);
test(
'should_use_prefetched_channel_without_another_request_on_first_select',
() async {
final repository = _ScriptedFeedRepository()
..enqueue(() async => FeedPage(dramas: [_drama('anime')]))
..enqueue(() async => FeedPage(dramas: [_drama('live')]));
final controller = HomeFeedController(repository);
controller.seedRecommend([_drama('seed')]);
await controller.prefetchChannels();
await controller.selectChannel(HomeFeedChannel.anime);
expect(controller.dramas.single.id, 'anime');
expect(repository.calls.map((call) => call.types), [
['ANIME'],
['LIVE'],
]);
controller.dispose();
},
);
test('should_keep_recommend_when_prefetch_fails', () async {
final repository = _ScriptedFeedRepository()
..enqueue(() async => throw StateError('offline'))
..enqueue(() async => FeedPage(dramas: [_drama('live')]));
final controller = HomeFeedController(repository);
controller.seedRecommend([_drama('seed')]);
await controller.prefetchChannels();
expect(controller.channel, HomeFeedChannel.recommend);
expect(controller.dramas.single.id, 'seed');
expect(controller.lastError, isNull);
controller.dispose();
});
test(
'should_wait_prefetch_without_duplicate_request_when_channel_is_selected',
() async {
final anime = Completer<FeedPage>();
final repository = _ScriptedFeedRepository()
..enqueue(() => anime.future)
..enqueue(() async => FeedPage(dramas: [_drama('live')]));
final controller = HomeFeedController(repository);
controller.seedRecommend([_drama('seed')]);
final prefetch = controller.prefetchChannels();
final select = controller.selectChannel(HomeFeedChannel.anime);
anime.complete(FeedPage(dramas: [_drama('anime')]));
await prefetch;
await select;
expect(
repository.calls.where((call) => call.types.contains('ANIME')),
hasLength(1),
);
expect(controller.dramas.single.id, 'anime');
controller.dispose();
},
);
test('should_request_anime_live_and_recommend_with_expected_types', () async {
final repository = _ScriptedFeedRepository()
..enqueue(() async => FeedPage(dramas: [_drama('anime')]))