后端接口从 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)
102 lines
2.8 KiB
Dart
102 lines
2.8 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:fruitshorts/core/data/models/drama.dart';
|
|
import 'package:fruitshorts/core/data/remote/api_client.dart';
|
|
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
|
|
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
|
|
import 'package:fruitshorts/core/data/services/favorite_controller.dart';
|
|
import 'package:fruitshorts/pages/drama_detail/drama_detail_logic.dart';
|
|
|
|
import '../support/fake_watch_history.dart';
|
|
|
|
/// 详情页逻辑依赖:票据仓库 + 收藏控制器(测试里都是内存实现)。
|
|
DramaDetailLogic _logic(Drama drama, FakeWatchHistory history) =>
|
|
DramaDetailLogic(
|
|
drama: drama,
|
|
history: history,
|
|
playback: FakePlaybackRepository(),
|
|
favorites: FavoriteController(InMemoryFavoriteRepository()),
|
|
);
|
|
|
|
Drama _card(String id) => Drama(
|
|
id: id,
|
|
title: id,
|
|
synopsis: 'synopsis',
|
|
posterUrl: '/files/$id.jpg',
|
|
totalEpisodes: 3,
|
|
episodes: [
|
|
Episode(
|
|
id: '$id-1',
|
|
number: 1,
|
|
title: '第 1 集',
|
|
isFree: true,
|
|
videoUrl: '/files/$id-1.mp4',
|
|
),
|
|
],
|
|
);
|
|
|
|
Drama _detail(String id) => Drama(
|
|
id: id,
|
|
title: id,
|
|
synopsis: 'synopsis',
|
|
posterUrl: '/files/$id.jpg',
|
|
totalEpisodes: 3,
|
|
detailLoaded: true,
|
|
episodes: [
|
|
for (var number = 1; number <= 3; number++)
|
|
Episode(
|
|
id: '$id-$number',
|
|
number: number,
|
|
title: '第 $number 集',
|
|
isFree: true,
|
|
videoUrl: '/files/$id-$number.mp4',
|
|
),
|
|
],
|
|
);
|
|
|
|
void main() {
|
|
test('should_upgrade_to_full_episode_list_when_detail_loads_for_list_card', () async {
|
|
var calls = 0;
|
|
final logic = _logic(_card('signal'), FakeWatchHistory());
|
|
|
|
await logic.load(() async {
|
|
calls++;
|
|
return _detail('signal');
|
|
});
|
|
|
|
expect(calls, 1);
|
|
expect(logic.loading, isFalse);
|
|
expect(logic.failed, isFalse);
|
|
expect(logic.drama.episodes, hasLength(3));
|
|
logic.dispose();
|
|
});
|
|
|
|
test('should_keep_card_and_report_reason_when_load_fails', () async {
|
|
final logic = _logic(_card('signal'), FakeWatchHistory());
|
|
|
|
await logic.load(() async => throw const ApiException(500, '服务异常'));
|
|
|
|
expect(logic.failed, isTrue);
|
|
expect(logic.failureMessage, '服务异常');
|
|
expect(logic.drama.episodes, hasLength(1));
|
|
|
|
await logic.load(() async => throw StateError('offline'));
|
|
expect(logic.failed, isTrue);
|
|
expect(logic.failureMessage, isNull);
|
|
logic.dispose();
|
|
});
|
|
|
|
test('should_skip_request_when_detail_is_already_loaded', () async {
|
|
var calls = 0;
|
|
final logic = _logic(_detail('signal'), FakeWatchHistory());
|
|
|
|
await logic.load(() async {
|
|
calls++;
|
|
return _detail('signal');
|
|
});
|
|
|
|
expect(calls, 0);
|
|
expect(logic.drama.episodes, hasLength(3));
|
|
logic.dispose();
|
|
});
|
|
}
|