diff --git a/integration_test/logbook_test.dart b/integration_test/logbook_test.dart index 546d2c7..b0465b6 100644 --- a/integration_test/logbook_test.dart +++ b/integration_test/logbook_test.dart @@ -63,23 +63,13 @@ void testLogbook(String description) { await tester.pumpAndSettle(); await tester.openPickerAndSelect(S.current.apertureValue, 'f/5.6'); await tester.openPickerAndSelect(S.current.shutterSpeedValue, '1/125'); - expect( - find.descendant( - of: find.byWidgetPredicate( - (widget) => widget is PickerListTile && widget.title == S.current.equipmentProfile, - ), - matching: find.text(mockEquipmentProfiles.first.name), - ), - findsOneWidget, + _expectPickerListTileValue( + S.current.equipmentProfile, + mockEquipmentProfiles.first.name, ); - expect( - find.descendant( - of: find.byWidgetPredicate( - (widget) => widget is PickerListTile && widget.title == S.current.film, - ), - matching: find.text(mockFilms.first.name), - ), - findsOneWidget, + _expectPickerListTileValue( + S.current.film, + mockFilms.first.name, ); await tester.openPickerAndSelect(S.current.film, S.current.notSet); await tester.pumpAndSettle(); @@ -117,14 +107,9 @@ void testLogbook(String description) { await tester.pumpAndSettle(); /// Verify the edits were saved - expect( - find.descendant( - of: find.byWidgetPredicate( - (widget) => widget is PickerListTile && widget.title == S.current.equipmentProfile, - ), - matching: find.text(S.current.notSet), - ), - findsOneWidget, + _expectPickerListTileValue( + S.current.equipmentProfile, + S.current.notSet, ); expect(find.text('Test note'), findsOneWidget); expect(find.text('f/5.6'), findsOneWidget); @@ -141,6 +126,138 @@ void testLogbook(String description) { ); } +@isTest +void testLogbookEquipmentProfileChanges(String description) { + setUp(() async { + SharedPreferences.setMockInitialValues({ + UserPreferencesService.evSourceTypeKey: EvSourceType.camera.index, + UserPreferencesService.seenChangelogVersionKey: await const PlatformUtils().version, + }); + }); + + testWidgets( + description, + (tester) async { + await tester.pumpApplication( + selectedEquipmentProfileId: mockEquipmentProfiles.first.id, + selectedFilmId: mockFilms.first.id, + customFilms: {}, + ); + await tester.takePhoto(); + await tester.openSettings(); + await tester.tapDescendantTextOf(S.current.logbook); + await tester.tap(find.byType(LogbookPhotoGridTile).first); + await tester.pumpAndSettle(); + + await tester.ensureVisible(find.text(mockEquipmentProfiles.first.name)); + _expectPickerListTileValue( + S.current.equipmentProfile, + mockEquipmentProfiles.first.name, + ); + + await tester.openPickerAndSelect(S.current.equipmentProfile, mockEquipmentProfiles[1].name); + await tester.pumpAndSettle(); + _expectPickerListTileValue( + S.current.equipmentProfile, + mockEquipmentProfiles[1].name, + ); + + await tester.openPickerAndSelect( + S.current.equipmentProfile, + mockPinholeEquipmentProfiles.first.name, + ); + await tester.pumpAndSettle(); + _expectPickerListTileValue( + S.current.equipmentProfile, + mockPinholeEquipmentProfiles.first.name, + ); + _expectPickerListTileValue( + S.current.apertureValue, + 'f/${mockPinholeEquipmentProfiles.first.aperture}', + reason: 'Aperture value must be automatically set when selecting a pinhole profile', + ); + + final aperturePickerFinder = find.descendant( + of: find.byWidgetPredicate( + (widget) => widget is PickerListTile && widget.title == S.current.apertureValue, + ), + matching: find.byType(PickerListTile), + ); + expect(aperturePickerFinder, findsOneWidget); + await tester.tap(aperturePickerFinder); + await tester.pumpAndSettle(); + expect( + find.byType(DialogPicker>), + findsNothing, + reason: 'Aperture picker dialog must not open when pinhole profile is selected', + ); + + await tester.openPickerAndSelect( + S.current.equipmentProfile, + mockPinholeEquipmentProfiles[1].name, + ); + await tester.pumpAndSettle(); + _expectPickerListTileValue( + S.current.equipmentProfile, + mockPinholeEquipmentProfiles[1].name, + ); + + _expectPickerListTileValue( + S.current.apertureValue, + 'f/${mockPinholeEquipmentProfiles[1].aperture}', + reason: 'Aperture value must be updated when switching to a different pinhole profile', + ); + + await tester.tap(aperturePickerFinder); + await tester.pumpAndSettle(); + expect( + find.byType(DialogPicker>), + findsNothing, + reason: 'Aperture picker dialog must not open when switching between pinhole profiles', + ); + + await tester.openPickerAndSelect(S.current.equipmentProfile, mockEquipmentProfiles.first.name); + await tester.pumpAndSettle(); + _expectPickerListTileValue( + S.current.equipmentProfile, + mockEquipmentProfiles.first.name, + ); + _expectPickerListTileValue( + S.current.apertureValue, + S.current.notSet, + reason: 'Aperture value must be cleared when switching from pinhole to regular profile', + ); + + await tester.tap(aperturePickerFinder); + await tester.pumpAndSettle(); + expect( + find.byType(DialogPicker>), + findsOneWidget, + reason: 'Aperture picker dialog must open when regular profile is selected', + ); + await tester.tap(find.text('Cancel')); + await tester.pumpAndSettle(); + + await tester.openPickerAndSelect(S.current.equipmentProfile, S.current.notSet); + await tester.pumpAndSettle(); + _expectPickerListTileValue( + S.current.equipmentProfile, + S.current.notSet, + ); + + await tester.tap(find.byIcon(Icons.save_outlined)); + await tester.pumpAndSettle(); + + await tester.tap(find.byType(LogbookPhotoGridTile).first); + await tester.pumpAndSettle(); + _expectPickerListTileValue( + S.current.equipmentProfile, + S.current.notSet, + ); + }, + ); +} + extension on WidgetTester { Future openPickerAndSelect(String title, String valueToSelect) async { await tap(find.text(title)); @@ -156,3 +273,16 @@ extension on WidgetTester { await tapSelectButton(); } } + +void _expectPickerListTileValue(String title, String value, {String? reason}) { + expect( + find.descendant( + of: find.byWidgetPredicate( + (widget) => widget is PickerListTile && widget.title == title, + ), + matching: find.text(value), + ), + findsOneWidget, + reason: reason, + ); +} diff --git a/integration_test/run_all_tests.dart b/integration_test/run_all_tests.dart index 718a565..663b613 100644 --- a/integration_test/run_all_tests.dart +++ b/integration_test/run_all_tests.dart @@ -19,9 +19,10 @@ void main() { mockCameraFocalLength(); }); - testPurchases('Purchase & refund premium features'); - testGuardProTap('Guard Pro tap'); - testToggleLayoutFeatures('Toggle metering screen layout features'); - testLogbook('Logbook'); - testE2E('e2e'); + testPurchases('Purchase & refund premium features test'); + testGuardProTap('Guard Pro tap test'); + testToggleLayoutFeatures('Toggle metering screen layout features test'); + testLogbook('Logbook test'); + testLogbookEquipmentProfileChanges('Logbook equipment profile changes test'); + testE2E('e2e test'); }