fix(flutter): 修复导航白线与观看记录错误透传
This commit is contained in:
1 parent
ac706a42a5
commit
732483465c
8 files changed
+85
-3
No files matched your search
@@ -8,6 +8,7 @@ import 'package:fruitshorts/core/data/models/home_feed.dart';
|
||||
import 'package:fruitshorts/core/data/models/watch_progress.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/catalog_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
|
||||
import 'package:fruitshorts/core/data/remote/api_client.dart';
|
||||
import 'package:fruitshorts/core/data/services/watch_records_controller.dart';
|
||||
|
||||
WatchProgress _progress(
|
||||
@@ -153,6 +154,19 @@ void main() {
|
||||
expect(controller.error, 'progressError');
|
||||
expect(controller.records, isEmpty);
|
||||
});
|
||||
|
||||
test('should_preserve_backend_message_when_recent_request_fails', () async {
|
||||
final history = ControlledWatchHistory([])
|
||||
..recentError = const ApiException(100000, '账号不存在,请先注册');
|
||||
final controller = WatchRecordsController(
|
||||
history: history,
|
||||
catalog: ScriptedWatchCatalog(),
|
||||
);
|
||||
|
||||
await controller.load();
|
||||
|
||||
expect(controller.error, '账号不存在,请先注册');
|
||||
});
|
||||
}
|
||||
|
||||
class ControlledWatchHistory implements WatchHistoryRepository {
|
||||
@@ -160,6 +174,7 @@ class ControlledWatchHistory implements WatchHistoryRepository {
|
||||
|
||||
final List<WatchProgress> items;
|
||||
bool failRecent = false;
|
||||
Object? recentError;
|
||||
bool failRemove = false;
|
||||
bool failClear = false;
|
||||
Completer<void>? removeGate;
|
||||
@@ -178,6 +193,7 @@ class ControlledWatchHistory implements WatchHistoryRepository {
|
||||
|
||||
@override
|
||||
Future<List<WatchProgress>> recent({int limit = 20}) async {
|
||||
if (recentError != null) throw recentError!;
|
||||
if (failRecent) throw StateError('recent unavailable');
|
||||
return items.take(limit).toList();
|
||||
}
|
||||
|
||||
@@ -126,6 +126,23 @@ void main() {
|
||||
expect(find.text('No watch history yet.'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('should_show_backend_message_when_recent_request_fails', (
|
||||
tester,
|
||||
) async {
|
||||
final auth = await _auth(signedIn: true);
|
||||
final history = _FailingRecentHistory();
|
||||
|
||||
await _pumpPage(
|
||||
tester,
|
||||
auth: auth,
|
||||
history: history,
|
||||
catalog: FakeCatalogRepository(),
|
||||
);
|
||||
|
||||
expect(find.text('账号不存在,请先注册'), findsOneWidget);
|
||||
expect(find.byKey(const Key('watch-records-retry')), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
WatchProgress _progress(String dramaId) => WatchProgress(
|
||||
@@ -202,6 +219,13 @@ class CountingWatchHistory extends InMemoryWatchHistoryRepository {
|
||||
}
|
||||
}
|
||||
|
||||
class _FailingRecentHistory extends InMemoryWatchHistoryRepository {
|
||||
@override
|
||||
Future<List<WatchProgress>> recent({int limit = 20}) async {
|
||||
throw const ApiException(100000, '账号不存在,请先注册');
|
||||
}
|
||||
}
|
||||
|
||||
class _FailingWatchCatalog implements CatalogRepository {
|
||||
final _delegate = FakeCatalogRepository();
|
||||
|
||||
|
||||
Reference in new issue
Block a user