fixed storage mock for integration tests

This commit is contained in:
Vadim 2024-11-08 10:12:45 +01:00
parent 5c51c284c9
commit 4ea34410a4
2 changed files with 32 additions and 34 deletions

View file

@ -58,24 +58,24 @@ void testE2E(String description) {
await tester.tapDescendantTextOf<SettingsScreen>(S.current.equipmentProfiles); await tester.tapDescendantTextOf<SettingsScreen>(S.current.equipmentProfiles);
await tester.tap(find.byIcon(Icons.add_outlined).first); await tester.tap(find.byIcon(Icons.add_outlined).first);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.selectProfileName(mockEquipmentProfiles[0].name); await tester.enterProfileName(mockEquipmentProfiles[0].name);
await tester.expandEquipmentProfileContainer(mockEquipmentProfiles[0].name); await tester.setIsoValues(mockEquipmentProfiles[0].isoValues);
await tester.setIsoValues(0, mockEquipmentProfiles[0].isoValues); await tester.setNdValues(mockEquipmentProfiles[0].ndValues);
await tester.setNdValues(0, mockEquipmentProfiles[0].ndValues); await tester.setApertureValues(mockEquipmentProfiles[0].apertureValues);
await tester.setApertureValues(0, mockEquipmentProfiles[0].apertureValues); await tester.setShutterSpeedValues(mockEquipmentProfiles[0].shutterSpeedValues);
await tester.setShutterSpeedValues(0, mockEquipmentProfiles[0].shutterSpeedValues); await tester.setZoomValue(mockEquipmentProfiles[0].lensZoom);
await tester.setZoomValue(0, mockEquipmentProfiles[0].lensZoom);
expect(find.text('x1.91'), findsOneWidget); expect(find.text('x1.91'), findsOneWidget);
expect(find.text('f/1.7 - f/16'), findsOneWidget); expect(find.text('f/1.7 - f/16'), findsOneWidget);
expect(find.text('1/1000 - B'), findsOneWidget); expect(find.text('1/1000 - B'), findsOneWidget);
await tester.tap(find.byIcon(Icons.save_outlined));
await tester.pump();
/// Create Praktica + Jupiter profile from Zenitar profile /// Create Praktica + Jupiter profile from Zenitar profile
await tester.tap(find.byIcon(Icons.copy_outlined).first); await tester.tap(find.byIcon(Icons.copy_outlined).first);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.selectProfileName(mockEquipmentProfiles[1].name); await tester.enterProfileName(mockEquipmentProfiles[1].name);
await tester.expandEquipmentProfileContainer(mockEquipmentProfiles[1].name); await tester.setApertureValues(mockEquipmentProfiles[1].apertureValues);
await tester.setApertureValues(1, mockEquipmentProfiles[1].apertureValues); await tester.setZoomValue(mockEquipmentProfiles[1].lensZoom);
await tester.setZoomValue(1, mockEquipmentProfiles[1].lensZoom);
expect(find.text('x5.02'), findsOneWidget); expect(find.text('x5.02'), findsOneWidget);
expect(find.text('f/3.5 - f/22'), findsOneWidget); expect(find.text('f/3.5 - f/22'), findsOneWidget);
expect(find.text('1/1000 - B'), findsNWidgets(2)); expect(find.text('1/1000 - B'), findsNWidgets(2));
@ -147,40 +147,31 @@ void testE2E(String description) {
} }
extension EquipmentProfileActions on WidgetTester { extension EquipmentProfileActions on WidgetTester {
Future<void> expandEquipmentProfileContainer(String name) async { Future<void> enterProfileName(String name) async {
await tap(find.text(name));
await pump(Dimens.durationM);
}
Future<void> selectProfileName(String name) async {
await enterText(find.byType(TextField), name); await enterText(find.byType(TextField), name);
await pump(); await pump();
await tapSaveButton();
} }
Future<void> setIsoValues(int profileIndex, List<IsoValue> values) => Future<void> setIsoValues(List<IsoValue> values) =>
_openAndSetDialogFilterValues<IsoValue>(profileIndex, S.current.isoValues, values); _openAndSetDialogFilterValues<IsoValue>(S.current.isoValues, values);
Future<void> setNdValues(int profileIndex, List<NdValue> values) => Future<void> setNdValues(List<NdValue> values) => _openAndSetDialogFilterValues<NdValue>(S.current.ndFilters, values);
_openAndSetDialogFilterValues<NdValue>(profileIndex, S.current.ndFilters, values);
Future<void> _openAndSetDialogFilterValues<T extends PhotographyValue>( Future<void> _openAndSetDialogFilterValues<T extends PhotographyValue>(
int profileIndex,
String listTileTitle, String listTileTitle,
List<T> valuesToSelect, { List<T> valuesToSelect, {
bool deselectAll = true, bool deselectAll = true,
}) async { }) async {
await tap(find.text(listTileTitle).at(profileIndex)); await tap(find.text(listTileTitle));
await pumpAndSettle(); await pumpAndSettle();
await setDialogFilterValues(valuesToSelect, deselectAll: deselectAll); await setDialogFilterValues(valuesToSelect, deselectAll: deselectAll);
} }
Future<void> setApertureValues(int profileIndex, List<ApertureValue> values) => Future<void> setApertureValues(List<ApertureValue> values) =>
_setDialogRangePickerValues<ApertureValue>(profileIndex, S.current.apertureValues, values); _setDialogRangePickerValues<ApertureValue>(S.current.apertureValues, values);
Future<void> setShutterSpeedValues(int profileIndex, List<ShutterSpeedValue> values) => Future<void> setShutterSpeedValues(List<ShutterSpeedValue> values) =>
_setDialogRangePickerValues<ShutterSpeedValue>(profileIndex, S.current.shutterSpeedValues, values); _setDialogRangePickerValues<ShutterSpeedValue>(S.current.shutterSpeedValues, values);
Future<void> setZoomValue(int profileIndex, double value) => Future<void> setZoomValue(double value) => _setDialogSliderPickerValue(S.current.lensZoom, value);
_setDialogSliderPickerValue(profileIndex, S.current.lensZoom, value);
} }
extension on WidgetTester { extension on WidgetTester {
@ -212,11 +203,10 @@ extension on WidgetTester {
} }
Future<void> _setDialogRangePickerValues<T extends PhotographyValue>( Future<void> _setDialogRangePickerValues<T extends PhotographyValue>(
int profileIndex,
String listTileTitle, String listTileTitle,
List<T> valuesToSelect, List<T> valuesToSelect,
) async { ) async {
await tap(find.text(listTileTitle).at(profileIndex)); await tap(find.text(listTileTitle));
await pumpAndSettle(); await pumpAndSettle();
final dialog = widget<DialogRangePicker<T>>(find.byType(DialogRangePicker<T>)); final dialog = widget<DialogRangePicker<T>>(find.byType(DialogRangePicker<T>));
@ -247,11 +237,10 @@ extension on WidgetTester {
} }
Future<void> _setDialogSliderPickerValue( Future<void> _setDialogSliderPickerValue(
int profileIndex,
String listTileTitle, String listTileTitle,
double value, double value,
) async { ) async {
await tap(find.text(listTileTitle).at(profileIndex)); await tap(find.text(listTileTitle));
await pumpAndSettle(); await pumpAndSettle();
final sliderFinder = find.byType(Slider); final sliderFinder = find.byType(Slider);

View file

@ -41,12 +41,21 @@ class _MockIAPProvidersState extends State<MockIAPProviders> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
registerFallbackValue(defaultEquipmentProfile);
mockEquipmentProfilesStorageService = _MockEquipmentProfilesStorageService(); mockEquipmentProfilesStorageService = _MockEquipmentProfilesStorageService();
when(() => mockEquipmentProfilesStorageService.init()).thenAnswer((_) async {}); when(() => mockEquipmentProfilesStorageService.init()).thenAnswer((_) async {});
when(() => mockEquipmentProfilesStorageService.getProfiles()) when(() => mockEquipmentProfilesStorageService.getProfiles())
.thenAnswer((_) => Future.value(widget.equipmentProfiles)); .thenAnswer((_) => Future.value(widget.equipmentProfiles));
when(() => mockEquipmentProfilesStorageService.selectedEquipmentProfileId) when(() => mockEquipmentProfilesStorageService.selectedEquipmentProfileId)
.thenReturn(widget.selectedEquipmentProfileId); .thenReturn(widget.selectedEquipmentProfileId);
when(() => mockEquipmentProfilesStorageService.addProfile(any<EquipmentProfile>())).thenAnswer((_) async {});
when(
() => mockEquipmentProfilesStorageService.updateProfile(
id: any<String>(named: 'id'),
name: any<String>(named: 'name'),
),
).thenAnswer((_) async {});
when(() => mockEquipmentProfilesStorageService.deleteProfile(any<String>())).thenAnswer((_) async {});
mockFilmsStorageService = _MockFilmsStorageService(); mockFilmsStorageService = _MockFilmsStorageService();
when(() => mockFilmsStorageService.init()).thenAnswer((_) async {}); when(() => mockFilmsStorageService.init()).thenAnswer((_) async {});