expanded logbook tests

This commit is contained in:
Vadim 2025-09-09 08:50:41 +02:00
parent 56ab8aa85a
commit 7b46d4342c
2 changed files with 160 additions and 29 deletions

View file

@ -63,23 +63,13 @@ void testLogbook(String description) {
await tester.pumpAndSettle();
await tester.openPickerAndSelect<ApertureValue>(S.current.apertureValue, 'f/5.6');
await tester.openPickerAndSelect<ShutterSpeedValue>(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<Film>(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<SettingsScreen>(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<IEquipmentProfile>(S.current.equipmentProfile, mockEquipmentProfiles[1].name);
await tester.pumpAndSettle();
_expectPickerListTileValue(
S.current.equipmentProfile,
mockEquipmentProfiles[1].name,
);
await tester.openPickerAndSelect<IEquipmentProfile>(
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<Optional<ApertureValue>>),
findsNothing,
reason: 'Aperture picker dialog must not open when pinhole profile is selected',
);
await tester.openPickerAndSelect<IEquipmentProfile>(
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<Optional<ApertureValue>>),
findsNothing,
reason: 'Aperture picker dialog must not open when switching between pinhole profiles',
);
await tester.openPickerAndSelect<IEquipmentProfile>(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<Optional<ApertureValue>>),
findsOneWidget,
reason: 'Aperture picker dialog must open when regular profile is selected',
);
await tester.tap(find.text('Cancel'));
await tester.pumpAndSettle();
await tester.openPickerAndSelect<IEquipmentProfile>(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<void> openPickerAndSelect<V>(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,
);
}

View file

@ -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');
}