fixed golden tests

This commit is contained in:
Vadim 2024-10-29 14:21:26 +01:00
parent b4fffb8cc2
commit 7b9f03f46e
6 changed files with 61 additions and 18 deletions

View file

@ -45,6 +45,7 @@ class _MockIAPProvidersState extends State<MockIAPProviders> {
when(() => mockIAPStorageService.selectedEquipmentProfileId).thenReturn(widget.selectedEquipmentProfileId); when(() => mockIAPStorageService.selectedEquipmentProfileId).thenReturn(widget.selectedEquipmentProfileId);
mockFilmsStorageService = _MockFilmsStorageService(); mockFilmsStorageService = _MockFilmsStorageService();
when(() => mockFilmsStorageService.init()).thenAnswer((_) async {});
when(() => mockFilmsStorageService.getPredefinedFilms()).thenAnswer((_) => Future.value(widget.predefinedFilms)); when(() => mockFilmsStorageService.getPredefinedFilms()).thenAnswer((_) => Future.value(widget.predefinedFilms));
when(() => mockFilmsStorageService.getCustomFilms()).thenAnswer((_) => Future.value(widget.customFilms)); when(() => mockFilmsStorageService.getCustomFilms()).thenAnswer((_) => Future.value(widget.customFilms));
when(() => mockFilmsStorageService.selectedFilmId).thenReturn(widget.selectedFilmId); when(() => mockFilmsStorageService.selectedFilmId).thenReturn(widget.selectedFilmId);
@ -135,10 +136,10 @@ final mockEquipmentProfiles = [
]; ];
const mockFilms = [ const mockFilms = [
FilmMultiplying(id: '1', name: 'Mock film 1', iso: 100, reciprocityMultiplier: 2), _FilmMultiplying(id: '1', name: 'Mock film 1', iso: 100, reciprocityMultiplier: 2),
FilmMultiplying(id: '2', name: 'Mock film 2', iso: 400, reciprocityMultiplier: 2), _FilmMultiplying(id: '2', name: 'Mock film 2', iso: 400, reciprocityMultiplier: 2),
FilmMultiplying(id: '3', name: 'Mock film 3', iso: 800, reciprocityMultiplier: 3), _FilmMultiplying(id: '3', name: 'Mock film 3', iso: 800, reciprocityMultiplier: 3),
FilmMultiplying(id: '4', name: 'Mock film 4', iso: 1200, reciprocityMultiplier: 1.5), _FilmMultiplying(id: '4', name: 'Mock film 4', iso: 1200, reciprocityMultiplier: 1.5),
]; ];
extension FilmMapper on List<Film> { extension FilmMapper on List<Film> {
@ -146,15 +147,15 @@ extension FilmMapper on List<Film> {
Map.fromEntries(map((e) => MapEntry(e.id, (film: e as T, isUsed: isUsed)))); Map.fromEntries(map((e) => MapEntry(e.id, (film: e as T, isUsed: isUsed))));
} }
class FilmMultiplying extends FilmExponential { class _FilmMultiplying extends FilmExponential {
final double reciprocityMultiplier; final double reciprocityMultiplier;
const FilmMultiplying({ const _FilmMultiplying({
String? id, String? id,
required super.name, required String name,
required super.iso, required super.iso,
required this.reciprocityMultiplier, required this.reciprocityMultiplier,
}) : super(id: id ?? name, exponent: 1); }) : super(id: id ?? name, name: 'Mock film $iso x$reciprocityMultiplier', exponent: 1);
@override @override
ShutterSpeedValue reciprocityFailure(ShutterSpeedValue shutterSpeed) { ShutterSpeedValue reciprocityFailure(ShutterSpeedValue shutterSpeed) {
@ -173,7 +174,7 @@ class FilmMultiplying extends FilmExponential {
bool operator ==(Object other) { bool operator ==(Object other) {
if (identical(this, other)) return true; if (identical(this, other)) return true;
if (other.runtimeType != runtimeType) return false; if (other.runtimeType != runtimeType) return false;
return other is FilmMultiplying && return other is _FilmMultiplying &&
other.id == id && other.id == id &&
other.name == name && other.name == name &&
other.iso == iso && other.iso == iso &&

View file

@ -51,7 +51,6 @@ class ApplicationWrapper extends StatelessWidget {
permissionsService: const PermissionsService(), permissionsService: const PermissionsService(),
userPreferencesService: userPreferencesService, userPreferencesService: userPreferencesService,
volumeEventsService: const VolumeEventsService(LocalPlatform()), volumeEventsService: const VolumeEventsService(LocalPlatform()),
filmsStorageService: filmsStorageService,
child: RemoteConfigProvider( child: RemoteConfigProvider(
remoteConfigService: remoteConfigService, remoteConfigService: remoteConfigService,
child: EquipmentProfileProvider( child: EquipmentProfileProvider(

View file

@ -7,7 +7,6 @@ import 'package:lightmeter/data/permissions_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart'; import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/data/volume_events_service.dart'; import 'package:lightmeter/data/volume_events_service.dart';
import 'package:lightmeter/environment.dart'; import 'package:lightmeter/environment.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
// coverage:ignore-start // coverage:ignore-start
class ServicesProvider extends InheritedWidget { class ServicesProvider extends InheritedWidget {
@ -20,9 +19,6 @@ class ServicesProvider extends InheritedWidget {
final UserPreferencesService userPreferencesService; final UserPreferencesService userPreferencesService;
final VolumeEventsService volumeEventsService; final VolumeEventsService volumeEventsService;
// IAP
final FilmsStorageService filmsStorageService;
const ServicesProvider({ const ServicesProvider({
required this.analytics, required this.analytics,
required this.caffeineService, required this.caffeineService,
@ -32,7 +28,6 @@ class ServicesProvider extends InheritedWidget {
required this.permissionsService, required this.permissionsService,
required this.userPreferencesService, required this.userPreferencesService,
required this.volumeEventsService, required this.volumeEventsService,
required this.filmsStorageService,
required super.child, required super.child,
}); });

View file

@ -2,13 +2,25 @@ import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:light_sensor/light_sensor.dart'; import 'package:light_sensor/light_sensor.dart';
import 'package:lightmeter/application_wrapper.dart'; import 'package:lightmeter/data/analytics/analytics.dart';
import 'package:lightmeter/data/analytics/api/analytics_firebase.dart';
import 'package:lightmeter/data/caffeine_service.dart';
import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/light_sensor_service.dart';
import 'package:lightmeter/data/models/supported_locale.dart'; import 'package:lightmeter/data/models/supported_locale.dart';
import 'package:lightmeter/data/permissions_service.dart';
import 'package:lightmeter/data/remote_config_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/data/volume_events_service.dart';
import 'package:lightmeter/environment.dart'; import 'package:lightmeter/environment.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/remote_config_provider.dart';
import 'package:lightmeter/providers/services_provider.dart';
import 'package:lightmeter/providers/user_preferences_provider.dart'; import 'package:lightmeter/providers/user_preferences_provider.dart';
import 'package:lightmeter/res/theme.dart'; import 'package:lightmeter/res/theme.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:platform/platform.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../integration_test/mocks/paid_features_mock.dart'; import '../integration_test/mocks/paid_features_mock.dart';
import '../integration_test/utils/platform_channel_mock.dart'; import '../integration_test/utils/platform_channel_mock.dart';
@ -94,8 +106,7 @@ class _GoldenTestApplicationMockState extends State<GoldenTestApplicationMock> {
price: '0.0\$', price: '0.0\$',
), ),
], ],
child: ApplicationWrapper( child: _MockApplicationWrapper(
const Environment.dev(),
child: MockIAPProviders( child: MockIAPProviders(
equipmentProfiles: mockEquipmentProfiles, equipmentProfiles: mockEquipmentProfiles,
selectedEquipmentProfileId: mockEquipmentProfiles.first.id, selectedEquipmentProfileId: mockEquipmentProfiles.first.id,
@ -126,3 +137,40 @@ class _GoldenTestApplicationMockState extends State<GoldenTestApplicationMock> {
); );
} }
} }
class _MockApplicationWrapper extends StatelessWidget {
final Widget child;
const _MockApplicationWrapper({required this.child});
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: SharedPreferences.getInstance(),
builder: (_, snapshot) {
if (snapshot.data != null) {
final userPreferencesService = UserPreferencesService(snapshot.data!);
return ServicesProvider(
analytics: const LightmeterAnalytics(api: LightmeterAnalyticsFirebase()),
caffeineService: const CaffeineService(),
environment: const Environment.dev().copyWith(hasLightSensor: true),
hapticsService: const HapticsService(),
lightSensorService: const LightSensorService(LocalPlatform()),
permissionsService: const PermissionsService(),
userPreferencesService: userPreferencesService,
volumeEventsService: const VolumeEventsService(LocalPlatform()),
child: RemoteConfigProvider(
remoteConfigService: const MockRemoteConfigService(),
child: UserPreferencesProvider(
hasLightSensor: true,
userPreferencesService: userPreferencesService,
child: child,
),
),
);
}
return const SizedBox();
},
);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 301 KiB

After

Width:  |  Height:  |  Size: 301 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 499 KiB

After

Width:  |  Height:  |  Size: 494 KiB