fixed tests

This commit is contained in:
Thibault Deckers 2022-08-29 21:30:18 +02:00
parent b012fc9ff5
commit 49b957faea
3 changed files with 15 additions and 9 deletions

View file

@ -4,12 +4,10 @@ import 'package:collection/collection.dart';
import 'package:test/fake.dart';
class FakeMediaFetchService extends Fake implements MediaFetchService {
Duration latency = Duration.zero;
Set<AvesEntry> entries = {};
@override
Future<AvesEntry?> getEntry(String uri, String? mimeType) async {
await Future.delayed(latency);
return entries.firstWhereOrNull((v) => v.uri == uri);
}
}

View file

@ -5,18 +5,23 @@ import 'package:aves/services/media/media_store_service.dart';
import 'package:test/fake.dart';
class FakeMediaStoreService extends Fake implements MediaStoreService {
Duration latency = Duration.zero;
Set<AvesEntry> entries = {};
late Set<AvesEntry> entries;
Duration? latency;
void reset() {
entries = {};
latency = null;
}
@override
Future<List<int>> checkObsoleteContentIds(List<int?> knownContentIds) async {
await Future.delayed(latency);
if (latency != null) await Future.delayed(latency!);
return [];
}
@override
Future<List<int>> checkObsoletePaths(Map<int?, String?> knownPathById) async {
await Future.delayed(latency);
if (latency != null) await Future.delayed(latency!);
return [];
}

View file

@ -51,7 +51,7 @@ void main() {
countryName: 'AUS',
);
setUp(() async {
setUpAll(() async {
// specify Posix style path context for consistent behaviour when running tests on Windows
getIt.registerLazySingleton<p.Context>(() => p.Context(style: p.Style.posix));
getIt.registerLazySingleton<AvesAvailability>(FakeAvesAvailability.new);
@ -71,7 +71,11 @@ void main() {
await androidFileUtils.init();
});
tearDown(() async {
setUp(() async {
(getIt<MediaStoreService>() as FakeMediaStoreService).reset();
});
tearDownAll(() async {
await getIt.reset();
});
@ -360,7 +364,6 @@ void main() {
FakeMediaStoreService.newImage('${FakeStorageService.primaryPath}Pictures/Arendt', '1'),
};
await androidFileUtils.init();
final source = await _initSource();
await tester.pumpWidget(
Builder(