Skip to content

commit acff97c

abduznik edited this page May 23, 2026 · 1 revision

test: update widget tests for zero-wait UI and snapshot services

Commit: acff97c40f3a07c296ad8357f418811e78d20f51

Author: abduznik

Date: 2026-05-01

Why: Adds or updates tests to ensure code correctness and prevent regressions.

Files Changed

test/widgets/library_screen_test.dart       |  24 ++++-
 test/widgets/library_screen_test.mocks.dart | 148 ++++++++++++++++++++++++++++
 2 files changed, 171 insertions(+), 1 deletion(-)
  • test/widgets/library_screen_test.dart
  • test/widgets/library_screen_test.mocks.dart

Diff

diff --git a/test/widgets/library_screen_test.dart b/test/widgets/library_screen_test.dart
index 938ebdb..d135362 100644
--- a/test/widgets/library_screen_test.dart
+++ b/test/widgets/library_screen_test.dart
@@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
 import 'package:freegosy/core/romm/romm_models.dart';
 import 'package:freegosy/core/romm/romm_service.dart';
 import 'package:freegosy/core/storage/directory_service.dart';
+import 'package:freegosy/providers/library_provider.dart';
 import 'package:freegosy/providers/paginated_games_provider.dart';
 import 'package:freegosy/providers/romm_provider.dart';
 import 'package:freegosy/providers/shared_prefs_provider.dart';
@@ -13,13 +14,17 @@ import 'package:mockito/mockito.dart';
 import 'package:shared_preferences/shared_preferences.dart';
 
 import 'package:freegosy/core/storage/rom_mapping_service.dart';
+import 'package:freegosy/core/romm/library_snapshot_service.dart';
+import 'package:freegosy/core/storage/metadata_cache_service.dart';
 import 'library_screen_test.mocks.dart';
 
-@GenerateMocks([RommService, DirectoryService, RomMappingService])
+@GenerateMocks([RommService, DirectoryService, RomMappingService, LibrarySnapshotService, MetadataCacheService])
 void main() {
   late MockRommService mockRommService;
   late MockDirectoryService mockDirectoryService;
   late MockRomMappingService mockRomMappingService;
+  late MockLibrarySnapshotService mockSnapshotService;
+  late MockMetadataCacheService mockCacheService;
   late SharedPreferences prefs;
 
   setUp(() async {
@@ -28,6 +33,8 @@ void main() {
     mockRommService = MockRommService();
     mockDirectoryService = MockDirectoryService();
     mockRomMappingService = MockRomMappingService();
+    mockSnapshotService = MockLibrarySnapshotService();
+    mockCacheService = MockMetadataCacheService();
     
     when(mockRommService.config).thenReturn(RomMConfig(baseUrl: 'https://test.com', username: 'u', password: 'p'));
     when(mockRommService.resolveCoverUrl(any)).thenReturn(null);
@@ -38,6 +45,9 @@ void main() {
     when(mockDirectoryService.status).thenReturn(const StorageStatus());
     when(mockRomMappingService.getMappings()).thenReturn({});
     when(mockRomMappingService.getMTimes()).thenReturn({});
+    when(mockSnapshotService.loadPlatforms()).thenAnswer((_) async => []);
+    when(mockSnapshotService.loadCollections()).thenAnswer((_) async => []);
+    when(mockCacheService.cachedGames).thenReturn([]);
   });
 
   group('LibraryScreen', () {
@@ -51,6 +61,9 @@ void main() {
           romMappingServiceProvider.overrideWith((ref) => Future.value(mockRomMappingService)),
           romScannerServiceProvider.overrideWithValue(null),
           directoryServiceProvider.overrideWith((ref) => Future.value(mockDirectoryService)),
+          librarySnapshotServiceProvider.overrideWithValue(mockSnapshotService),
+          metadataCacheServiceProvider.overrideWith((ref) => Future.value(mockCacheService)),
+          platformsProvider.overrideWith((ref) => []),
           paginatedGamesProvider.overrideWith((ref) => PaginatedGamesNotifier(ref)..state = const PaginatedGamesState(isLoading: true)),
         ],
         child: const MaterialApp(home: LibraryScreen()),
@@ -75,6 +88,9 @@ void main() {
           romMappingServiceProvider.overrideWith((ref) => Future.value(mockRomMappingService)),
           romScannerServiceProvider.overrideWithValue(null),
           directoryServiceProvider.overrideWith((ref) => Future.value(mockDirectoryService)),
+          librarySnapshotServiceProvider.overrideWithValue(mockSnapshotService),
+          metadataCacheServiceProvider.overrideWith((ref) => Future.value(mockCacheService)),
+          platformsProvider.overrideWith((ref) => []),
           isHomeSelectedProvider.overrideWith((ref) => false),
           paginatedGamesProvider.overrideWith((ref) => PaginatedGamesNotifier(ref)..state = PaginatedGamesState(games: games, total: 2, hasMore: false)),
         ],
@@ -97,6 +113,9 @@ void main() {
           romMappingServiceProvider.overrideWith((ref) => Future.value(mockRomMappingService)),
           romScannerServiceProvider.overrideWithValue(null),
           directoryServiceProvider.overrideWith((ref) => Future.value(mockDirectoryService)),
+          librarySnapshotServiceProvider.overrideWithValue(mockSnapshotService),
+          metadataCacheServiceProvider.overrideWith((ref) => Future.value(mockCacheService)),
+          platformsProvider.overrideWith((ref) => []),
           isHomeSelectedProvider.overrideWith((ref) => false),
           paginatedGamesProvider.overrideWith((ref) => PaginatedGamesNotifier(ref)..state = const PaginatedGamesState(games: [], total: 0, hasMore: false)),
         ],
@@ -118,6 +137,9 @@ void main() {
           romMappingServiceProvider.overrideWith((ref) => Future.value(mockRomMappingService)),
           romScannerServiceProvider.overrideWithValue(null),
           directoryServiceProvider.overrideWith((ref) => Future.value(mockDirectoryService)),
+          librarySnapshotServiceProvider.overrideWithValue(mockSnapshotService),
+          metadataCacheServiceProvider.overrideWith((ref) => Future.value(mockCacheService)),
+          platformsProvider.overrideWith((ref) => []),
           isHomeSelectedProvider.overrideWith((ref) => false),
           paginatedGamesProvider.overrideWith((ref) => PaginatedGamesNotifier(ref)..state = const PaginatedGamesState(error: 'Connection Failed')),
         ],
diff --git a/test/widgets/library_screen_test.mocks.dart b/test/widgets/library_screen_test.mocks.dart
index 97f44d9..f56efbf 100644
--- a/test/widgets/library_screen_test.mocks.dart
+++ b/test/widgets/library_screen_test.mocks.dart
@@ -10,9 +10,11 @@ import 'dart:typed_data' as _i11;
 import 'package:flutter/foundation.dart' as _i2;
 import 'package:freegosy/core/emulator/linux_strategies/linux_environment_strategy.dart'
     as _i5;
+import 'package:freegosy/core/romm/library_snapshot_service.dart' as _i13;
 import 'package:freegosy/core/romm/romm_models.dart' as _i3;
 import 'package:freegosy/core/romm/romm_service.dart' as _i6;
 import 'package:freegosy/core/storage/directory_service.dart' as _i4;
+import 'package:freegosy/core/storage/metadata_cache_service.dart' as _i14;
 import 'package:freegosy/core/storage/rom_mapping_service.dart' as _i12;
 import 'package:mockito/mockito.dart' as _i1;
 import 'package:mockito/src/dummies.dart' as _i7;
@@ -1036,3 +1038,149 @@ class MockRomMappingService extends _i1.Mock implements _i12.RomMappingService {
           )
           as _i8.Future<void>);
 }
+
+/// A class which mocks [LibrarySnapshotService].
+///
+/// See the documentation for Mockito's code generation for more information.
+class MockLibrarySnapshotService extends _i1.Mock
+    implements _i13.LibrarySnapshotService {
+  MockLibrarySnapshotService() {
+    _i1.throwOnMissingStub(this);
+  }
+
+  @override
+  _i8.Future<void> savePlatforms(List<_i3.Platform>? platforms) =>
+      (super.noSuchMethod(
+            Invocation.method(#savePlatforms, [platforms]),
+            returnValue: _i8.Future<void>.value(),
+            returnValueForMissingStub: _i8.Future<void>.value(),
+          )
+          as _i8.Future<void>);
+
+  @override
+  _i8.Future<List<_i3.Platform>> loadPlatforms() =>
+      (super.noSuchMethod(
+            Invocation.method(#loadPlatforms, []),
+            returnValue: _i8.Future<List<_i3.Platform>>.value(<_i3.Platform>[]),
+          )
+          as _i8.Future<List<_i3.Platform>>);
+
+  @override
+  _i8.Future<void> saveCollections(List<Map<String, dynamic>>? collections) =>
+      (super.noSuchMethod(
+            Invocation.method(#saveCollections, [collections]),
+            returnValue: _i8.Future<void>.value(),
+            returnValueForMissingStub: _i8.Future<void>.value(),
+          )
+          as _i8.Future<void>);
+
+  @override
+  _i8.Future<List<Map<String, dynamic>>> loadCollections() =>
+      (super.noSuchMethod(
+            Invocation.method(#loadCollections, []),
+            returnValue: _i8.Future<List<Map<String, dynamic>>>.value(
+              <Map<String, dynamic>>[],
+            ),
+          )
+          as _i8.Future<List<Map<String, dynamic>>>);
+
+  @override
+  _i8.Future<void> clear() =>
+      (super.noSuchMethod(
+            Invocation.method(#clear, []),
+            returnValue: _i8.Future<void>.value(),
+            returnValueForMissingStub: _i8.Future<void>.value(),
+          )
+          as _i8.Future<void>);
+}
+
+/// A class which mocks [MetadataCacheService].
+///
+/// See the documentation for Mockito's code generation for more information.
+class MockMetadataCacheService extends _i1.Mock
+    implements _i14.MetadataCacheService {
+  MockMetadataCacheService() {
+    _i1.throwOnMissingStub(this);
+  }
+
+  @override
+  List<_i3.Game> get cachedGames =>
+      (super.noSuchMethod(
+            Invocation.getter(#cachedGames),
+            returnValue: <_i3.Game>[],
+          )
+          as List<_i3.Game>);
+
+  @override
+  _i8.Future<void> load() =>
+      (super.noSuchMethod(
+            Invocation.method(#load, []),
+            returnValue: _i8.Future<void>.value(),
+            returnValueForMissingStub: _i8.Future<void>.value(),
+          )
+          as _i8.Future<void>);
+
+  @override
+  _i8.Future<void> saveGames(List<_i3.Game>? games) =>
+      (super.noSuchMethod(
+            Invocation.method(#saveGames, [games]),
+            returnValue: _i8.Future<void>.value(),
+            returnValueForMissingStub: _i8.Future<void>.value(),
+          )
+          as _i8.Future<void>);
+
+  @override
+  _i8.Future<void> updatePlatformCount(String? platformId, int? count) =>
+      (super.noSuchMethod(
+            Invocation.method(#updatePlatformCount, [platformId, count]),
+            returnValue: _i8.Future<void>.value(),
+            returnValueForMissingStub: _i8.Future<void>.value(),
+          )
+          as _i8.Future<void>);
+
+  @override
+  bool isPlatformValid(String? platformId, int? remoteCount) =>
+      (super.noSuchMethod(
+            Invocation.method(#isPlatformValid, [platformId, remoteCount]),
+            returnValue: false,
+          )
+          as bool);
+
+  @override
+  _i8.Future<void> invalidatePlatform(String? platformId) =>
+      (super.noSuchMethod(
+            Invocation.method(#invalidatePlatform, [platformId]),
+            returnValue: _i8.Future<void>.value(),
+            returnValueForMissingStub: _i8.Future<void>.value(),
+          )
+          as _i8.Future<void>);
+
+  @override
+  List<_i3.Game> getOfflineGames({
+    String? platformId,
+    String? search,
+    List<String>? genres,
+    List<String>? regions,
+    List<String>? languages,
+  }) =>
+      (super.noSuchMethod(
+            Invocation.method(#getOfflineGames, [], {
+              #platformId: platformId,
+              #search: search,
+              #genres: genres,
+              #regions: regions,
+              #languages: languages,
+            }),
+            returnValue: <_i3.Game>[],
+          )
+          as List<_i3.Game>);
+
+  @override
+  _i8.Future<void> clear() =>
+      (super.noSuchMethod(
+            Invocation.method(#clear, []),
+            returnValue: _i8.Future<void>.value(),
+            returnValueForMissingStub: _i8.Future<void>.value(),
+          )
+          as _i8.Future<void>);
+}

Clone this wiki locally