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(); 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 { Future<void> tapListTile(String title) async {
final listTile = find.byWidgetPredicate( final listTile = find.byWidgetPredicate(
(widget) => widget is ListTile && widget.title is Text && (widget.title as Text?)?.data == title, (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/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_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/ev_source_type.dart';
import 'package:lightmeter/data/models/metering_screen_layout_config.dart'; import 'package:lightmeter/data/models/exposure_pair.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/shared_prefs_service.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/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/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/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/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'; 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:lightmeter/screens/shared/icon_placeholder/widget_icon_placeholder.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:mocktail/mocktail.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:permission_handler/permission_handler.dart';
import 'mocks/paid_features_mock.dart'; import 'mocks/paid_features_mock.dart';
import 'utils/expectations.dart'; import 'utils/expectations.dart';
import 'utils/platform_channel_mock.dart';
import 'utils/widget_tester_actions.dart'; import 'utils/widget_tester_actions.dart';
class _MockUserPreferencesService extends Mock implements UserPreferencesService {} const defaultIsoValue = IsoValue(100, StopType.full);
const mockPhotoEv100 = 8.3;
class _MockCaffeineService extends Mock implements CaffeineService {} const mockPhotoFastestAperture = ApertureValue(1, StopType.full);
const mockPhotoSlowestAperture = ApertureValue(45, StopType.full);
class _MockHapticsService extends Mock implements HapticsService {} const mockPhotoFastestShutterSpeed = ShutterSpeedValue(320, true, StopType.third);
const mockPhotoSlowestShutterSpeed = ShutterSpeedValue(6, false, StopType.third);
class _MockPermissionsService extends Mock implements PermissionsService {} const mockPhotoFastestExposurePair = ExposurePair(mockPhotoFastestAperture, mockPhotoFastestShutterSpeed);
const mockPhotoSlowestExposurePair = ExposurePair(mockPhotoSlowestAperture, mockPhotoSlowestShutterSpeed);
class _MockLightSensorService extends Mock implements LightSensorService {}
class _MockVolumeEventsService extends Mock implements VolumeEventsService {}
const _defaultIsoValue = IsoValue(400, StopType.full);
//https://stackoverflow.com/a/67186625/13167574 //https://stackoverflow.com/a/67186625/13167574
void main() { void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); IntegrationTestWidgetsFlutterBinding.ensureInitialized();
late _MockUserPreferencesService mockUserPreferencesService; group(
late _MockCaffeineService mockCaffeineService; '[Light sensor availability]',
late _MockHapticsService mockHapticsService; () {
late _MockPermissionsService mockPermissionsService; testWidgets(
late _MockLightSensorService mockLightSensorService; 'Android - has sensor',
late _MockVolumeEventsService mockVolumeEventsService; (tester) async {
SharedPreferences.setMockInitialValues({UserPreferencesService.evSourceTypeKey: EvSourceType.sensor.index});
setLightSensorAvilability(hasSensor: true);
await tester.pumpApplication(productStatus: IAPProductStatus.purchasable);
setUpAll(() { /// Verify that [LightSensorContainer] is shown in correspondance with the saved ev source
mockUserPreferencesService = _MockUserPreferencesService(); expect(find.byType(LightSensorContainer), findsOneWidget);
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.sensor); },
when(() => mockUserPreferencesService.stopType).thenReturn(StopType.third); skip: Platform.isIOS,
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);
mockCaffeineService = _MockCaffeineService(); testWidgets(
when(() => mockCaffeineService.isKeepScreenOn()).thenAnswer((_) async => false); 'Android - no sensor',
when(() => mockCaffeineService.keepScreenOn(true)).thenAnswer((_) async => true); (tester) async {
when(() => mockCaffeineService.keepScreenOn(false)).thenAnswer((_) async => false); SharedPreferences.setMockInitialValues({UserPreferencesService.evSourceTypeKey: EvSourceType.sensor.index});
setLightSensorAvilability(hasSensor: false);
await tester.pumpApplication(productStatus: IAPProductStatus.purchasable);
mockHapticsService = _MockHapticsService(); /// Verify that [CameraContainer] is shown instead of [LightSensorContainer]
when(() => mockHapticsService.quickVibration()).thenAnswer((_) async {}); expect(find.byType(CameraContainer), findsOneWidget);
when(() => mockHapticsService.responseVibration()).thenAnswer((_) async {});
when(() => mockHapticsService.errorVibration()).thenAnswer((_) async {});
mockPermissionsService = _MockPermissionsService(); /// and there is no ability to switch to the incident metering
when(() => mockPermissionsService.requestCameraPermission()).thenAnswer((_) async => PermissionStatus.granted); expect(find.byTooltip(S.current.tooltipUseLightSensor), findsNothing);
when(() => mockPermissionsService.checkCameraPermission()).thenAnswer((_) async => PermissionStatus.granted); },
skip: Platform.isIOS,
);
mockLightSensorService = _MockLightSensorService(); testWidgets(
when(() => mockLightSensorService.hasSensor()).thenAnswer((_) async => true); 'iOS - no sensor',
when(() => mockLightSensorService.luxStream()).thenAnswer((_) => Stream.fromIterable([100])); (tester) async {
SharedPreferences.setMockInitialValues({UserPreferencesService.evSourceTypeKey: EvSourceType.sensor.index});
await tester.pumpApplication(productStatus: IAPProductStatus.purchasable);
mockVolumeEventsService = _MockVolumeEventsService(); /// verify no button to switch to the incident light mode
when(() => mockVolumeEventsService.setVolumeHandling(true)).thenAnswer((_) async => true); expect(find.byType(CameraContainer), findsOneWidget);
when(() => mockVolumeEventsService.setVolumeHandling(false)).thenAnswer((_) async => false);
when(() => mockVolumeEventsService.volumeButtonsEventStream()).thenAnswer((_) => const Stream<int>.empty());
when(() => mockHapticsService.quickVibration()).thenAnswer((_) async {}); /// and there is no ability to switch to the incident metering
when(() => mockHapticsService.responseVibration()).thenAnswer((_) async {}); expect(find.byTooltip(S.current.tooltipUseLightSensor), findsNothing);
}); },
skip: Platform.isAndroid,
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();
}
group( 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) { void expectExposurePairsListItem(int index, String aperture, String shutterSpeed) {
final firstPairRow = find.byWidgetPredicate( final firstPairRow = find.byWidgetPredicate((widget) => widget is Row && widget.key == ValueKey(index));
(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);
expect(
find.descendant(of: firstPairRow, matching: find.text(aperture)),
findsOneWidget,
);
expect(
find.descendant(of: firstPairRow, matching: find.text(shutterSpeed)),
findsOneWidget,
);
} }
setUpAll(() { setUpAll(() {
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.sensor); SharedPreferences.setMockInitialValues({UserPreferencesService.evSourceTypeKey: EvSourceType.camera.index});
when(() => mockLightSensorService.luxStream()).thenAnswer((_) => Stream.fromIterable([100]));
}); });
testWidgets( testWidgets(
'No exposure pairs', 'No exposure pairs',
(tester) async { (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); final pickerFinder = find.byType(ExtremeExposurePairsContainer);
expect(pickerFinder, findsOneWidget); expect(pickerFinder, findsOneWidget);
expect( expect(find.descendant(of: pickerFinder, matching: find.text(S.current.fastestExposurePair)), findsOneWidget);
find.descendant(of: pickerFinder, matching: find.text(S.current.fastestExposurePair)), expect(find.descendant(of: pickerFinder, matching: find.text(S.current.slowestExposurePair)), findsOneWidget);
findsOneWidget,
);
expect(
find.descendant(of: pickerFinder, matching: find.text(S.current.slowestExposurePair)),
findsOneWidget,
);
expect(find.descendant(of: pickerFinder, matching: find.text('-')), findsNWidgets(2)); expect(find.descendant(of: pickerFinder, matching: find.text('-')), findsNWidgets(2));
/// Verify that the exposure pairs list is empty
expect( expect(
find.descendant( find.descendant(
of: find.byType(ExposurePairsList), of: find.byType(ExposurePairsList),
@ -195,88 +147,106 @@ void main() {
testWidgets( testWidgets(
'Multiple exposure pairs w/o reciprocity', 'Multiple exposure pairs w/o reciprocity',
(tester) async { (tester) async {
await pumpApplication(tester, IAPProductStatus.purchasable); await tester.pumpApplication(productStatus: IAPProductStatus.purchasable);
await tester.toggleIncidentMetering(); await tester.takePhoto();
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"');
expectExposurePairsListItem(0, 'f/1.0', '1/160');
expectMeasureButton(7.3);
final exposurePairs = MeteringContainerBuidler.buildExposureValues( /// Verify that reciprocity is not applied to the slowest exposure pair in the container
7.3, expectExposurePairsContainer('$mockPhotoFastestAperture - 1/320', '$mockPhotoSlowestAperture - 6"');
StopType.third, expectMeasureButton(mockPhotoEv100);
defaultEquipmentProfile,
); /// Verify that reciprocity is not applied to the slowest exposure pair in the list
await tester.scrollUntilVisible( expectExposurePairsListItem(0, '$mockPhotoFastestAperture', '1/320');
find.byWidgetPredicate( final exposurePairs = await scrollToTheLastExposurePair(tester);
(widget) => widget is Row && widget.key == ValueKey(exposurePairs.length - 1), expectExposurePairsListItem(exposurePairs.length - 1, '$mockPhotoSlowestAperture', '6"');
), expectMeasureButton(mockPhotoEv100);
56,
scrollable: find.descendant(
of: find.byType(ExposurePairsList),
matching: find.byType(Scrollable),
),
);
expectExposurePairsListItem(exposurePairs.length - 1, 'f/45', '13"');
expectMeasureButton(7.3);
}, },
); );
testWidgets( testWidgets(
'Multiple exposure pairs w/ reciprocity', 'Multiple exposure pairs w/ reciprocity',
(tester) async { (tester) async {
await pumpApplication(tester, IAPProductStatus.purchased, selectedFilm: mockFilms.first); await tester.pumpApplication(selectedFilm: mockFilms.first);
await tester.toggleIncidentMetering(); await tester.takePhoto();
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 26"');
expectExposurePairsListItem(0, 'f/1.0', '1/160');
expectMeasureButton(7.3);
final exposurePairs = MeteringContainerBuidler.buildExposureValues( /// Verify that reciprocity is applied to the slowest exposure pair in the container
7.3, expectExposurePairsContainer('$mockPhotoFastestAperture - 1/320', '$mockPhotoSlowestAperture - 12"');
StopType.third, expectMeasureButton(mockPhotoEv100);
defaultEquipmentProfile,
); /// Verify that reciprocity is applied to the slowest exposure pair in the list
await tester.scrollUntilVisible( expectExposurePairsListItem(0, '$mockPhotoFastestAperture', '1/320');
find.byWidgetPredicate( final exposurePairs = await scrollToTheLastExposurePair(tester);
(widget) => widget is Row && widget.key == ValueKey(exposurePairs.length - 1), expectExposurePairsListItem(exposurePairs.length - 1, '$mockPhotoSlowestAperture', '12"');
), expectMeasureButton(mockPhotoEv100);
56,
scrollable: find.descendant(
of: find.byType(ExposurePairsList),
matching: find.byType(Scrollable),
),
);
expectExposurePairsListItem(exposurePairs.length - 1, 'f/45', '26"');
expectMeasureButton(7.3);
}, },
); );
}, },
skip: true,
); );
group( group(
'Pickers tests', '[Pickers tests]',
() { () {
group('Select film', () { group('Select film', () {
testWidgets( testWidgets(
'with the same ISO', 'with the same ISO',
(tester) async { (tester) async {
await pumpApplication(tester, IAPProductStatus.purchased); await tester.pumpApplication();
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"'); await tester.takePhoto();
expectMeasureButton(7.3);
// 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.openAnimatedPicker<FilmPicker>();
expect(find.byType(DialogPicker<Film>), findsOneWidget); await tester.tapDescendantTextOf<DialogPicker<Film>>(mockFilms.first.name);
await tester.tapRadioListTile<Film>('2');
await tester.tapSelectButton(); await tester.tapSelectButton();
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"');
expectMeasureButton(7.3);
/// Make sure, that nothing is changed /// Verify that exposure pairs are the same, except that the reciprocity failure is applied
await tester.tap(find.byType(MeteringMeasureButton)); expectExposurePairsContainer(
await tester.tap(find.byType(MeteringMeasureButton)); '$mockPhotoFastestExposurePair',
await tester.pumpAndSettle(); '$mockPhotoSlowestAperture - ${mockFilms.first.reciprocityFailure(mockPhotoSlowestShutterSpeed)}',
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"'); );
expectMeasureButton(7.3); 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( testWidgets(
'Select ISO +1 EV', 'Select ISO +1 EV',
(tester) async { (tester) async {
await pumpApplication(tester, IAPProductStatus.purchased); await tester.pumpApplication(productStatus: IAPProductStatus.purchased);
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"'); expectExposurePairsContainer('f/1.0 - 1/320', 'f/45 - 13"');
expectMeasureButton(7.3); expectMeasureButton(mockPhotoEv100);
await tester.openAnimatedPicker<IsoValuePicker>(); await tester.openAnimatedPicker<IsoValuePicker>();
expect(find.byType(DialogPicker<IsoValue>), findsOneWidget); expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
@ -302,14 +272,15 @@ void main() {
expectExposurePairsContainer('f/1.0 - 1/320', 'f/45 - 6"'); expectExposurePairsContainer('f/1.0 - 1/320', 'f/45 - 6"');
expectMeasureButton(8.3); expectMeasureButton(8.3);
}, },
skip: true,
); );
testWidgets( testWidgets(
'Select ND -1 EV', 'Select ND -1 EV',
(tester) async { (tester) async {
await pumpApplication(tester, IAPProductStatus.purchased); await tester.pumpApplication(productStatus: IAPProductStatus.purchased);
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"'); expectExposurePairsContainer('f/1.0 - 1/320', 'f/45 - 13"');
expectMeasureButton(7.3); expectMeasureButton(mockPhotoEv100);
await tester.openAnimatedPicker<NdValuePicker>(); await tester.openAnimatedPicker<NdValuePicker>();
expect(find.byType(DialogPicker<NdValue>), findsOneWidget); expect(find.byType(DialogPicker<NdValue>), findsOneWidget);
@ -325,15 +296,8 @@ void main() {
expectExposurePairsContainer('f/1.0 - 1/80', 'f/36 - 16"'); expectExposurePairsContainer('f/1.0 - 1/80', 'f/36 - 16"');
expectMeasureButton(6.3); 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 { class _MockFilm extends Film {
final double reciprocityMultiplier; 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:flutter_test/flutter_test.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.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}) { void expectAnimatedPickerWith<T>({String? title, String? value}) {
final pickerFinder = find.byType(T); final pickerFinder = find.byType(T);
expect(pickerFinder, findsOneWidget); expect(pickerFinder, findsOneWidget);
if (title != null) { if (title != null) expect(find.descendant(of: pickerFinder, matching: find.text(title)), findsOneWidget);
expect( if (value != null) expect(find.descendant(of: pickerFinder, matching: find.text(value)), findsOneWidget);
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 /// Finds exactly one dialog picker of the provided value type
@ -37,10 +28,15 @@ void expectMeasureButton(double ev) {
void expectExposurePairsContainer(String fastest, String slowest) { void expectExposurePairsContainer(String fastest, String slowest) {
final pickerFinder = find.byType(ExtremeExposurePairsContainer); final pickerFinder = find.byType(ExtremeExposurePairsContainer);
expect(pickerFinder, findsOneWidget); expect(pickerFinder, findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text(S.current.fastestExposurePair)), expect(find.descendant(of: pickerFinder, matching: find.text(S.current.fastestExposurePair)), findsOneWidget);
findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text(fastest)), findsOneWidget); expect(find.descendant(of: pickerFinder, matching: find.text(fastest)), findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text(S.current.slowestExposurePair)), expect(find.descendant(of: pickerFinder, matching: find.text(S.current.slowestExposurePair)), findsOneWidget);
findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text(slowest)), 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) {}, (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 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import '../mocks/paid_features_mock.dart'; import '../mocks/paid_features_mock.dart';
import 'platform_channel_mock.dart';
extension WidgetTesterCommonActions on WidgetTester { extension WidgetTesterCommonActions on WidgetTester {
Future<void> pumpApplication({ Future<void> pumpApplication({
@ -33,8 +34,16 @@ extension WidgetTesterCommonActions on WidgetTester {
await pumpAndSettle(); await pumpAndSettle();
} }
Future<void> toggleIncidentMetering() async { Future<void> takePhoto() async {
await tap(find.byType(MeteringMeasureButton)); 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 tap(find.byType(MeteringMeasureButton));
await pumpAndSettle(); 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 { extension WidgetTesterTextButtonActions on WidgetTester {
Future<void> tapSelectButton() => _tapTextButton(S.current.select); 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 'dart:io';
import 'package:integration_test/integration_test_driver_extended.dart'; import 'package:integration_test/integration_test_driver_extended.dart';
import 'utils/grant_camera_permission.dart';
Future<void> main() async { Future<void> main() async {
try { await grantCameraPermission();
final bool adbExists = Process.runSync('which', <String>['adb']).exitCode == 0; await integrationDriver(
if (!adbExists) { onScreenshot: (name, bytes, [args]) async {
log(r'This test needs ADB to exist on the $PATH. Skipping...'); final File image = await File('screenshots/TEST_$name.png').create(recursive: true);
exit(0); image.writeAsBytesSync(bytes);
} return true;
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');
}
} }

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