后端接口从 6 个扩到 13 个,全部走真数据:
- 新增 api:playback_api(/app/episodes/{id}/play)、watch_api(/app/watch/*)、
library_api(/app/favorites*);票据从 CatalogApi 搬到 PlaybackApi
- 新增 repository:PlaybackRepository(含票据 TTL 缓存,默认 10 分钟,时钟可注入)、
FavoriteRepository、WatchHistoryRepository 换成服务端模型(每剧一条续看记录,删掉 demoProfileId)
- PlayerLogic:起播前取票(拿不到给三态 UI,失败可重试);accessType 驱动锁定文案,
不在前端猜;签名地址原样交给播放器(只补 host,不动 path/query);
进度上报节流 5s → 10s,切集/退出/切后台各补一次,播完带 finished
- 续看定位:服务端记录里的那一集才 seek(其它集从头播),续看位置进详情/播放页时读一次
- FavoriteController:收藏以服务端为准,乐观更新 + 失败回滚;退出登录清空
- UI 三态:详情页(加载/失败可重试/空剧集 + 续看进度条 + 收藏按钮)、
播放页(票据加载中/失败可重试/后端判定不可播)、我的页(续看失败可重试、收藏三态、最近观看)
- l10n 新增 8 个键(en/zh/id 三份):网络/进度/收藏失败、锁定提示、续看文案等
测试:flutter test 188 全过(存量 27 个测试文件未跑红);新增票据过期重取、进度节流、
续看定位、收藏回滚、签名 query 原样保留、真实后端端到端联调(live_watch_flow)
97 lines
2.7 KiB
Dart
97 lines
2.7 KiB
Dart
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/core/data/repositories/catalog_repository.dart';
|
|
import 'package:fruitshorts/core/data/services/catalog_controller.dart';
|
|
|
|
void main() {
|
|
test('should_distinguish_empty_catalog_from_load_failure_when_retry_succeeds', () async {
|
|
final repository = ScriptedCatalogRepository();
|
|
final controller = CatalogController(repository);
|
|
|
|
await controller.load();
|
|
expect(controller.dramas, isEmpty);
|
|
expect(controller.error, isNull);
|
|
|
|
repository.fail = true;
|
|
await controller.load();
|
|
expect(controller.error, isNotNull);
|
|
|
|
repository.fail = false;
|
|
repository.feed = HomeFeed(
|
|
sections: [
|
|
FeedSection(code: 'hot', title: '热门推荐', dramas: [_card('1')]),
|
|
],
|
|
);
|
|
await controller.load();
|
|
expect(controller.error, isNull);
|
|
expect(controller.dramas, hasLength(1));
|
|
expect(controller.sections.single.title, '热门推荐');
|
|
});
|
|
|
|
test('should_request_drama_detail_once_when_it_is_loaded_on_demand', () async {
|
|
final repository = ScriptedCatalogRepository();
|
|
final controller = CatalogController(repository);
|
|
repository.feed = HomeFeed(
|
|
sections: [
|
|
FeedSection(code: 'hot', title: '热门推荐', dramas: [_card('1')]),
|
|
],
|
|
);
|
|
await controller.load();
|
|
|
|
final card = controller.dramas.single;
|
|
expect(card.episodes, isEmpty);
|
|
|
|
final detail = await controller.requireDetail(card);
|
|
expect(detail.episodes, hasLength(2));
|
|
expect(repository.detailCalls, 1);
|
|
|
|
// 第二次已经是详情,直接复用,不再请求
|
|
await controller.requireDetail(detail);
|
|
expect(repository.detailCalls, 1);
|
|
expect(controller.dramas.single.episodes, hasLength(2));
|
|
});
|
|
|
|
}
|
|
|
|
Drama _card(String id) => Drama(
|
|
id: id,
|
|
title: 'Drama $id',
|
|
synopsis: '简介 $id',
|
|
posterUrl: '/files/$id.jpg',
|
|
);
|
|
|
|
Drama _detail(String id) => Drama(
|
|
id: id,
|
|
title: 'Drama $id',
|
|
synopsis: '简介 $id',
|
|
posterUrl: '/files/$id.jpg',
|
|
detailLoaded: true,
|
|
episodes: const [
|
|
Episode(id: '1', number: 1, title: '第一集', isFree: true),
|
|
Episode(id: '2', number: 2, title: '第二集', isFree: false),
|
|
],
|
|
);
|
|
|
|
class ScriptedCatalogRepository implements CatalogRepository {
|
|
bool fail = false;
|
|
HomeFeed feed = const HomeFeed();
|
|
int detailCalls = 0;
|
|
|
|
@override
|
|
Future<HomeFeed> fetchHomeFeed() async {
|
|
if (fail) throw StateError('offline');
|
|
return feed;
|
|
}
|
|
|
|
@override
|
|
Future<HomeFeed> fetchDiscoverFeed() async => feed;
|
|
|
|
@override
|
|
Future<Drama> fetchDrama(String dramaId) async {
|
|
detailCalls++;
|
|
return _detail(dramaId);
|
|
}
|
|
|
|
}
|