fix(library): 优化观看历史标题加载

This commit is contained in:
Zhou Weidong committed 2026-10-22 12:42:58 +08:00
1 parent abfca7a3be
commit 78114fa46d
11 files changed
+135 -88

No files matched your search

-30
View File
@@ -50,34 +50,4 @@ void main() {
expect(page.list.single.episodeNumber, 6);
expect(page.list.single.totalEpisodes, 68);
});
test(
'should_wrap_legacy_list_when_backend_has_not_deployed_paging',
() async {
final adapter = FakeHttpAdapter(
(_) async => FakeHttpResponse(
jsonEncode({
'code': 0,
'message': 'ok',
'data': [
{
'dramaId': '5',
'episodeId': '7',
'positionMs': '1000',
'durationMs': '2000',
},
],
}),
),
);
final api = WatchApi(
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
);
final page = await api.recent();
expect(page.total, 1);
expect(page.list.single.dramaId, '5');
},
);
}
@@ -16,11 +16,13 @@ import 'package:fruitshorts/core/data/services/watch_records_controller.dart';
WatchProgress _progress(
String dramaId, {
String episodeId = 'episode-1',
String? dramaTitle,
int positionMs = 12000,
int durationMs = 60000,
}) => WatchProgress(
dramaId: dramaId,
episodeId: episodeId,
dramaTitle: dramaTitle,
position: Duration(milliseconds: positionMs),
duration: Duration(milliseconds: durationMs),
updatedAt: DateTime(2026, 10, 17, 12),
@@ -74,6 +76,27 @@ void main() {
expect(controller.error, isNull);
});
test('should_use_backend_title_and_skip_detail_until_opened', () async {
final history = ControlledWatchHistory([
_progress('12', dramaTitle: '后端标题'),
]);
final catalog = ScriptedWatchCatalog();
final controller = WatchRecordsController(
history: history,
catalog: catalog,
);
await controller.load();
expect(controller.records.single.displayTitle, '后端标题');
expect(catalog.calls, isEmpty);
final detail = await controller.detailForOpen('12');
expect(detail?.id, '12');
expect(catalog.calls, ['12']);
});
test('should_reuse_cached_details_when_records_are_loaded_again', () async {
final history = ControlledWatchHistory([_progress('1'), _progress('2')]);
final catalog = ScriptedWatchCatalog();
+6 -6
View File
@@ -111,16 +111,13 @@ void main() {
episodeNumber: 3,
),
]);
final catalog = _AlwaysFailingWatchCatalog();
await _pumpPage(
tester,
auth: auth,
history: history,
catalog: _AlwaysFailingWatchCatalog(),
);
await _pumpPage(tester, auth: auth, history: history, catalog: catalog);
expect(find.text('Backend Title'), findsOneWidget);
expect(find.text('Episode 3'), findsOneWidget);
expect(catalog.calls, isEmpty);
expect(
find.byKey(const Key('watch-record-cover-metadata')),
findsOneWidget,
@@ -421,8 +418,11 @@ class _FailingWatchCatalog implements CatalogRepository {
}
class _AlwaysFailingWatchCatalog implements CatalogRepository {
final List<String> calls = [];
@override
Future<Drama> fetchDrama(String dramaId) async {
calls.add(dramaId);
throw StateError('missing detail');
}