Compare commits

...

4 commits

Author SHA1 Message Date
Vadim
24804a119e FilmPicker integration tests 2023-10-17 17:39:11 +02:00
Vadim
387d875038 extracted common values 2023-10-17 17:14:10 +02:00
Vadim
5e8f02afb2 fixed metering screen tests 2023-10-17 17:01:11 +02:00
Vadim
0e5762b88e unified granting camera permission on Android 2023-10-17 16:52:57 +02:00
10 changed files with 282 additions and 263 deletions

View file

@ -136,13 +136,6 @@ extension on WidgetTester {
await pumpAndSettle();
}
Future<void> takePhoto() async {
await tap(find.byType(MeteringMeasureButton));
await pump(const Duration(seconds: 2)); // wait for circular progress indicator
await pump(const Duration(seconds: 1)); // wait for circular progress indicator
await pumpAndSettle();
}
Future<void> tapListTile(String title) async {
final listTile = find.byWidgetPredicate(
(widget) => widget is ListTile && widget.title is Text && (widget.title as Text?)?.data == title,

View file

@ -1,24 +1,15 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:lightmeter/application.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/ev_source_type.dart';
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
import 'package:lightmeter/data/models/supported_locale.dart';
import 'package:lightmeter/data/models/theme_type.dart';
import 'package:lightmeter/data/models/volume_action.dart';
import 'package:lightmeter/data/permissions_service.dart';
import 'package:lightmeter/data/models/exposure_pair.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/generated/l10n.dart';
import 'package:lightmeter/providers/services_provider.dart';
import 'package:lightmeter/providers/user_preferences_provider.dart';
import 'package:lightmeter/res/theme.dart';
import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.dart';
import 'package:lightmeter/screens/metering/components/camera_container/widget_container_camera.dart';
import 'package:lightmeter/screens/metering/components/light_sensor_container/widget_container_light_sensor.dart';
import 'package:lightmeter/screens/metering/components/shared/exposure_pairs_list/widget_list_exposure_pairs.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/extreme_exposure_pairs_container/widget_container_extreme_exposure_pairs.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/film_picker/widget_picker_film.dart';
@ -29,154 +20,115 @@ import 'package:lightmeter/screens/metering/screen_metering.dart';
import 'package:lightmeter/screens/shared/icon_placeholder/widget_icon_placeholder.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:mocktail/mocktail.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'mocks/paid_features_mock.dart';
import 'utils/expectations.dart';
import 'utils/platform_channel_mock.dart';
import 'utils/widget_tester_actions.dart';
class _MockUserPreferencesService extends Mock implements UserPreferencesService {}
class _MockCaffeineService extends Mock implements CaffeineService {}
class _MockHapticsService extends Mock implements HapticsService {}
class _MockPermissionsService extends Mock implements PermissionsService {}
class _MockLightSensorService extends Mock implements LightSensorService {}
class _MockVolumeEventsService extends Mock implements VolumeEventsService {}
const _defaultIsoValue = IsoValue(400, StopType.full);
const defaultIsoValue = IsoValue(100, StopType.full);
const mockPhotoEv100 = 8.3;
const mockPhotoFastestAperture = ApertureValue(1, StopType.full);
const mockPhotoSlowestAperture = ApertureValue(45, StopType.full);
const mockPhotoFastestShutterSpeed = ShutterSpeedValue(320, true, StopType.third);
const mockPhotoSlowestShutterSpeed = ShutterSpeedValue(6, false, StopType.third);
const mockPhotoFastestExposurePair = ExposurePair(mockPhotoFastestAperture, mockPhotoFastestShutterSpeed);
const mockPhotoSlowestExposurePair = ExposurePair(mockPhotoSlowestAperture, mockPhotoSlowestShutterSpeed);
//https://stackoverflow.com/a/67186625/13167574
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
late _MockUserPreferencesService mockUserPreferencesService;
late _MockCaffeineService mockCaffeineService;
late _MockHapticsService mockHapticsService;
late _MockPermissionsService mockPermissionsService;
late _MockLightSensorService mockLightSensorService;
late _MockVolumeEventsService mockVolumeEventsService;
group(
'[Light sensor availability]',
() {
testWidgets(
'Android - has sensor',
(tester) async {
SharedPreferences.setMockInitialValues({UserPreferencesService.evSourceTypeKey: EvSourceType.sensor.index});
setLightSensorAvilability(hasSensor: true);
await tester.pumpApplication(productStatus: IAPProductStatus.purchasable);
setUpAll(() {
mockUserPreferencesService = _MockUserPreferencesService();
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.sensor);
when(() => mockUserPreferencesService.stopType).thenReturn(StopType.third);
when(() => mockUserPreferencesService.locale).thenReturn(SupportedLocale.en);
when(() => mockUserPreferencesService.caffeine).thenReturn(true);
when(() => mockUserPreferencesService.volumeAction).thenReturn(VolumeAction.shutter);
when(() => mockUserPreferencesService.cameraEvCalibration).thenReturn(0.0);
when(() => mockUserPreferencesService.lightSensorEvCalibration).thenReturn(0.0);
when(() => mockUserPreferencesService.iso).thenReturn(_defaultIsoValue);
when(() => mockUserPreferencesService.ndFilter).thenReturn(NdValue.values.first);
when(() => mockUserPreferencesService.haptics).thenReturn(true);
when(() => mockUserPreferencesService.meteringScreenLayout).thenReturn({
MeteringScreenLayoutFeature.equipmentProfiles: true,
MeteringScreenLayoutFeature.extremeExposurePairs: true,
MeteringScreenLayoutFeature.filmPicker: true,
MeteringScreenLayoutFeature.histogram: false,
});
when(() => mockUserPreferencesService.themeType).thenReturn(ThemeType.light);
when(() => mockUserPreferencesService.primaryColor).thenReturn(primaryColorsList[5]);
when(() => mockUserPreferencesService.dynamicColor).thenReturn(false);
/// Verify that [LightSensorContainer] is shown in correspondance with the saved ev source
expect(find.byType(LightSensorContainer), findsOneWidget);
},
skip: Platform.isIOS,
);
mockCaffeineService = _MockCaffeineService();
when(() => mockCaffeineService.isKeepScreenOn()).thenAnswer((_) async => false);
when(() => mockCaffeineService.keepScreenOn(true)).thenAnswer((_) async => true);
when(() => mockCaffeineService.keepScreenOn(false)).thenAnswer((_) async => false);
testWidgets(
'Android - no sensor',
(tester) async {
SharedPreferences.setMockInitialValues({UserPreferencesService.evSourceTypeKey: EvSourceType.sensor.index});
setLightSensorAvilability(hasSensor: false);
await tester.pumpApplication(productStatus: IAPProductStatus.purchasable);
mockHapticsService = _MockHapticsService();
when(() => mockHapticsService.quickVibration()).thenAnswer((_) async {});
when(() => mockHapticsService.responseVibration()).thenAnswer((_) async {});
when(() => mockHapticsService.errorVibration()).thenAnswer((_) async {});
/// Verify that [CameraContainer] is shown instead of [LightSensorContainer]
expect(find.byType(CameraContainer), findsOneWidget);
mockPermissionsService = _MockPermissionsService();
when(() => mockPermissionsService.requestCameraPermission()).thenAnswer((_) async => PermissionStatus.granted);
when(() => mockPermissionsService.checkCameraPermission()).thenAnswer((_) async => PermissionStatus.granted);
/// and there is no ability to switch to the incident metering
expect(find.byTooltip(S.current.tooltipUseLightSensor), findsNothing);
},
skip: Platform.isIOS,
);
mockLightSensorService = _MockLightSensorService();
when(() => mockLightSensorService.hasSensor()).thenAnswer((_) async => true);
when(() => mockLightSensorService.luxStream()).thenAnswer((_) => Stream.fromIterable([100]));
testWidgets(
'iOS - no sensor',
(tester) async {
SharedPreferences.setMockInitialValues({UserPreferencesService.evSourceTypeKey: EvSourceType.sensor.index});
await tester.pumpApplication(productStatus: IAPProductStatus.purchasable);
mockVolumeEventsService = _MockVolumeEventsService();
when(() => mockVolumeEventsService.setVolumeHandling(true)).thenAnswer((_) async => true);
when(() => mockVolumeEventsService.setVolumeHandling(false)).thenAnswer((_) async => false);
when(() => mockVolumeEventsService.volumeButtonsEventStream()).thenAnswer((_) => const Stream<int>.empty());
/// verify no button to switch to the incident light mode
expect(find.byType(CameraContainer), findsOneWidget);
when(() => mockHapticsService.quickVibration()).thenAnswer((_) async {});
when(() => mockHapticsService.responseVibration()).thenAnswer((_) async {});
});
Future<void> pumpApplication(
WidgetTester tester,
IAPProductStatus purchaseStatus, {
String selectedEquipmentProfileId = '',
Film selectedFilm = const Film.other(),
}) async {
await tester.pumpWidget(
MockIAPProviders(
purchaseStatus: purchaseStatus,
selectedEquipmentProfileId: selectedEquipmentProfileId,
selectedFilm: selectedFilm,
child: ServicesProvider(
environment: const Environment.prod().copyWith(hasLightSensor: true),
userPreferencesService: mockUserPreferencesService,
caffeineService: mockCaffeineService,
hapticsService: mockHapticsService,
permissionsService: mockPermissionsService,
lightSensorService: mockLightSensorService,
volumeEventsService: mockVolumeEventsService,
child: const UserPreferencesProvider(
child: Application(),
),
),
),
);
await tester.pumpAndSettle();
}
/// and there is no ability to switch to the incident metering
expect(find.byTooltip(S.current.tooltipUseLightSensor), findsNothing);
},
skip: Platform.isAndroid,
);
},
);
group(
'Match extreme exposure pairs & pairs list edge values',
'[Match extreme exposure pairs & pairs list edge values]',
() {
Future<List<ExposurePair>> scrollToTheLastExposurePair(WidgetTester tester) async {
final exposurePairs = MeteringContainerBuidler.buildExposureValues(
mockPhotoEv100,
StopType.third,
defaultEquipmentProfile,
);
await tester.scrollUntilVisible(
find.byWidgetPredicate((widget) => widget is Row && widget.key == ValueKey(exposurePairs.length - 1)),
56,
scrollable: find.descendant(of: find.byType(ExposurePairsList), matching: find.byType(Scrollable)),
);
return exposurePairs;
}
void expectExposurePairsListItem(int index, String aperture, String shutterSpeed) {
final firstPairRow = find.byWidgetPredicate(
(widget) => widget is Row && widget.key == ValueKey(index),
);
expect(
find.descendant(of: firstPairRow, matching: find.text(aperture)),
findsOneWidget,
);
expect(
find.descendant(of: firstPairRow, matching: find.text(shutterSpeed)),
findsOneWidget,
);
final firstPairRow = find.byWidgetPredicate((widget) => widget is Row && widget.key == ValueKey(index));
expect(find.descendant(of: firstPairRow, matching: find.text(aperture)), findsOneWidget);
expect(find.descendant(of: firstPairRow, matching: find.text(shutterSpeed)), findsOneWidget);
}
setUpAll(() {
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.sensor);
when(() => mockLightSensorService.luxStream()).thenAnswer((_) => Stream.fromIterable([100]));
SharedPreferences.setMockInitialValues({UserPreferencesService.evSourceTypeKey: EvSourceType.camera.index});
});
testWidgets(
'No exposure pairs',
(tester) async {
await pumpApplication(tester, IAPProductStatus.purchasable);
await tester.pumpApplication(productStatus: IAPProductStatus.purchasable);
/// Verify that no exposure pairs are shown in [ExtremeExposurePairsContainer]
final pickerFinder = find.byType(ExtremeExposurePairsContainer);
expect(pickerFinder, findsOneWidget);
expect(
find.descendant(of: pickerFinder, matching: find.text(S.current.fastestExposurePair)),
findsOneWidget,
);
expect(
find.descendant(of: pickerFinder, matching: find.text(S.current.slowestExposurePair)),
findsOneWidget,
);
expect(find.descendant(of: pickerFinder, matching: find.text(S.current.fastestExposurePair)), findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text(S.current.slowestExposurePair)), findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text('-')), findsNWidgets(2));
/// Verify that the exposure pairs list is empty
expect(
find.descendant(
of: find.byType(ExposurePairsList),
@ -195,88 +147,106 @@ void main() {
testWidgets(
'Multiple exposure pairs w/o reciprocity',
(tester) async {
await pumpApplication(tester, IAPProductStatus.purchasable);
await tester.toggleIncidentMetering();
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"');
expectExposurePairsListItem(0, 'f/1.0', '1/160');
expectMeasureButton(7.3);
await tester.pumpApplication(productStatus: IAPProductStatus.purchasable);
await tester.takePhoto();
final exposurePairs = MeteringContainerBuidler.buildExposureValues(
7.3,
StopType.third,
defaultEquipmentProfile,
);
await tester.scrollUntilVisible(
find.byWidgetPredicate(
(widget) => widget is Row && widget.key == ValueKey(exposurePairs.length - 1),
),
56,
scrollable: find.descendant(
of: find.byType(ExposurePairsList),
matching: find.byType(Scrollable),
),
);
expectExposurePairsListItem(exposurePairs.length - 1, 'f/45', '13"');
expectMeasureButton(7.3);
/// Verify that reciprocity is not applied to the slowest exposure pair in the container
expectExposurePairsContainer('$mockPhotoFastestAperture - 1/320', '$mockPhotoSlowestAperture - 6"');
expectMeasureButton(mockPhotoEv100);
/// Verify that reciprocity is not applied to the slowest exposure pair in the list
expectExposurePairsListItem(0, '$mockPhotoFastestAperture', '1/320');
final exposurePairs = await scrollToTheLastExposurePair(tester);
expectExposurePairsListItem(exposurePairs.length - 1, '$mockPhotoSlowestAperture', '6"');
expectMeasureButton(mockPhotoEv100);
},
);
testWidgets(
'Multiple exposure pairs w/ reciprocity',
(tester) async {
await pumpApplication(tester, IAPProductStatus.purchased, selectedFilm: mockFilms.first);
await tester.toggleIncidentMetering();
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 26"');
expectExposurePairsListItem(0, 'f/1.0', '1/160');
expectMeasureButton(7.3);
await tester.pumpApplication(selectedFilm: mockFilms.first);
await tester.takePhoto();
final exposurePairs = MeteringContainerBuidler.buildExposureValues(
7.3,
StopType.third,
defaultEquipmentProfile,
);
await tester.scrollUntilVisible(
find.byWidgetPredicate(
(widget) => widget is Row && widget.key == ValueKey(exposurePairs.length - 1),
),
56,
scrollable: find.descendant(
of: find.byType(ExposurePairsList),
matching: find.byType(Scrollable),
),
);
expectExposurePairsListItem(exposurePairs.length - 1, 'f/45', '26"');
expectMeasureButton(7.3);
/// Verify that reciprocity is applied to the slowest exposure pair in the container
expectExposurePairsContainer('$mockPhotoFastestAperture - 1/320', '$mockPhotoSlowestAperture - 12"');
expectMeasureButton(mockPhotoEv100);
/// Verify that reciprocity is applied to the slowest exposure pair in the list
expectExposurePairsListItem(0, '$mockPhotoFastestAperture', '1/320');
final exposurePairs = await scrollToTheLastExposurePair(tester);
expectExposurePairsListItem(exposurePairs.length - 1, '$mockPhotoSlowestAperture', '12"');
expectMeasureButton(mockPhotoEv100);
},
);
},
skip: true,
);
group(
'Pickers tests',
'[Pickers tests]',
() {
group('Select film', () {
testWidgets(
'with the same ISO',
(tester) async {
await pumpApplication(tester, IAPProductStatus.purchased);
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"');
expectMeasureButton(7.3);
await tester.pumpApplication();
await tester.takePhoto();
// Verify that reciprocity failure is applies for the film is not selected
expectAnimatedPickerWith<FilmPicker>(title: S.current.film, value: S.current.none);
expectExposurePairsContainer('$mockPhotoFastestExposurePair', '$mockPhotoSlowestExposurePair');
expectMeasureButton(mockPhotoEv100);
await tester.openAnimatedPicker<FilmPicker>();
expect(find.byType(DialogPicker<Film>), findsOneWidget);
await tester.tapRadioListTile<Film>('2');
await tester.tapDescendantTextOf<DialogPicker<Film>>(mockFilms.first.name);
await tester.tapSelectButton();
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"');
expectMeasureButton(7.3);
/// Make sure, that nothing is changed
await tester.tap(find.byType(MeteringMeasureButton));
await tester.tap(find.byType(MeteringMeasureButton));
await tester.pumpAndSettle();
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"');
expectMeasureButton(7.3);
/// Verify that exposure pairs are the same, except that the reciprocity failure is applied
expectExposurePairsContainer(
'$mockPhotoFastestExposurePair',
'$mockPhotoSlowestAperture - ${mockFilms.first.reciprocityFailure(mockPhotoSlowestShutterSpeed)}',
);
expectMeasureButton(mockPhotoEv100);
/// Make sure, that the EV is not changed
await tester.takePhoto();
expectExposurePairsContainer(
'$mockPhotoFastestExposurePair',
'$mockPhotoSlowestAperture - ${mockFilms.first.reciprocityFailure(mockPhotoSlowestShutterSpeed)}',
);
expectMeasureButton(mockPhotoEv100);
},
);
testWidgets(
'with greater ISO',
(tester) async {
await tester.pumpApplication();
await tester.takePhoto();
// Verify that reciprocity failure is applies for the film is not selected
expectAnimatedPickerWith<FilmPicker>(title: S.current.film, value: S.current.none);
expectExposurePairsContainer('$mockPhotoFastestExposurePair', '$mockPhotoSlowestExposurePair');
expectMeasureButton(mockPhotoEv100);
await tester.openAnimatedPicker<FilmPicker>();
await tester.tapDescendantTextOf<DialogPicker<Film>>(mockFilms[1].name);
await tester.tapSelectButton();
/// Verify that exposure pairs are the same, except that the reciprocity failure is applied
expectExposurePairsContainer(
'$mockPhotoFastestExposurePair',
'$mockPhotoSlowestAperture - ${mockFilms[1].reciprocityFailure(mockPhotoSlowestShutterSpeed)}',
);
expectMeasureButton(mockPhotoEv100);
/// Make sure, that the EV is not changed
await tester.takePhoto();
expectExposurePairsContainer(
'$mockPhotoFastestExposurePair',
'$mockPhotoSlowestAperture - ${mockFilms[1].reciprocityFailure(mockPhotoSlowestShutterSpeed)}',
);
expectMeasureButton(mockPhotoEv100);
},
);
});
@ -284,9 +254,9 @@ void main() {
testWidgets(
'Select ISO +1 EV',
(tester) async {
await pumpApplication(tester, IAPProductStatus.purchased);
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"');
expectMeasureButton(7.3);
await tester.pumpApplication(productStatus: IAPProductStatus.purchased);
expectExposurePairsContainer('f/1.0 - 1/320', 'f/45 - 13"');
expectMeasureButton(mockPhotoEv100);
await tester.openAnimatedPicker<IsoValuePicker>();
expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
@ -302,14 +272,15 @@ void main() {
expectExposurePairsContainer('f/1.0 - 1/320', 'f/45 - 6"');
expectMeasureButton(8.3);
},
skip: true,
);
testWidgets(
'Select ND -1 EV',
(tester) async {
await pumpApplication(tester, IAPProductStatus.purchased);
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"');
expectMeasureButton(7.3);
await tester.pumpApplication(productStatus: IAPProductStatus.purchased);
expectExposurePairsContainer('f/1.0 - 1/320', 'f/45 - 13"');
expectMeasureButton(mockPhotoEv100);
await tester.openAnimatedPicker<NdValuePicker>();
expect(find.byType(DialogPicker<NdValue>), findsOneWidget);
@ -325,15 +296,8 @@ void main() {
expectExposurePairsContainer('f/1.0 - 1/80', 'f/36 - 16"');
expectMeasureButton(6.3);
},
skip: true,
);
},
skip: true,
);
}
extension _WidgetTesterActions on WidgetTester {
Future<void> tapRadioListTile<T>(String value) async {
expect(find.descendant(of: find.byType(RadioListTile<T>), matching: find.text(value)), findsOneWidget);
await tap(find.descendant(of: find.byType(RadioListTile<T>), matching: find.text(value)));
}
}

View file

@ -93,7 +93,7 @@ final mockEquipmentProfiles = [
),
];
const mockFilms = [_MockFilm(400, 2), _MockFilm(3, 800), _MockFilm(400, 1.5)];
const mockFilms = [_MockFilm(100, 2), _MockFilm(400, 2), _MockFilm(3, 800), _MockFilm(400, 1.5)];
class _MockFilm extends Film {
final double reciprocityMultiplier;

View file

@ -0,0 +1,17 @@
# https://github.com/flutter/flutter/issues/86295#issuecomment-1192766368
devices=$(adb devices)
devicesIds=$(echo $devices | grep -Eo '[A-Z0-9]{2,}')
firstDeviceId=$(echo $devicesIds | cut -d " " -f 1)
# adb -s $firstDeviceId shell pm grant com.vodemn.lightmeter.dev android.permission.CAMERA
flutter drive \
--dart-define="cameraPreviewAspectRatio=240/320" \
--dart-define="cameraStubImage=assets/camera_stub_image.jpg" \
--driver=test_driver/integration_driver.dart \
--target=integration_test/metering_screen_test.dart \
--profile \
--flavor=dev \
--no-dds \
--endless-trace-buffer \
--purge-persistent-cache \
-d $firstDeviceId

View file

@ -1,3 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.dart';
@ -8,18 +9,8 @@ import 'package:lightmeter/screens/settings/components/shared/dialog_picker/widg
void expectAnimatedPickerWith<T>({String? title, String? value}) {
final pickerFinder = find.byType(T);
expect(pickerFinder, findsOneWidget);
if (title != null) {
expect(
find.descendant(of: pickerFinder, matching: find.text(title)),
findsOneWidget,
);
}
if (value != null) {
expect(
find.descendant(of: pickerFinder, matching: find.text(value)),
findsOneWidget,
);
}
if (title != null) expect(find.descendant(of: pickerFinder, matching: find.text(title)), findsOneWidget);
if (value != null) expect(find.descendant(of: pickerFinder, matching: find.text(value)), findsOneWidget);
}
/// Finds exactly one dialog picker of the provided value type
@ -37,10 +28,15 @@ void expectMeasureButton(double ev) {
void expectExposurePairsContainer(String fastest, String slowest) {
final pickerFinder = find.byType(ExtremeExposurePairsContainer);
expect(pickerFinder, findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text(S.current.fastestExposurePair)),
findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text(S.current.fastestExposurePair)), findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text(fastest)), findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text(S.current.slowestExposurePair)),
findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text(S.current.slowestExposurePair)), findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text(slowest)), findsOneWidget);
}
void expectRadioListTile<T>(String text, {bool isSelected = false}) {
expect(
find.descendant(of: find.byWidgetPredicate((widget) => widget is RadioListTile<T>), matching: find.text(text)),
findsOneWidget,
);
}

View file

@ -18,3 +18,17 @@ Future<void> sendMockIncidentEv(double ev) async {
(ByteData? data) {},
);
}
void setLightSensorAvilability({required bool hasSensor}) {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('system_feature'),
(methodCall) async {
switch (methodCall.method) {
case "sensor":
return hasSensor;
default:
return null;
}
},
);
}

View file

@ -10,6 +10,7 @@ import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import '../mocks/paid_features_mock.dart';
import 'platform_channel_mock.dart';
extension WidgetTesterCommonActions on WidgetTester {
Future<void> pumpApplication({
@ -33,8 +34,16 @@ extension WidgetTesterCommonActions on WidgetTester {
await pumpAndSettle();
}
Future<void> toggleIncidentMetering() async {
Future<void> takePhoto() async {
await tap(find.byType(MeteringMeasureButton));
await pump(const Duration(seconds: 2)); // wait for circular progress indicator
await pump(const Duration(seconds: 1)); // wait for circular progress indicator
await pumpAndSettle();
}
Future<void> toggleIncidentMetering(double ev) async {
await tap(find.byType(MeteringMeasureButton));
await sendMockIncidentEv(ev);
await tap(find.byType(MeteringMeasureButton));
await pumpAndSettle();
}
@ -45,6 +54,17 @@ extension WidgetTesterCommonActions on WidgetTester {
}
}
extension WidgetTesterListTileActions on WidgetTester {
Future<void> tapRadioListTile<T>(String text) async {
await tap(find.descendant(of: find.byType(RadioListTile<T>), matching: find.text(text)));
}
/// Useful for tapping a specific [ListTile] inside a specific screen or dialog
Future<void> tapDescendantTextOf<T>(String text) async {
await tap(find.descendant(of: find.byType(T), matching: find.text(text)));
}
}
extension WidgetTesterTextButtonActions on WidgetTester {
Future<void> tapSelectButton() => _tapTextButton(S.current.select);

View file

@ -0,0 +1,8 @@
import 'package:integration_test/integration_test_driver_extended.dart';
import 'utils/grant_camera_permission.dart';
Future<void> main() async {
await grantCameraPermission();
await integrationDriver();
}

View file

@ -1,42 +1,15 @@
import 'dart:developer';
import 'dart:io';
import 'package:integration_test/integration_test_driver_extended.dart';
import 'utils/grant_camera_permission.dart';
Future<void> main() async {
try {
final bool adbExists = Process.runSync('which', <String>['adb']).exitCode == 0;
if (!adbExists) {
log(r'This test needs ADB to exist on the $PATH. Skipping...');
exit(0);
}
final deviceId = await Process.run('adb', ["-s", 'shell', 'devices']).then((value) {
if (value.stdout is String) {
return RegExp(r"(?:List of devices attached\n)([A-Z0-9]*)(?:\sdevice\n)")
.firstMatch(value.stdout as String)!
.group(1);
}
});
if (deviceId == null) {
log('This test needs at least one device connected');
exit(0);
}
await Process.run('adb', [
"-s",
deviceId, // https://github.com/flutter/flutter/issues/86295#issuecomment-1192766368
'shell',
'pm',
'grant',
'com.vodemn.lightmeter.dev',
'android.permission.CAMERA'
]);
await integrationDriver(
onScreenshot: (name, bytes, [args]) async {
final File image = await File('screenshots/$name.png').create(recursive: true);
image.writeAsBytesSync(bytes);
return true;
},
);
} catch (e) {
log('Error occured: $e');
}
await grantCameraPermission();
await integrationDriver(
onScreenshot: (name, bytes, [args]) async {
final File image = await File('screenshots/TEST_$name.png').create(recursive: true);
image.writeAsBytesSync(bytes);
return true;
},
);
}

View file

@ -0,0 +1,34 @@
import 'dart:developer';
import 'dart:io';
Future<void> grantCameraPermission() async {
try {
final bool adbExists = Process.runSync('which', <String>['adb']).exitCode == 0;
if (!adbExists) {
log(r'This test needs ADB to exist on the $PATH. Skipping...');
exit(0);
}
final deviceId = await Process.run('adb', ["-s", 'shell', 'devices']).then((value) {
if (value.stdout is String) {
return RegExp(r"(?:List of devices attached\n)([A-Z0-9]*)(?:\sdevice\n)")
.firstMatch(value.stdout as String)!
.group(1);
}
});
if (deviceId == null) {
log('This test needs at least one device connected');
exit(0);
}
await Process.run('adb', [
"-s",
deviceId, // https://github.com/flutter/flutter/issues/86295#issuecomment-1192766368
'shell',
'pm',
'grant',
'com.vodemn.lightmeter.dev',
'android.permission.CAMERA'
]);
} catch (e) {
log('Error occured: $e');
}
}