feat(client): 对接详情/播放/进度续看/收藏(K1 看剧闭环)+ 三态 UI

后端接口从 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)
This commit is contained in:
Vicky committed 2026-10-16 17:39:05 +08:00
1 parent 94ff9f1177
commit d7eff4ca59
48 files changed
+2411 -377

No files matched your search

+36 -15
View File
@@ -8,6 +8,11 @@ import 'package:shared_preferences_platform_interface/shared_preferences_async_p
import 'support/fake_catalog.dart';
import 'support/widget_player.dart';
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
import 'package:fruitshorts/core/data/repositories/catalog_repository.dart';
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
import 'package:fruitshorts/core/data/services/playback_session.dart';
void main() {
/// 默认按「已登录」起测:账号体系接上后,"登录"不再是本地演示开关,
@@ -27,17 +32,31 @@ void main() {
seedSignedInSession();
});
/// 所有 widget 测试都注入离线仓库:票据 / 进度 / 收藏都不碰网络,
/// 这样断言的是 UI 行为,而不是后端有没有起。
Widget appUnderTest({
PlayerFactory? playerFactory,
CatalogRepository? catalogRepository,
}) => LumaDramaApp(
playerFactory: playerFactory ?? createWidgetPlayer,
catalogRepository: catalogRepository ?? FakeCatalogRepository(),
watchHistoryRepository: InMemoryWatchHistoryRepository(),
favoriteRepository: InMemoryFavoriteRepository(
cards: FakeCatalogRepository().dramas,
),
playbackRepository: FakePlaybackRepository(),
);
testWidgets(
'should_promote_next_without_recreating_it_or_showing_loading_when_home_is_swiped',
(tester) async {
final created = <String>[];
await tester.pumpWidget(
LumaDramaApp(
appUnderTest(
playerFactory: (episode) {
created.add(episode.id);
return WidgetPlayer();
},
catalogRepository: FakeCatalogRepository(),
),
);
await tester.pumpAndSettle();
@@ -64,7 +83,7 @@ void main() {
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
LumaDramaApp(playerFactory: createWidgetPlayer, catalogRepository: FakeCatalogRepository()),
appUnderTest(),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-home')));
@@ -91,7 +110,7 @@ void main() {
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
LumaDramaApp(playerFactory: createWidgetPlayer, catalogRepository: FakeCatalogRepository()),
appUnderTest(),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-home')));
@@ -116,7 +135,7 @@ void main() {
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
LumaDramaApp(playerFactory: createWidgetPlayer, catalogRepository: FakeCatalogRepository()),
appUnderTest(),
);
await tester.pumpAndSettle();
expect(find.text('Continue Watching'), findsOneWidget);
@@ -171,7 +190,7 @@ void main() {
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
LumaDramaApp(playerFactory: createWidgetPlayer, catalogRepository: FakeCatalogRepository()),
appUnderTest(),
);
await tester.pumpAndSettle();
expect(find.byTooltip('Captions'), findsNothing);
@@ -200,7 +219,7 @@ void main() {
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
LumaDramaApp(playerFactory: createWidgetPlayer, catalogRepository: FakeCatalogRepository()),
appUnderTest(),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-home')));
@@ -226,7 +245,7 @@ void main() {
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
LumaDramaApp(playerFactory: createWidgetPlayer, catalogRepository: FakeCatalogRepository()),
appUnderTest(),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-my')));
@@ -249,7 +268,7 @@ void main() {
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
LumaDramaApp(playerFactory: createWidgetPlayer, catalogRepository: FakeCatalogRepository()),
appUnderTest(),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Home'));
@@ -283,7 +302,7 @@ void main() {
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
LumaDramaApp(playerFactory: createWidgetPlayer, catalogRepository: FakeCatalogRepository()),
appUnderTest(),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Home'));
@@ -335,7 +354,7 @@ void main() {
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
LumaDramaApp(playerFactory: createWidgetPlayer, catalogRepository: FakeCatalogRepository()),
appUnderTest(),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-home')));
@@ -366,7 +385,7 @@ void main() {
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
LumaDramaApp(playerFactory: createWidgetPlayer, catalogRepository: FakeCatalogRepository()),
appUnderTest(),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-home')));
@@ -404,7 +423,7 @@ void main() {
);
await tester.pumpWidget(
LumaDramaApp(playerFactory: createWidgetPlayer, catalogRepository: FakeCatalogRepository()),
appUnderTest(),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-home')));
@@ -445,7 +464,7 @@ void main() {
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
LumaDramaApp(playerFactory: createWidgetPlayer, catalogRepository: FakeCatalogRepository()),
appUnderTest(),
);
await tester.pumpAndSettle();
@@ -473,8 +492,10 @@ void main() {
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
// 收藏要求登录态:沿用本文件已有的"假登录"初始化
seedSignedInSession();
await tester.pumpWidget(
LumaDramaApp(playerFactory: createWidgetPlayer, catalogRepository: FakeCatalogRepository()),
appUnderTest(),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('tab-home')));