diff --git a/test/core/network/auth_credentials_storage_test.dart b/test/core/network/auth_credentials_storage_test.dart index 3186c737c..54436efa9 100644 --- a/test/core/network/auth_credentials_storage_test.dart +++ b/test/core/network/auth_credentials_storage_test.dart @@ -29,7 +29,7 @@ import 'package:wger/core/network/auth_credentials_storage.dart'; import 'package:wger/core/network/secure_token_storage.dart'; import 'package:wger/core/shared_preferences.dart'; -import '../../fake_auth_environment.dart'; +import '../../helpers/fake_auth_environment.dart'; import 'auth_credentials_storage_test.mocks.dart'; @GenerateMocks([SecureTokenStorage]) diff --git a/test/core/network/auth_notifier_login_test.dart b/test/core/network/auth_notifier_login_test.dart index e8ceef763..52f75f92f 100644 --- a/test/core/network/auth_notifier_login_test.dart +++ b/test/core/network/auth_notifier_login_test.dart @@ -26,10 +26,6 @@ import 'package:http/http.dart' as http; import 'package:http/http.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'package:package_info_plus/package_info_plus.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart'; -import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart'; import 'package:wger/core/consts.dart'; import 'package:wger/core/exceptions/http_exception.dart'; import 'package:wger/core/exceptions/mfa_required_exception.dart'; @@ -42,6 +38,7 @@ import 'package:wger/features/account/models/account.dart'; import 'package:wger/features/account/providers/account_notifier.dart'; import 'package:wger/features/account/providers/account_repository.dart'; +import '../../helpers/fake_auth_environment.dart'; import 'auth_notifier_login_test.mocks.dart'; /// Storage that simulates the process dying at the moment login claims DB @@ -65,7 +62,7 @@ void main() { // Needed to install the path_provider mock channel below. TestWidgetsFlutterBinding.ensureInitialized(); - SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty(); + installFakeAuthEnvironment(); late MockClient mockClient; late MockSecureTokenStorage mockSecureStorage; @@ -144,16 +141,6 @@ void main() { } }); - SharedPreferences.setMockInitialValues({}); - PackageInfo.setMockInitialValues( - appName: 'wger', - packageName: 'com.example.example', - version: '1.2.3', - buildNumber: '2', - buildSignature: 'buildSignature', - ); - await PreferenceHelper.asyncPref.clear(); - // Default gating-chain mocks (happy path). Login-flow tests override // only what they care about. when(mockClient.get(tVersion)).thenAnswer((_) async => Response('"99.99.99"', 200)); diff --git a/test/core/network/auth_notifier_powersync_test.dart b/test/core/network/auth_notifier_powersync_test.dart index ce3307745..9a5a8c079 100644 --- a/test/core/network/auth_notifier_powersync_test.dart +++ b/test/core/network/auth_notifier_powersync_test.dart @@ -29,18 +29,15 @@ import 'package:http/http.dart' as http; import 'package:http/http.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'package:package_info_plus/package_info_plus.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart'; -import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart'; import 'package:wger/core/consts.dart'; import 'package:wger/core/network/auth_notifier.dart'; import 'package:wger/core/network/auth_state.dart'; import 'package:wger/core/network/secure_token_storage.dart'; import 'package:wger/core/shared_preferences.dart'; -import '../../fake_connectivity.dart'; +import '../../helpers/fake_auth_environment.dart'; +import '../../helpers/fake_connectivity.dart'; import 'auth_notifier_powersync_test.mocks.dart'; @GenerateMocks([http.Client, SecureTokenStorage]) @@ -51,7 +48,7 @@ void main() { // Replacement for SharedPreferences.setMockInitialValues() for the // async API used by the auth notifier. - SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty(); + installFakeAuthEnvironment(); // The background revalidation observes connectivity to re-probe on // reconnect; stub the connectivity platform so no real plugin is needed. @@ -103,15 +100,6 @@ void main() { when(mockSecureStorage.readRefreshToken()).thenAnswer((_) async => null); when(mockSecureStorage.writeRefreshToken(any)).thenAnswer((_) async {}); - SharedPreferences.setMockInitialValues({}); - PackageInfo.setMockInitialValues( - appName: 'wger', - packageName: 'com.example.example', - version: '1.2.3', - buildNumber: '2', - buildSignature: 'buildSignature', - ); - // Point the on-disk wipe path at a real temp dir so a wiping logout // succeeds (no file present -> no-op). Set [failDbPathLookup] to make the // lookup throw and exercise a failed wipe. @@ -133,7 +121,6 @@ void main() { // Wipe async prefs between tests (the platform instance is shared). final prefs = PreferenceHelper.asyncPref; - await prefs.clear(); // Persist a logged-in user so auto-login actually runs. await prefs.setString( diff --git a/test/core/network/base_provider_test.dart b/test/core/network/base_provider_test.dart index e7a7834de..605ec6a14 100644 --- a/test/core/network/base_provider_test.dart +++ b/test/core/network/base_provider_test.dart @@ -29,14 +29,13 @@ import 'package:wger/core/exceptions/http_exception.dart'; import 'package:wger/core/network/base_provider.dart'; import '../../fixtures/fixture_reader.dart'; -import '../../utils.dart'; import 'base_provider_test.mocks.dart'; @GenerateMocks([http.Client]) void main() { group('test base provider', () { test('Test the makeUrl helper', () { - final WgerBaseProvider provider = buildTestBaseProvider(); + final WgerBaseProvider provider = WgerBaseProvider(serverUrl: 'https://localhost'); expect( Uri.https('localhost', '/api/v2/endpoint/'), @@ -70,9 +69,7 @@ void main() { test('Test the makeUrl helper with sub url', () { // Trailing slash is removed when saving the server URL - final WgerBaseProvider provider = buildTestBaseProvider( - serverUrl: 'https://example.com/wger-url', - ); + final WgerBaseProvider provider = WgerBaseProvider(serverUrl: 'https://example.com/wger-url'); expect( Uri.https('example.com', '/wger-url/api/v2/endpoint/'), @@ -141,7 +138,10 @@ void main() { ).thenAnswer((_) => Future.value(response3)); // Act - final WgerBaseProvider provider = buildTestBaseProvider(client: mockHttpClient); + final WgerBaseProvider provider = WgerBaseProvider( + serverUrl: 'https://localhost', + client: mockHttpClient, + ); final data = await provider.fetchPaginated(paginationUri1); // Assert @@ -160,7 +160,7 @@ void main() { setUp(() { mockClient = MockClient(); - repo = buildTestBaseProvider(client: mockClient); + repo = WgerBaseProvider(serverUrl: 'https://localhost', client: mockClient); }); final uri = Uri.https('localhost', '/api/v2/endpoint/'); diff --git a/test/core/network/server_gating_test.dart b/test/core/network/server_gating_test.dart index 7c2e8688a..07747eec3 100644 --- a/test/core/network/server_gating_test.dart +++ b/test/core/network/server_gating_test.dart @@ -28,7 +28,7 @@ import 'package:wger/core/network/auth_credentials_storage.dart'; import 'package:wger/core/network/secure_token_storage.dart'; import 'package:wger/core/network/server_gating.dart'; -import '../../fake_auth_environment.dart'; +import '../../helpers/fake_auth_environment.dart'; /// The version gates don't touch storage; this stand-in satisfies the /// constructor without pulling in secure-storage plumbing. diff --git a/test/core/recovery_screens_test.dart b/test/core/recovery_screens_test.dart index 9285196f4..ef3713aca 100644 --- a/test/core/recovery_screens_test.dart +++ b/test/core/recovery_screens_test.dart @@ -26,10 +26,6 @@ import 'package:http/http.dart' as http; import 'package:http/http.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'package:package_info_plus/package_info_plus.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart'; -import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart'; import 'package:wger/core/consts.dart'; import 'package:wger/core/network/auth_notifier.dart'; import 'package:wger/core/network/secure_token_storage.dart'; @@ -37,6 +33,7 @@ import 'package:wger/core/powersync_unreachable_screen.dart'; import 'package:wger/core/shared_preferences.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; +import '../helpers/fake_auth_environment.dart'; import 'recovery_screens_test.mocks.dart'; /// Widget tests for the recovery screens. @@ -44,7 +41,7 @@ import 'recovery_screens_test.mocks.dart'; void main() { // Replacement for SharedPreferences.setMockInitialValues() for the // async API used by the auth notifier. - SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty(); + installFakeAuthEnvironment(); late MockClient mockClient; late MockSecureTokenStorage mockSecureStorage; @@ -99,18 +96,8 @@ void main() { when(mockSecureStorage.readRefreshToken()).thenAnswer((_) async => null); when(mockSecureStorage.writeRefreshToken(any)).thenAnswer((_) async {}); - SharedPreferences.setMockInitialValues({}); - PackageInfo.setMockInitialValues( - appName: 'wger', - packageName: 'com.example.example', - version: '1.2.3', - buildNumber: '2', - buildSignature: 'buildSignature', - ); - // Wipe async prefs between tests (the platform instance is shared). final prefs = PreferenceHelper.asyncPref; - await prefs.clear(); // Saved login → autoLogin runs the full probe path. await prefs.setString( diff --git a/test/features/account/widgets/settings/certs_not_verified_test.dart b/test/features/account/widgets/settings/certs_not_verified_test.dart index 8e7b1dbf3..578094fa5 100644 --- a/test/features/account/widgets/settings/certs_not_verified_test.dart +++ b/test/features/account/widgets/settings/certs_not_verified_test.dart @@ -30,14 +30,7 @@ import 'package:wger/core/network/auth_state.dart'; import 'package:wger/features/account/widgets/settings/certs_not_verified.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; -class _FakeAuthNotifier extends AuthNotifier { - _FakeAuthNotifier(this._state); - - final AuthState _state; - - @override - Future build() async => _state; -} +import '../../../../helpers/fake_auth_notifier.dart'; void main() { const selfHosted = 'https://gym.example.com'; @@ -58,7 +51,7 @@ void main() { overrides: [ appSettingsPrefsProvider.overrideWithValue(prefs), authProvider.overrideWith( - () => _FakeAuthNotifier( + () => FakeAuthNotifier( AuthState(status: AuthStatus.loggedIn, serverUrl: serverUrl), ), ), diff --git a/test/features/auth/screens/auth_screen_test.dart b/test/features/auth/screens/auth_screen_test.dart index afbb4a1f7..0d02839ac 100644 --- a/test/features/auth/screens/auth_screen_test.dart +++ b/test/features/auth/screens/auth_screen_test.dart @@ -25,11 +25,7 @@ import 'package:http/http.dart' as http; import 'package:http/http.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'package:package_info_plus/package_info_plus.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart'; -import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart'; import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'; import 'package:wger/core/consts.dart'; import 'package:wger/core/http_overrides.dart'; @@ -41,7 +37,8 @@ import 'package:wger/features/auth/screens/auth_screen.dart'; import 'package:wger/features/auth/screens/mfa_challenge_screen.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; -import '../../../fake_connectivity.dart'; +import '../../../helpers/fake_auth_environment.dart'; +import '../../../helpers/fake_connectivity.dart'; import 'auth_screen_test.mocks.dart'; /// Captures `launchUrl(...)` calls so the web-handoff test can inspect the @@ -62,6 +59,9 @@ void main() { // The auth screen watches networkStatusProvider to gate the action button. // Stub connectivity so that probe is deterministic. installFakeConnectivity(); + // Installs the prefs/PackageInfo fakes and clears the store between tests, + // so values a test writes (e.g. PREFS_LAST_SERVER) don't leak into the next. + installFakeAuthEnvironment(); late MockClient mockClient; late MockSecureTokenStorage mockSecureStorage; @@ -121,20 +121,6 @@ void main() { // Default: online. The offline test overrides this. reachabilityCheck = (_, _, _) async => (reachable: true, reason: 'test'); - SharedPreferences.setMockInitialValues({}); - SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty(); - // PreferenceHelper caches its SharedPreferencesAsync, so swapping the - // platform instance above does not isolate it; clear the store so values a - // test writes (e.g. PREFS_LAST_SERVER) don't leak into the next one. - await PreferenceHelper.asyncPref.clear(); - PackageInfo.setMockInitialValues( - appName: 'wger', - packageName: 'com.example.example', - version: '1.2.3', - buildNumber: '2', - buildSignature: 'buildSignature', - ); - // Happy-path stubs for the headless login / signup endpoints; tests // that exercise error responses override these as needed. when( diff --git a/test/features/auth/screens/mfa_challenge_screen_test.dart b/test/features/auth/screens/mfa_challenge_screen_test.dart index 2eb01b5cf..71c8a3a59 100644 --- a/test/features/auth/screens/mfa_challenge_screen_test.dart +++ b/test/features/auth/screens/mfa_challenge_screen_test.dart @@ -25,23 +25,19 @@ import 'package:http/http.dart' as http; import 'package:http/http.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'package:package_info_plus/package_info_plus.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart'; -import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart'; import 'package:wger/core/network/auth_notifier.dart'; import 'package:wger/core/network/secure_token_storage.dart'; -import 'package:wger/core/shared_preferences.dart'; import 'package:wger/core/update_app_screen.dart'; import 'package:wger/core/update_server_screen.dart'; import 'package:wger/features/auth/screens/mfa_challenge_screen.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; +import '../../../helpers/fake_auth_environment.dart'; import 'mfa_challenge_screen_test.mocks.dart'; @GenerateMocks([http.Client, SecureTokenStorage]) void main() { - SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty(); + installFakeAuthEnvironment(); late MockClient mockClient; late MockSecureTokenStorage mockSecureStorage; @@ -95,16 +91,6 @@ void main() { when(mockSecureStorage.readRefreshToken()).thenAnswer((_) async => null); when(mockSecureStorage.writeRefreshToken(any)).thenAnswer((_) async {}); - SharedPreferences.setMockInitialValues({}); - PackageInfo.setMockInitialValues( - appName: 'wger', - packageName: 'com.example.example', - version: '1.2.3', - buildNumber: '2', - buildSignature: 'buildSignature', - ); - await PreferenceHelper.asyncPref.clear(); - // Gating-chain happy-path stubs so a successful completeMfa reaches // AuthStatus.loggedIn rather than getting stuck on a probe. when(mockClient.get(tVersion)).thenAnswer((_) async => Response('"99.99.99"', 200)); diff --git a/test/features/exercises/screens/add_exercise_screen_test.dart b/test/features/exercises/screens/add_exercise_screen_test.dart index bd264c81e..bc63d84e8 100644 --- a/test/features/exercises/screens/add_exercise_screen_test.dart +++ b/test/features/exercises/screens/add_exercise_screen_test.dart @@ -37,7 +37,7 @@ import 'package:wger/features/exercises/widgets/add_exercise/steps/step_1_basics import 'package:wger/l10n/generated/app_localizations.dart'; import '../../../../test_data/exercises.dart'; -import '../../../fake_connectivity.dart'; +import '../../../helpers/fake_connectivity.dart'; import 'add_exercise_screen_test.mocks.dart'; /// Test suite for the exercise-contribution screen. diff --git a/test/features/exercises/widgets/exercises_detail_widget_test.dart b/test/features/exercises/widgets/exercises_detail_widget_test.dart index ebe8c276a..875cdb468 100644 --- a/test/features/exercises/widgets/exercises_detail_widget_test.dart +++ b/test/features/exercises/widgets/exercises_detail_widget_test.dart @@ -31,7 +31,7 @@ import 'package:wger/features/exercises/widgets/exercises.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; import '../../../../test_data/exercises.dart'; -import '../../../fake_connectivity.dart'; +import '../../../helpers/fake_connectivity.dart'; import 'exercises_detail_widget_test.mocks.dart'; @GenerateMocks([ExerciseRepository]) diff --git a/test/features/nutrition/providers/nutrition_notifier_test.dart b/test/features/nutrition/providers/nutrition_notifier_test.dart index a75aec551..386d7e1c0 100644 --- a/test/features/nutrition/providers/nutrition_notifier_test.dart +++ b/test/features/nutrition/providers/nutrition_notifier_test.dart @@ -27,7 +27,7 @@ import 'package:wger/features/nutrition/providers/ingredient_repository.dart'; import 'package:wger/features/nutrition/providers/nutrition_notifier.dart'; import 'package:wger/features/nutrition/providers/nutrition_repository.dart'; -import '../../../fake_connectivity.dart'; +import '../../../helpers/fake_connectivity.dart'; import 'nutrition_notifier_test.mocks.dart'; @GenerateMocks([NutritionRepository, IngredientRepository]) diff --git a/test/features/nutrition/screens/nutritional_plan_screen_test.dart b/test/features/nutrition/screens/nutritional_plan_screen_test.dart index a307c111a..5bd2393cd 100644 --- a/test/features/nutrition/screens/nutritional_plan_screen_test.dart +++ b/test/features/nutrition/screens/nutritional_plan_screen_test.dart @@ -37,9 +37,9 @@ import 'package:wger/l10n/generated/app_localizations.dart'; import '../../../../test_data/body_weight.dart'; import '../../../../test_data/nutritional_plans.dart'; -import '../../../fake_auth_environment.dart'; -import '../../../fake_connectivity.dart'; import '../../../fixtures/fixture_reader.dart'; +import '../../../helpers/fake_auth_environment.dart'; +import '../../../helpers/fake_connectivity.dart'; import 'nutritional_plan_screen_test.mocks.dart'; @GenerateMocks([ diff --git a/test/features/nutrition/screens/nutritional_plans_screen_test.dart b/test/features/nutrition/screens/nutritional_plans_screen_test.dart index a80c78d24..4c9ab86c8 100644 --- a/test/features/nutrition/screens/nutritional_plans_screen_test.dart +++ b/test/features/nutrition/screens/nutritional_plans_screen_test.dart @@ -34,7 +34,7 @@ import 'package:wger/features/nutrition/widgets/forms.dart'; import 'package:wger/features/weight/providers/body_weight_repository.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; -import '../../../fake_connectivity.dart'; +import '../../../helpers/fake_connectivity.dart'; import 'nutritional_plans_screen_test.mocks.dart'; @GenerateMocks([ diff --git a/test/features/nutrition/widgets/ingredient_typeahead_test.dart b/test/features/nutrition/widgets/ingredient_typeahead_test.dart index 4a76cdce3..901eb93e1 100644 --- a/test/features/nutrition/widgets/ingredient_typeahead_test.dart +++ b/test/features/nutrition/widgets/ingredient_typeahead_test.dart @@ -33,7 +33,7 @@ import 'package:wger/features/nutrition/widgets/widgets.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; import '../../../../test_data/nutritional_plans.dart'; -import '../../../fake_connectivity.dart'; +import '../../../helpers/fake_connectivity.dart'; import 'ingredient_typeahead_test.mocks.dart'; @GenerateMocks([IngredientRepository]) diff --git a/test/features/nutrition/widgets/nutritional_meal_form_test.dart b/test/features/nutrition/widgets/nutritional_meal_form_test.dart index ec0046d62..712b3df0d 100644 --- a/test/features/nutrition/widgets/nutritional_meal_form_test.dart +++ b/test/features/nutrition/widgets/nutritional_meal_form_test.dart @@ -35,7 +35,7 @@ import 'package:wger/features/nutrition/widgets/forms.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; import '../../../../test_data/nutritional_plans.dart'; -import '../../../fake_connectivity.dart'; +import '../../../helpers/fake_connectivity.dart'; import 'nutritional_meal_form_test.mocks.dart'; @GenerateMocks([IngredientRepository, NutritionRepository]) diff --git a/test/features/nutrition/widgets/nutritional_meal_item_form_test.dart b/test/features/nutrition/widgets/nutritional_meal_item_form_test.dart index b7a0bed33..8b7224b32 100644 --- a/test/features/nutrition/widgets/nutritional_meal_item_form_test.dart +++ b/test/features/nutrition/widgets/nutritional_meal_item_form_test.dart @@ -43,8 +43,8 @@ import 'package:wger/features/nutrition/widgets/forms.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; import '../../../../test_data/nutritional_plans.dart'; -import '../../../fake_connectivity.dart'; import '../../../fixtures/fixture_reader.dart'; +import '../../../helpers/fake_connectivity.dart'; import 'nutritional_meal_item_form_test.mocks.dart'; @GenerateMocks([http.Client, IngredientRepository, NutritionRepository]) diff --git a/test/features/routines/providers/routines_notifier_test.dart b/test/features/routines/providers/routines_notifier_test.dart index 41697c893..b5e9e116d 100644 --- a/test/features/routines/providers/routines_notifier_test.dart +++ b/test/features/routines/providers/routines_notifier_test.dart @@ -40,7 +40,7 @@ import 'package:wger/features/routines/providers/routines_repository.dart'; import '../../../../test_data/exercises.dart'; import '../../../../test_data/routines.dart'; -import '../../../fake_connectivity.dart'; +import '../../../helpers/fake_connectivity.dart'; import '../helpers/routine_form_test_overrides.dart'; import 'routines_notifier_test.mocks.dart'; diff --git a/test/features/routines/screens/gym_mode_test.dart b/test/features/routines/screens/gym_mode_test.dart index 2d7693e87..818bb109a 100644 --- a/test/features/routines/screens/gym_mode_test.dart +++ b/test/features/routines/screens/gym_mode_test.dart @@ -54,7 +54,7 @@ import 'package:wger/l10n/generated/app_localizations.dart'; import '../../../../test_data/exercises.dart'; import '../../../../test_data/routines.dart'; -import '../../../fake_connectivity.dart'; +import '../../../helpers/fake_connectivity.dart'; import 'gym_mode_test.mocks.dart'; @GenerateMocks([ diff --git a/test/features/routines/screens/routine_screen_test.dart b/test/features/routines/screens/routine_screen_test.dart index 238074453..3a50efae1 100644 --- a/test/features/routines/screens/routine_screen_test.dart +++ b/test/features/routines/screens/routine_screen_test.dart @@ -29,7 +29,7 @@ import 'package:wger/features/routines/screens/routine_screen.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; import '../../../../test_data/routines.dart'; -import '../../../fake_auth_environment.dart'; +import '../../../helpers/fake_auth_environment.dart'; class _StubRoutinesRiverpod extends RoutinesRiverpod { _StubRoutinesRiverpod(this._routines); diff --git a/test/features/routines/widgets/forms/routine_form_test.dart b/test/features/routines/widgets/forms/routine_form_test.dart index 6b1d32f55..e728cf0f5 100644 --- a/test/features/routines/widgets/forms/routine_form_test.dart +++ b/test/features/routines/widgets/forms/routine_form_test.dart @@ -44,7 +44,7 @@ import 'package:wger/features/routines/widgets/forms/routine.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; import '../../../../../test_data/routines.dart'; -import '../../../../fake_connectivity.dart'; +import '../../../../helpers/fake_connectivity.dart'; import './routine_form_test.mocks.dart'; @GenerateMocks([ diff --git a/test/fake_auth_environment.dart b/test/helpers/fake_auth_environment.dart similarity index 100% rename from test/fake_auth_environment.dart rename to test/helpers/fake_auth_environment.dart diff --git a/test/utils.dart b/test/helpers/fake_auth_notifier.dart similarity index 53% rename from test/utils.dart rename to test/helpers/fake_auth_notifier.dart index 6a4a043b6..4f27a53b5 100644 --- a/test/utils.dart +++ b/test/helpers/fake_auth_notifier.dart @@ -1,6 +1,6 @@ /* * This file is part of wger Workout Manager . - * Copyright (c) 2026 wger Team + * Copyright (c) 2026 - 2026 wger Team * * wger Workout Manager is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -16,17 +16,19 @@ * along with this program. If not, see . */ -import 'package:http/http.dart' as http; -import 'package:wger/core/network/base_provider.dart'; +import 'package:wger/core/network/auth_notifier.dart'; +import 'package:wger/core/network/auth_state.dart'; -/// Builds a [WgerBaseProvider] pre-configured for tests with a fixed server -/// URL. Pass a mocked [http.Client] to intercept requests. Authentication is -/// the client's responsibility now, the test client is unauthenticated, so -/// tests that assert on the `Authorization` header have to stub the client -/// directly (or use a wrapped `AuthHttpClient`). -WgerBaseProvider buildTestBaseProvider({ - http.Client? client, - String serverUrl = 'https://localhost', -}) { - return WgerBaseProvider(serverUrl: serverUrl, client: client); +/// An [AuthNotifier] that resolves to a fixed state. +/// +/// Use it via `authProvider.overrideWith(() => FakeAuthNotifier(state))` in +/// widget tests instead of seeding preferences and stubbing every request the +/// real notifier makes on its eager build. +class FakeAuthNotifier extends AuthNotifier { + FakeAuthNotifier(this._state); + + final AuthState _state; + + @override + Future build() async => _state; } diff --git a/test/fake_connectivity.dart b/test/helpers/fake_connectivity.dart similarity index 100% rename from test/fake_connectivity.dart rename to test/helpers/fake_connectivity.dart diff --git a/test/screenshots/screenshots_01_dashboard.dart b/test/screenshots/screenshots_01_dashboard.dart index ed7e45792..a14937ac0 100644 --- a/test/screenshots/screenshots_01_dashboard.dart +++ b/test/screenshots/screenshots_01_dashboard.dart @@ -45,17 +45,9 @@ import '../../test_data/nutritional_plans.dart'; import '../../test_data/profile.dart'; import '../../test_data/routines.dart'; import '../../test_data/trophies.dart'; +import '../helpers/fake_auth_notifier.dart'; import 'screenshots_01_dashboard.mocks.dart'; -class _FakeAuthNotifier extends AuthNotifier { - _FakeAuthNotifier(this._state); - - final AuthState _state; - - @override - Future build() async => _state; -} - @GenerateMocks([ GalleryRepository, NutritionRepository, @@ -122,7 +114,7 @@ Widget createDashboardScreen({Locale? locale}) { overrides: [ bodyWeightRepositoryProvider.overrideWithValue(mockBodyWeightRepository), measurementRepositoryProvider.overrideWithValue(mockMeasurementRepo), - authProvider.overrideWith(() => _FakeAuthNotifier(loggedInAuth)), + authProvider.overrideWith(() => FakeAuthNotifier(loggedInAuth)), userProfileRepositoryProvider.overrideWithValue(mockUserProfileRepo), nutritionRepositoryProvider.overrideWithValue(mockNutritionRepo), ingredientRepositoryProvider.overrideWithValue(mockIngredientRepo),