From 4498167ddc902fe834907b95fb4387d95ee48dd5 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Sun, 6 Oct 2024 20:26:40 +0200 Subject: [PATCH] sync with resources --- iap/lib/src/data/iap_storage_service.dart | 2 +- .../mocks/paid_features_mock.dart | 18 ++++---- .../utils/widget_tester_actions.dart | 2 +- lib/providers/films_provider.dart | 16 ++++---- .../film_picker/widget_picker_film.dart | 2 +- ...dget_list_tile_metering_screen_layout.dart | 2 +- screenshots/generate_screenshots.dart | 2 +- test/providers/films_provider_test.dart | 41 ++++++------------- ...extreme_exposure_pairs_container_test.dart | 6 +-- .../readings_container/film_picker_test.dart | 10 ++--- 10 files changed, 40 insertions(+), 61 deletions(-) diff --git a/iap/lib/src/data/iap_storage_service.dart b/iap/lib/src/data/iap_storage_service.dart index f62f622..9bc58d0 100644 --- a/iap/lib/src/data/iap_storage_service.dart +++ b/iap/lib/src/data/iap_storage_service.dart @@ -9,7 +9,7 @@ class IAPStorageService { List get equipmentProfiles => []; set equipmentProfiles(List profiles) {} - Film get selectedFilm => const Film.other(); + Film get selectedFilm => const FilmStub(); set selectedFilm(Film value) {} List get filmsInUse => []; diff --git a/integration_test/mocks/paid_features_mock.dart b/integration_test/mocks/paid_features_mock.dart index 34e8fb0..161a338 100644 --- a/integration_test/mocks/paid_features_mock.dart +++ b/integration_test/mocks/paid_features_mock.dart @@ -20,7 +20,7 @@ class MockIAPProviders extends StatefulWidget { this.selectedEquipmentProfileId = '', List? availableFilms, List? filmsInUse, - this.selectedFilm = const Film.other(), + this.selectedFilm = const FilmStub(), required this.child, super.key, }) : availableFilms = availableFilms ?? mockFilms, @@ -128,13 +128,9 @@ final mockEquipmentProfiles = [ ), ]; -const mockFilms = [_MockFilm(100, 2), _MockFilm(400, 2), _MockFilm(3, 800), _MockFilm(400, 1.5)]; - -class _MockFilm extends Film { - final double reciprocityMultiplier; - - const _MockFilm(int iso, this.reciprocityMultiplier) : super('Mock film $iso x$reciprocityMultiplier', iso); - - @override - double reciprocityFormula(double t) => t * reciprocityMultiplier; -} +const mockFilms = [ + FilmExponential(id: '1', name: 'Mock film 1', iso: 100, exponent: 1.34), + FilmExponential(id: '2', name: 'Mock film 2', iso: 400, exponent: 1.34), + FilmExponential(id: '3', name: 'Mock film 3', iso: 800, exponent: 1.34), + FilmExponential(id: '4', name: 'Mock film 4', iso: 1200, exponent: 1.34), +]; diff --git a/integration_test/utils/widget_tester_actions.dart b/integration_test/utils/widget_tester_actions.dart index 8515c1d..de58c29 100644 --- a/integration_test/utils/widget_tester_actions.dart +++ b/integration_test/utils/widget_tester_actions.dart @@ -24,7 +24,7 @@ extension WidgetTesterCommonActions on WidgetTester { String selectedEquipmentProfileId = '', List? availableFilms, List? filmsInUse, - Film selectedFilm = const Film.other(), + Film selectedFilm = const FilmStub(), }) async { await pumpWidget( MockIAPProductsProvider( diff --git a/lib/providers/films_provider.dart b/lib/providers/films_provider.dart index 3e9d02d..d378ee6 100644 --- a/lib/providers/films_provider.dart +++ b/lib/providers/films_provider.dart @@ -40,14 +40,14 @@ class FilmsProviderState extends State { Widget build(BuildContext context) { return Films( values: [ - const Film.other(), + const FilmStub(), ...widget.availableFilms ?? films, ], filmsInUse: [ - const Film.other(), + const FilmStub(), if (context.isPro) ..._filmsInUse, ], - selected: context.isPro ? _selected : const Film.other(), + selected: context.isPro ? _selected : const FilmStub(), child: widget.child, ); } @@ -68,9 +68,9 @@ class FilmsProviderState extends State { } void _discardSelectedIfNotIncluded() { - if (_selected != const Film.other() && !_filmsInUse.contains(_selected)) { - _selected = const Film.other(); - widget.storageService.selectedFilm = const Film.other(); + if (_selected != const FilmStub() && !_filmsInUse.contains(_selected)) { + _selected = const FilmStub(); + widget.storageService.selectedFilm = const FilmStub(); } } } @@ -86,12 +86,12 @@ class Films extends SelectableInheritedModel { required super.child, }); - /// [Film.other()] + all the custom fields with actual reciprocity formulas + /// [FilmStub()] + all the custom fields with actual reciprocity formulas static List of(BuildContext context) { return InheritedModel.inheritFrom(context)!.values; } - /// [Film.other()] + films in use selected by user + /// [FilmStub()] + films in use selected by user static List inUseOf(BuildContext context) { return InheritedModel.inheritFrom( context, diff --git a/lib/screens/metering/components/shared/readings_container/components/film_picker/widget_picker_film.dart b/lib/screens/metering/components/shared/readings_container/components/film_picker/widget_picker_film.dart index 6c6ccf1..b4af640 100644 --- a/lib/screens/metering/components/shared/readings_container/components/film_picker/widget_picker_film.dart +++ b/lib/screens/metering/components/shared/readings_container/components/film_picker/widget_picker_film.dart @@ -30,7 +30,7 @@ class FilmPicker extends StatelessWidget { } String _label(BuildContext context) { - if (Films.selectedOf(context) == const Film.other() || Films.selectedOf(context).iso == selectedIso.value) { + if (Films.selectedOf(context) == const FilmStub() || Films.selectedOf(context).iso == selectedIso.value) { return S.of(context).film; } diff --git a/lib/screens/settings/components/metering/components/metering_screen_layout/widget_list_tile_metering_screen_layout.dart b/lib/screens/settings/components/metering/components/metering_screen_layout/widget_list_tile_metering_screen_layout.dart index 9dfb026..242b5e4 100644 --- a/lib/screens/settings/components/metering/components/metering_screen_layout/widget_list_tile_metering_screen_layout.dart +++ b/lib/screens/settings/components/metering/components/metering_screen_layout/widget_list_tile_metering_screen_layout.dart @@ -39,7 +39,7 @@ class MeteringScreenLayoutListTile extends StatelessWidget { EquipmentProfileProvider.of(context).setProfile(EquipmentProfiles.of(context).first); } if (!value[MeteringScreenLayoutFeature.filmPicker]!) { - FilmsProvider.of(context).setFilm(const Film.other()); + FilmsProvider.of(context).setFilm(const FilmStub()); } UserPreferencesProvider.of(context).setMeteringScreenLayout(value); }, diff --git a/screenshots/generate_screenshots.dart b/screenshots/generate_screenshots.dart index 13aa98d..dd89d77 100644 --- a/screenshots/generate_screenshots.dart +++ b/screenshots/generate_screenshots.dart @@ -32,7 +32,7 @@ import 'models/screenshot_args.dart'; //https://stackoverflow.com/a/67186625/13167574 -const _mockFilm = Film('Ilford HP5+', 400); +const _mockFilm = FilmExponential(id: '1', name: 'Ilford HP5+', iso: 400, exponent: 1.34); final Color _lightThemeColor = primaryColorsList[5]; final Color _darkThemeColor = primaryColorsList[3]; final ThemeData _themeLight = themeFrom(_lightThemeColor, Brightness.light); diff --git a/test/providers/films_provider_test.dart b/test/providers/films_provider_test.dart index f898579..66c6908 100644 --- a/test/providers/films_provider_test.dart +++ b/test/providers/films_provider_test.dart @@ -96,7 +96,7 @@ void main() { testWidgets( 'Select films in use', (tester) async { - when(() => mockIAPStorageService.selectedFilm).thenReturn(const Film.other()); + when(() => mockIAPStorageService.selectedFilm).thenReturn(const FilmStub()); when(() => mockIAPStorageService.filmsInUse).thenReturn([]); /// Init @@ -113,14 +113,14 @@ void main() { expectSelectedFilmName(''); verify(() => mockIAPStorageService.filmsInUse = mockFilms.skip(0).toList()).called(1); - verifyNever(() => mockIAPStorageService.selectedFilm = const Film.other()); + verifyNever(() => mockIAPStorageService.selectedFilm = const FilmStub()); }, ); testWidgets( 'Select film', (tester) async { - when(() => mockIAPStorageService.selectedFilm).thenReturn(const Film.other()); + when(() => mockIAPStorageService.selectedFilm).thenReturn(const FilmStub()); when(() => mockIAPStorageService.filmsInUse).thenReturn(mockFilms); /// Init @@ -156,14 +156,14 @@ void main() { expectSelectedFilmName(''); verifyNever(() => mockIAPStorageService.filmsInUse = any>()); - verify(() => mockIAPStorageService.selectedFilm = const Film.other()).called(1); + verify(() => mockIAPStorageService.selectedFilm = const FilmStub()).called(1); }, ); testWidgets( 'None film selected', (tester) async { - when(() => mockIAPStorageService.selectedFilm).thenReturn(const Film.other()); + when(() => mockIAPStorageService.selectedFilm).thenReturn(const FilmStub()); when(() => mockIAPStorageService.filmsInUse).thenReturn([]); /// Init @@ -172,7 +172,7 @@ void main() { expectSelectedFilmName(''); verifyNever(() => mockIAPStorageService.filmsInUse = any>()); - verifyNever(() => mockIAPStorageService.selectedFilm = const Film.other()); + verifyNever(() => mockIAPStorageService.selectedFilm = const FilmStub()); }, ); }, @@ -198,7 +198,7 @@ void main() { expectSelectedFilmName(''); verify(() => mockIAPStorageService.filmsInUse = mockFilms.skip(1).toList()).called(1); - verify(() => mockIAPStorageService.selectedFilm = const Film.other()).called(1); + verify(() => mockIAPStorageService.selectedFilm = const FilmStub()).called(1); }, ); }, @@ -252,25 +252,8 @@ class _Application extends StatelessWidget { } } -const mockFilms = [_MockFilm2x(), _MockFilm3x(), _MockFilm4x()]; - -class _MockFilm2x extends Film { - const _MockFilm2x() : super('Mock film 2x', 400); - - @override - double reciprocityFormula(double t) => t * 2; -} - -class _MockFilm3x extends Film { - const _MockFilm3x() : super('Mock film 3x', 800); - - @override - double reciprocityFormula(double t) => t * 3; -} - -class _MockFilm4x extends Film { - const _MockFilm4x() : super('Mock film 4x', 1600); - - @override - double reciprocityFormula(double t) => t * 4; -} +const mockFilms = [ + FilmExponential(id: '1', name: 'Mock film 2x', iso: 400, exponent: 1.34), + FilmExponential(id: '2', name: 'Mock film 3x', iso: 800, exponent: 1.34), + FilmExponential(id: '3', name: 'Mock film 4x', iso: 1200, exponent: 1.34), +]; diff --git a/test/screens/metering/components/shared/readings_container/extreme_exposure_pairs_container_test.dart b/test/screens/metering/components/shared/readings_container/extreme_exposure_pairs_container_test.dart index ef95e1d..7d79c1f 100644 --- a/test/screens/metering/components/shared/readings_container/extreme_exposure_pairs_container_test.dart +++ b/test/screens/metering/components/shared/readings_container/extreme_exposure_pairs_container_test.dart @@ -50,9 +50,9 @@ extension WidgetTesterActions on WidgetTester { }) async { await pumpWidget( Films( - values: const [Film.other()], - filmsInUse: const [Film.other()], - selected: const Film.other(), + values: const [FilmStub()], + filmsInUse: const [FilmStub()], + selected: const FilmStub(), child: WidgetTestApplicationMock( child: Row( children: [ diff --git a/test/screens/metering/components/shared/readings_container/film_picker_test.dart b/test/screens/metering/components/shared/readings_container/film_picker_test.dart index 765ca51..afd8a2f 100644 --- a/test/screens/metering/components/shared/readings_container/film_picker_test.dart +++ b/test/screens/metering/components/shared/readings_container/film_picker_test.dart @@ -51,7 +51,7 @@ void main() { testWidgets( 'Film.other()', (tester) async { - when(() => mockIAPStorageService.selectedFilm).thenReturn(const Film.other()); + when(() => mockIAPStorageService.selectedFilm).thenReturn(const FilmStub()); await pumpApplication(tester); expectReadingValueContainerText(S.current.film); expectReadingValueContainerText(S.current.none); @@ -104,8 +104,8 @@ void main() { } const _films = [ - Film('ISO 100 Film', 100), - Film('ISO 400 Film', 400), - Film('ISO 800 Film', 800), - Film('ISO 1600 Film', 1600), + FilmExponential(id: '', name: 'ISO 100 Film', iso: 100, exponent: 1.34), + FilmExponential(id: '', name: 'ISO 400 Film', iso: 400, exponent: 1.34), + FilmExponential(id: '', name: 'ISO 800 Film', iso: 800, exponent: 1.34), + FilmExponential(id: '', name: 'ISO 1600 Film', iso: 1600, exponent: 1.34), ];