42 lines
1.2 KiB
Dart
42 lines
1.2 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:nontonki/core/data/repositories/catalog_repository.dart';
|
|
import 'package:nontonki/core/data/models/drama.dart';
|
|
import 'package:nontonki/core/data/services/catalog_controller.dart';
|
|
|
|
void main() {
|
|
test(
|
|
'empty catalog is distinct from a failed load, and retry recovers',
|
|
() async {
|
|
final repo = ScriptedCatalogRepository();
|
|
final controller = CatalogController(repo);
|
|
await controller.load();
|
|
expect(controller.dramas, isEmpty);
|
|
expect(controller.error, isNull);
|
|
|
|
repo.fail = true;
|
|
await controller.load();
|
|
expect(controller.error, isNotNull);
|
|
|
|
repo.fail = false;
|
|
repo.items = await DemoCatalogRepository().fetchDramas();
|
|
await controller.load();
|
|
expect(controller.error, isNull);
|
|
expect(controller.dramas, hasLength(3));
|
|
expect(controller.dramas.first.episodes.length, 3);
|
|
},
|
|
);
|
|
}
|
|
|
|
class ScriptedCatalogRepository implements CatalogRepository {
|
|
bool fail = false;
|
|
List<Drama> items = const [];
|
|
|
|
@override
|
|
Future<List<Drama>> fetchDramas() async {
|
|
if (fail) throw StateError('offline');
|
|
return items;
|
|
}
|
|
}
|