Compare commits

..

5 commits

Author SHA1 Message Date
Vadim
b68e6384d9 Films in use test 2023-10-14 21:24:11 +02:00
Vadim
49412cfce4 split integration tests by screens 2023-10-14 20:56:44 +02:00
Vadim
b4f07ccd14 Metering layout features tests 2023-10-14 20:41:39 +02:00
Vadim
a5c8908983 removed unnecessary imports 2023-10-14 19:45:38 +02:00
Vadim
1c41abbde9 FilmPicker tests 2023-10-14 19:24:00 +02:00
16 changed files with 737 additions and 297 deletions

View file

@ -236,46 +236,3 @@ extension on WidgetTester {
await pumpAndSettle();
}
}
final _mockEquipmentProfiles = [
const EquipmentProfile(
id: '',
name: '',
apertureValues: ApertureValue.values,
ndValues: NdValue.values,
shutterSpeedValues: ShutterSpeedValue.values,
isoValues: IsoValue.values,
),
EquipmentProfile(
id: '1',
name: 'Praktica + Zenitar',
apertureValues: ApertureValue.values.sublist(
ApertureValue.values.indexOf(const ApertureValue(1.7, StopType.half)),
ApertureValue.values.indexOf(const ApertureValue(16, StopType.full)) + 1,
),
ndValues: NdValue.values.sublist(0, 3),
shutterSpeedValues: ShutterSpeedValue.values.sublist(
ShutterSpeedValue.values.indexOf(const ShutterSpeedValue(1000, true, StopType.full)),
ShutterSpeedValue.values.indexOf(const ShutterSpeedValue(16, false, StopType.full)) + 1,
),
isoValues: const [
IsoValue(50, StopType.full),
IsoValue(100, StopType.full),
IsoValue(200, StopType.full),
IsoValue(250, StopType.third),
IsoValue(400, StopType.full),
IsoValue(500, StopType.third),
IsoValue(800, StopType.full),
IsoValue(1600, StopType.full),
IsoValue(3200, StopType.full),
],
),
const EquipmentProfile(
id: '2',
name: 'Praktica + Jupiter',
apertureValues: ApertureValue.values,
ndValues: NdValue.values,
shutterSpeedValues: ShutterSpeedValue.values,
isoValues: IsoValue.values,
),
];

View file

@ -17,16 +17,15 @@ 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/dimens.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/shared/exposure_pairs_list/widget_list_exposure_pairs.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/equipment_profile_picker/widget_picker_equipment_profiles.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/iso_picker/widget_picker_iso.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/nd_picker/widget_picker_nd.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart';
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';
@ -35,6 +34,7 @@ import 'package:permission_handler/permission_handler.dart';
import 'mocks/paid_features_mock.dart';
import 'utils/expectations.dart';
import 'utils/widget_tester_actions.dart';
class _MockUserPreferencesService extends Mock implements UserPreferencesService {}
@ -63,7 +63,7 @@ void main() {
setUpAll(() {
mockUserPreferencesService = _MockUserPreferencesService();
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.camera);
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.sensor);
when(() => mockUserPreferencesService.stopType).thenReturn(StopType.third);
when(() => mockUserPreferencesService.locale).thenReturn(SupportedLocale.en);
when(() => mockUserPreferencesService.caffeine).thenReturn(true);
@ -110,10 +110,17 @@ void main() {
when(() => mockHapticsService.responseVibration()).thenAnswer((_) async {});
});
Future<void> pumpApplication(WidgetTester tester, IAPProductStatus purchaseStatus) 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,
@ -131,90 +138,115 @@ void main() {
await tester.pumpAndSettle();
}
group('Match extreme exposure pairs & pairs list edge values', () {
setUpAll(() {
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.sensor);
when(() => mockLightSensorService.luxStream()).thenAnswer((_) => Stream.fromIterable([100]));
});
testWidgets(
'No exposure pairs',
(tester) async {
await pumpApplication(tester, IAPProductStatus.purchasable);
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('-')), findsNWidgets(2));
group(
'Match extreme exposure pairs & pairs list edge values',
() {
void expectExposurePairsListItem(int index, String aperture, String shutterSpeed) {
final firstPairRow = find.byWidgetPredicate(
(widget) => widget is Row && widget.key == ValueKey(index),
);
expect(
find.descendant(
of: find.byType(ExposurePairsList),
matching: find.byWidgetPredicate(
(widget) =>
widget is IconPlaceholder &&
widget.icon == Icons.not_interested &&
widget.text == S.current.noExposurePairs,
),
),
find.descendant(of: firstPairRow, matching: find.text(aperture)),
findsOneWidget,
);
},
);
testWidgets(
'Multiple exposure pairs',
(tester) async {
await pumpApplication(tester, IAPProductStatus.purchasable);
await tester.tap(find.byType(MeteringMeasureButton));
await tester.tap(find.byType(MeteringMeasureButton));
await tester.pumpAndSettle();
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('f/1.0 - 1/160')), findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text('f/45 - 13"')), findsOneWidget);
final firstPairRow = find.byWidgetPredicate((widget) => widget is Row && widget.key == const ValueKey(0));
expect(find.descendant(of: firstPairRow, matching: find.text('f/1.0')), findsOneWidget);
expect(find.descendant(of: firstPairRow, matching: find.text('1/160')), findsOneWidget);
final lastPairRow = find.byWidgetPredicate(
(widget) =>
widget is Row && widget.key == ValueKey(ApertureValue.values.whereStopType(StopType.third).length - 1),
expect(
find.descendant(of: firstPairRow, matching: find.text(shutterSpeed)),
findsOneWidget,
);
final listFinder = find.descendant(of: find.byType(ExposurePairsList), matching: find.byType(Scrollable));
await tester.scrollUntilVisible(lastPairRow, 56, scrollable: listFinder);
expect(find.descendant(of: lastPairRow, matching: find.text('f/45')), findsOneWidget);
expect(find.descendant(of: lastPairRow, matching: find.text('13"')), findsOneWidget);
},
);
});
}
setUpAll(() {
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.sensor);
when(() => mockLightSensorService.luxStream()).thenAnswer((_) => Stream.fromIterable([100]));
});
group(
'Free version',
() {
testWidgets(
'Initial state',
'No exposure pairs',
(tester) async {
await pumpApplication(tester, IAPProductStatus.purchasable);
expectAnimatedPicker<EquipmentProfilePicker>(S.current.equipmentProfile, S.current.none);
expectAnimatedPicker<FilmPicker>(S.current.film, S.current.none);
expectAnimatedPicker<IsoValuePicker>(S.current.iso, '400');
expectAnimatedPicker<NdValuePicker>(S.current.nd, S.current.none);
await tester.openAnimatedPicker<EquipmentProfilePicker>();
expect(find.byType(DialogPicker<EquipmentProfile>), findsOneWidget);
// expect None selected and no other profiles present
await tester.tapCancelButton();
expect(find.byType(DialogPicker<EquipmentProfile>), findsNothing);
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('-')), findsNWidgets(2));
await tester.openAnimatedPicker<FilmPicker>();
await tester.openAnimatedPicker<IsoValuePicker>();
await tester.openAnimatedPicker<NdValuePicker>();
expect(
find.descendant(
of: find.byType(ExposurePairsList),
matching: find.byWidgetPredicate(
(widget) =>
widget is IconPlaceholder &&
widget.icon == Icons.not_interested &&
widget.text == S.current.noExposurePairs,
),
),
findsOneWidget,
);
},
);
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);
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);
},
);
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);
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);
},
);
},
@ -222,19 +254,76 @@ void main() {
);
group(
'Pro version',
'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.openAnimatedPicker<FilmPicker>();
expect(find.byType(DialogPicker<Film>), findsOneWidget);
await tester.tapRadioListTile<Film>('2');
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);
},
);
});
testWidgets(
'Initial state',
'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.openAnimatedPicker<IsoValuePicker>();
expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
await tester.tapRadioListTile<IsoValue>('800');
await tester.tapSelectButton();
expectExposurePairsContainer('f/1.0 - 1/320', 'f/45 - 6"');
expectMeasureButton(8.3);
/// Make sure, that current ISO is used in metering
await tester.tap(find.byType(MeteringMeasureButton));
await tester.tap(find.byType(MeteringMeasureButton));
await tester.pumpAndSettle();
expectExposurePairsContainer('f/1.0 - 1/320', 'f/45 - 6"');
expectMeasureButton(8.3);
},
);
testWidgets(
'Film (push/pull)',
'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.openAnimatedPicker<NdValuePicker>();
expect(find.byType(DialogPicker<NdValue>), findsOneWidget);
await tester.tapRadioListTile<NdValue>('2');
await tester.tapSelectButton();
expectExposurePairsContainer('f/1.0 - 1/80', 'f/36 - 16"');
expectMeasureButton(6.3);
/// Make sure, that current ISO is used in metering
await tester.tap(find.byType(MeteringMeasureButton));
await tester.tap(find.byType(MeteringMeasureButton));
await tester.pumpAndSettle();
expectExposurePairsContainer('f/1.0 - 1/80', 'f/36 - 16"');
expectMeasureButton(6.3);
},
);
},
@ -242,27 +331,9 @@ void main() {
);
}
extension WidgetTesterActions on WidgetTester {
Future<void> openAnimatedPicker<T>() async {
await tap(find.byType(T));
await pumpAndSettle(Dimens.durationL);
}
Future<void> tapSelectButton() async {
final cancelButton = find.byWidgetPredicate(
(widget) => widget is TextButton && widget.child is Text && (widget.child as Text?)?.data == S.current.select,
);
expect(cancelButton, findsOneWidget);
await tap(cancelButton);
await pumpAndSettle();
}
Future<void> tapCancelButton() async {
final cancelButton = find.byWidgetPredicate(
(widget) => widget is TextButton && widget.child is Text && (widget.child as Text?)?.data == S.current.cancel,
);
expect(cancelButton, findsOneWidget);
await tap(cancelButton);
await pumpAndSettle();
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

@ -67,6 +67,7 @@ class _MockIAPProvidersState extends State<MockIAPProviders> {
storageService: mockIAPStorageService,
child: FilmsProvider(
storageService: mockIAPStorageService,
availableFilms: mockFilms,
child: widget.child,
),
),
@ -119,4 +120,18 @@ final mockEquipmentProfiles = [
),
];
const mockFilms = [Film('Ilford HP5+', 400)];
const mockFilms = [_MockFilm2x(), _MockFilm3x()];
class _MockFilm2x extends Film {
const _MockFilm2x() : super('Mock film 2x', 400);
@override
double reciprocityFormula(double t) => t * 2;
}
class _MockFilm3x extends Film {
const _MockFilm3x() : super('Mock film 3x', 800);
@override
double reciprocityFormula(double t) => t * 3;
}

View file

@ -0,0 +1,294 @@
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/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/shared/readings_container/components/equipment_profile_picker/widget_picker_equipment_profiles.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/shared/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart';
import 'package:lightmeter/screens/settings/components/metering/components/metering_screen_layout/components/meterins_screen_layout_features_dialog/widget_dialog_metering_screen_layout_features.dart';
import 'package:lightmeter/screens/settings/components/shared/dialog_filter/widget_dialog_filter.dart';
import 'package:lightmeter/screens/settings/screen_settings.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 'mocks/paid_features_mock.dart';
import 'utils/expectations.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);
//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;
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: true,
});
when(() => mockUserPreferencesService.themeType).thenReturn(ThemeType.light);
when(() => mockUserPreferencesService.primaryColor).thenReturn(primaryColorsList[5]);
when(() => mockUserPreferencesService.dynamicColor).thenReturn(false);
mockCaffeineService = _MockCaffeineService();
when(() => mockCaffeineService.isKeepScreenOn()).thenAnswer((_) async => false);
when(() => mockCaffeineService.keepScreenOn(true)).thenAnswer((_) async => true);
when(() => mockCaffeineService.keepScreenOn(false)).thenAnswer((_) async => false);
mockHapticsService = _MockHapticsService();
when(() => mockHapticsService.quickVibration()).thenAnswer((_) async {});
when(() => mockHapticsService.responseVibration()).thenAnswer((_) async {});
when(() => mockHapticsService.errorVibration()).thenAnswer((_) async {});
mockPermissionsService = _MockPermissionsService();
when(() => mockPermissionsService.requestCameraPermission()).thenAnswer((_) async => PermissionStatus.granted);
when(() => mockPermissionsService.checkCameraPermission()).thenAnswer((_) async => PermissionStatus.granted);
mockLightSensorService = _MockLightSensorService();
when(() => mockLightSensorService.hasSensor()).thenAnswer((_) async => true);
when(() => mockLightSensorService.luxStream()).thenAnswer((_) => Stream.fromIterable([100]));
mockVolumeEventsService = _MockVolumeEventsService();
when(() => mockVolumeEventsService.setVolumeHandling(true)).thenAnswer((_) async => true);
when(() => mockVolumeEventsService.setVolumeHandling(false)).thenAnswer((_) async => false);
when(() => mockVolumeEventsService.volumeButtonsEventStream()).thenAnswer((_) => const Stream<int>.empty());
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();
}
group(
'[Metering layout features]',
() {
Future<void> toggleFeatureAndClose(WidgetTester tester, String feature) async {
await tester.openSettings();
expect(find.byType(SettingsScreen), findsOneWidget);
await tester.tap(find.text(S.current.meteringScreenLayout));
await tester.pumpAndSettle();
expect(find.byType(MeteringScreenLayoutFeaturesDialog), findsOneWidget);
await tester.tap(
find.descendant(
of: find.byType(SwitchListTile),
matching: find.text(feature),
),
);
await tester.tapSaveButton();
expect(find.byType(MeteringScreenLayoutFeaturesDialog), findsNothing);
await tester.tap(find.byIcon(Icons.close));
await tester.pumpAndSettle();
}
testWidgets(
'Toggle equipmentProfiles & discard selected',
(tester) async {
await pumpApplication(
tester,
IAPProductStatus.purchased,
selectedEquipmentProfileId: mockEquipmentProfiles[0].id,
);
await tester.toggleIncidentMetering();
expectAnimatedPickerWith<EquipmentProfilePicker>(value: mockEquipmentProfiles[0].name);
expectExposurePairsContainer('f/1.8 - 1/50', 'f/16 - 1.6"');
expectMeasureButton(7.3);
await toggleFeatureAndClose(tester, S.current.meteringScreenLayoutHintEquipmentProfiles);
expect(find.byType(EquipmentProfilePicker), findsNothing);
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"');
expectMeasureButton(7.3);
await toggleFeatureAndClose(tester, S.current.meteringScreenLayoutHintEquipmentProfiles);
expectAnimatedPickerWith<EquipmentProfilePicker>(value: S.current.none);
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"');
expectMeasureButton(7.3);
},
);
testWidgets(
'Toggle extremeExposurePairs',
(tester) async {
await pumpApplication(tester, IAPProductStatus.purchased);
await tester.toggleIncidentMetering();
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"');
expectMeasureButton(7.3);
await toggleFeatureAndClose(tester, S.current.meteringScreenFeatureExtremeExposurePairs);
expect(find.byType(ExtremeExposurePairsContainer), findsNothing);
expectMeasureButton(7.3);
await toggleFeatureAndClose(tester, S.current.meteringScreenFeatureExtremeExposurePairs);
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"');
expectMeasureButton(7.3);
},
);
testWidgets(
'Toggle film & discard selected',
(tester) async {
await pumpApplication(
tester,
IAPProductStatus.purchased,
selectedFilm: mockFilms.first,
);
await tester.toggleIncidentMetering();
expectAnimatedPickerWith<FilmPicker>(value: mockFilms.first.name);
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 26"');
expectMeasureButton(7.3);
await toggleFeatureAndClose(tester, S.current.meteringScreenFeatureFilmPicker);
expect(find.byType(FilmPicker), findsNothing);
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"');
expectMeasureButton(7.3);
await toggleFeatureAndClose(tester, S.current.meteringScreenFeatureFilmPicker);
expectAnimatedPickerWith<FilmPicker>(value: S.current.none);
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 13"');
expectMeasureButton(7.3);
},
);
testWidgets(
'Toggle histogram',
(tester) async {
await pumpApplication(tester, IAPProductStatus.purchased);
},
skip: true, // TODO(@vodemn)
);
},
);
testWidgets(
'[Films in use] Deselect current',
(tester) async {
await pumpApplication(
tester,
IAPProductStatus.purchased,
selectedFilm: mockFilms[0],
);
// Check that film is selected and reciprocity is applied
await tester.toggleIncidentMetering();
expectAnimatedPickerWith<FilmPicker>(value: mockFilms[0].name);
expectExposurePairsContainer('f/1.0 - 1/160', 'f/45 - 26"');
expectMeasureButton(7.3);
// Deselect the first films
await tester.openSettings();
expect(find.byType(SettingsScreen), findsOneWidget);
await tester.tap(find.text(S.current.filmsInUse));
await tester.pumpAndSettle();
expect(find.byType(DialogFilter<Film>), findsOneWidget);
await tester.tap(
find.descendant(
of: find.byType(CheckboxListTile),
matching: find.text(mockFilms[0].name),
),
);
await tester.tapSaveButton();
expect(find.byType(DialogFilter<Film>), findsNothing);
await tester.tap(find.byIcon(Icons.close));
await tester.pumpAndSettle();
// The previously selected films is no longer in use and therefore is discarded to None
expectAnimatedPickerWith<FilmPicker>(value: S.current.none);
expectMeasureButton(7.3);
// The previously selected films is no longer in use and therefore is not present in the picker
await tester.openAnimatedPicker<FilmPicker>();
expect(find.byType(DialogPicker<Film>), findsOneWidget);
expect(
find.descendant(
of: find.byWidgetPredicate((widget) => widget is RadioListTile<Film> && widget.selected),
matching: find.text(mockFilms[0].name),
),
findsNothing,
);
},
);
}
extension _WidgetTesterActions on WidgetTester {
Future<void> openSettings() async {
expect(find.byTooltip(S.current.tooltipOpenSettings), findsOneWidget);
await tap(find.byTooltip(S.current.tooltipOpenSettings));
await pumpAndSettle();
}
}

View file

@ -1,14 +1,46 @@
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';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/extreme_exposure_pairs_container/widget_container_extreme_exposure_pairs.dart';
import 'package:lightmeter/screens/settings/components/shared/dialog_picker/widget_dialog_picker.dart';
void expectAnimatedPicker<T>(String title, String value) {
/// Expects exactly one picker of the specified type and verifies `title` or/and `value` if any of the values is not null.
void expectAnimatedPickerWith<T>({String? title, String? value}) {
final pickerFinder = find.byType(T);
expect(find.descendant(of: pickerFinder, matching: find.text(title)), findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text(value)), findsOneWidget);
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,
);
}
}
/// Finds exactly one dialog picker of the provided value type
void expectDialogPicker<T>() {
expect(find.byType(DialogPicker<T>), findsOneWidget);
}
void expectMeasureButton(double ev) {
find.descendant(
of: find.byType(MeteringMeasureButton),
matching: find.text('${ev.toStringAsFixed(1)}\n${S.current.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(fastest)), findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text(S.current.slowestExposurePair)),
findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text(slowest)), findsOneWidget);
}

View file

@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.dart';
extension WidgetTesterTextButtonActions on WidgetTester {
Future<void> tapSelectButton() => _tapTextButton(S.current.select);
Future<void> tapCancelButton() => _tapTextButton(S.current.cancel);
Future<void> tapSaveButton() => _tapTextButton(S.current.save);
Future<void> _tapTextButton(String text) async {
final button = find.byWidgetPredicate(
(widget) => widget is TextButton && widget.child is Text && (widget.child as Text?)?.data == text,
);
expect(button, findsOneWidget);
await tap(button);
await pumpAndSettle();
}
}
extension WidgetTesterCommonActions on WidgetTester {
Future<void> toggleIncidentMetering() async {
await tap(find.byType(MeteringMeasureButton));
await tap(find.byType(MeteringMeasureButton));
await pumpAndSettle();
}
Future<void> openAnimatedPicker<T>() async {
await tap(find.byType(T));
await pumpAndSettle(Dimens.durationL);
}
}

View file

@ -27,14 +27,13 @@ class NdValuePicker extends StatelessWidget {
value.value == 0 ? S.of(context).none : value.value.toString(),
),
// using descending order, because ND filter darkens image & lowers EV
itemTrailingBuilder: (selected, value) => value.value != selected.value
? Text(S.of(context).evValue(value.toStringDifference(selected)))
: null,
itemTrailingBuilder: (selected, value) =>
value.value != selected.value ? Text(S.of(context).evValue(value.toStringDifference(selected))) : null,
onChanged: onChanged,
closedChild: ReadingValueContainer.singleValue(
value: ReadingValue(
label: S.of(context).nd,
value: selectedValue.value.toString(),
value: selectedValue.value == 0 ? S.of(context).none : selectedValue.value.toString(),
),
),
);

View file

@ -4,9 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/ev_source_type.dart';
import 'package:lightmeter/data/models/exposure_pair.dart';
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
import 'package:lightmeter/providers/equipment_profile_provider.dart';
import 'package:lightmeter/providers/films_provider.dart';
import 'package:lightmeter/providers/services_provider.dart';
import 'package:lightmeter/providers/user_preferences_provider.dart';
import 'package:lightmeter/screens/metering/bloc_metering.dart';
@ -15,7 +13,6 @@ import 'package:lightmeter/screens/metering/components/camera_container/provider
import 'package:lightmeter/screens/metering/components/light_sensor_container/provider_container_light_sensor.dart';
import 'package:lightmeter/screens/metering/event_metering.dart';
import 'package:lightmeter/screens/metering/state_metering.dart';
import 'package:lightmeter/screens/metering/utils/listener_metering_layout_feature.dart';
import 'package:lightmeter/screens/metering/utils/listsner_equipment_profiles.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
@ -74,15 +71,7 @@ class _InheritedListeners extends StatelessWidget {
onDidChangeDependencies: (value) {
context.read<MeteringBloc>().add(EquipmentProfileChangedEvent(value));
},
child: MeteringScreenLayoutFeatureListener(
feature: MeteringScreenLayoutFeature.filmPicker,
onDidChangeDependencies: (value) {
if (!value) {
FilmsProvider.of(context).setFilm(const Film.other());
}
},
child: child,
),
child: child,
);
}
}

View file

@ -1,52 +0,0 @@
import 'package:flutter/material.dart';
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
import 'package:lightmeter/providers/user_preferences_provider.dart';
/// Listening to multiple dependencies at the same time causes firing an event for all dependencies
/// even though some of them didn't change:
/// ```dart
/// @override
/// void didChangeDependencies() {
/// super.didChangeDependencies();
/// _bloc.add(EquipmentProfileChangedEvent(EquipmentProfile.of(context)));
/// if (!MeteringScreenLayout.featureStatusOf(context, MeteringScreenLayoutFeature.filmPicker)) {
/// _bloc.add(const FilmChangedEvent(Film.other()));
/// }
/// }
/// ```
/// To overcome this issue I've decided to create a generic listener,
/// that will listen to each dependency separately.
class MeteringScreenLayoutFeatureListener extends StatefulWidget {
final MeteringScreenLayoutFeature feature;
final ValueChanged<bool> onDidChangeDependencies;
final Widget child;
const MeteringScreenLayoutFeatureListener({
required this.feature,
required this.onDidChangeDependencies,
required this.child,
super.key,
});
@override
State<MeteringScreenLayoutFeatureListener> createState() =>
_MeteringScreenLayoutFeatureListenerState();
}
class _MeteringScreenLayoutFeatureListenerState extends State<MeteringScreenLayoutFeatureListener> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
widget.onDidChangeDependencies(
UserPreferencesProvider.meteringScreenFeatureOf(
context,
widget.feature,
),
);
}
@override
Widget build(BuildContext context) {
return widget.child;
}
}

View file

@ -2,20 +2,20 @@ import 'package:flutter/material.dart';
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/equipment_profile_provider.dart';
import 'package:lightmeter/providers/films_provider.dart';
import 'package:lightmeter/providers/user_preferences_provider.dart';
import 'package:lightmeter/res/dimens.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
class MeteringScreenLayoutFeaturesDialog extends StatefulWidget {
const MeteringScreenLayoutFeaturesDialog({super.key});
@override
State<MeteringScreenLayoutFeaturesDialog> createState() =>
_MeteringScreenLayoutFeaturesDialogState();
State<MeteringScreenLayoutFeaturesDialog> createState() => _MeteringScreenLayoutFeaturesDialogState();
}
class _MeteringScreenLayoutFeaturesDialogState extends State<MeteringScreenLayoutFeaturesDialog> {
late final _features =
MeteringScreenLayoutConfig.from(UserPreferencesProvider.meteringScreenConfigOf(context));
late final _features = MeteringScreenLayoutConfig.from(UserPreferencesProvider.meteringScreenConfigOf(context));
@override
Widget build(BuildContext context) {
@ -57,6 +57,9 @@ class _MeteringScreenLayoutFeaturesDialogState extends State<MeteringScreenLayou
if (!_features[MeteringScreenLayoutFeature.equipmentProfiles]!) {
EquipmentProfileProvider.of(context).setProfile(EquipmentProfiles.of(context).first);
}
if (!_features[MeteringScreenLayoutFeature.filmPicker]!) {
FilmsProvider.of(context).setFilm(const Film.other());
}
UserPreferencesProvider.of(context).setMeteringScreenLayout(_features);
Navigator.of(context).pop();
},

View file

@ -2,14 +2,13 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/films_provider.dart';
import 'package:lightmeter/res/dimens.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/shared/reading_value_container/widget_container_reading_value.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 '../../../../../application_mock.dart';
import 'utils.dart';
class _MockIAPStorageService extends Mock implements IAPStorageService {}
@ -53,8 +52,8 @@ void main() {
(tester) async {
when(() => mockIAPStorageService.selectedFilm).thenReturn(const Film.other());
await pumpApplication(tester);
_expectReadingValueContainerText(S.current.film);
_expectReadingValueContainerText(S.current.none);
expectReadingValueContainerText(S.current.film);
expectReadingValueContainerText(S.current.none);
},
);
@ -63,8 +62,8 @@ void main() {
(tester) async {
when(() => mockIAPStorageService.selectedFilm).thenReturn(_films[1]);
await pumpApplication(tester);
_expectReadingValueContainerText(S.current.film);
_expectReadingValueContainerText(_films[1].name);
expectReadingValueContainerText(S.current.film);
expectReadingValueContainerText(_films[1].name);
},
);
@ -73,8 +72,8 @@ void main() {
(tester) async {
when(() => mockIAPStorageService.selectedFilm).thenReturn(_films[2]);
await pumpApplication(tester);
_expectReadingValueContainerText(S.current.filmPull);
_expectReadingValueContainerText(_films[2].name);
expectReadingValueContainerText(S.current.filmPull);
expectReadingValueContainerText(_films[2].name);
},
);
@ -83,8 +82,8 @@ void main() {
(tester) async {
when(() => mockIAPStorageService.selectedFilm).thenReturn(_films[0]);
await pumpApplication(tester);
_expectReadingValueContainerText(S.current.filmPush);
_expectReadingValueContainerText(_films[0].name);
expectReadingValueContainerText(S.current.filmPush);
expectReadingValueContainerText(_films[0].name);
},
);
});
@ -94,12 +93,11 @@ void main() {
(tester) async {
when(() => mockIAPStorageService.selectedFilm).thenReturn(_films[0]);
await pumpApplication(tester);
await tester.tap(find.byType(FilmPicker));
await tester.pumpAndSettle(Dimens.durationL);
_expectRadioListTile(S.current.none);
_expectRadioListTile(_films[1].name);
_expectRadioListTile(_films[2].name);
_expectRadioListTile(_films[3].name);
await tester.openAnimatedPicker<FilmPicker>();
expectRadioListTile<Film>(S.current.none, isSelected: true);
expectRadioListTile<Film>(_films[1].name);
expectRadioListTile<Film>(_films[2].name);
expectRadioListTile<Film>(_films[3].name);
},
);
}
@ -110,17 +108,3 @@ const _films = [
Film('ISO 800 Film', 800),
Film('ISO 1600 Film', 1600),
];
void _expectReadingValueContainerText(String text) {
expect(
find.descendant(of: find.byType(ReadingValueContainer), matching: find.text(text)),
findsOneWidget,
);
}
void _expectRadioListTile(String filmName) {
expect(
find.descendant(of: find.byType(RadioListTile<Film>), matching: find.text(filmName)),
findsOneWidget,
);
}

View file

@ -0,0 +1,72 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/nd_picker/widget_picker_nd.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import '../../../../../application_mock.dart';
import 'utils.dart';
void main() {
Future<void> pumpApplication(
WidgetTester tester, {
List<NdValue> values = NdValue.values,
NdValue selectedValue = const NdValue(0),
}) async {
assert(values.contains(selectedValue));
await tester.pumpWidget(
WidgetTestApplicationMock(
child: Row(
children: [
Expanded(
child: NdValuePicker(
selectedValue: selectedValue,
values: values,
onChanged: (_) {},
),
),
],
),
),
);
await tester.pumpAndSettle();
}
testWidgets(
'Check dialog icon and title consistency',
(tester) async {
await pumpApplication(tester);
expectReadingValueContainerText(S.current.nd);
await tester.openAnimatedPicker<NdValuePicker>();
expect(find.byIcon(Icons.filter_b_and_w), findsOneWidget);
expectDialogPickerText<NdValue>(S.current.nd);
expectDialogPickerText<NdValue>(S.current.ndFilterFactor);
},
skip: true,
);
group(
'Display selected value',
() {
testWidgets(
'None',
(tester) async {
await pumpApplication(tester);
expectReadingValueContainerText(S.current.none);
await tester.openAnimatedPicker<NdValuePicker>();
expectRadioListTile<NdValue>(S.current.none, isSelected: true);
},
);
testWidgets(
'ND2',
(tester) async {
await pumpApplication(tester, selectedValue: const NdValue(2));
expectReadingValueContainerText('2');
await tester.openAnimatedPicker<NdValuePicker>();
expectRadioListTile<NdValue>('2', isSelected: true);
},
);
},
);
}

View file

@ -2,11 +2,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/iso_picker/widget_picker_iso.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/widget_picker_dialog_animated.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/reading_value_container/widget_container_reading_value.dart';
import '../../../../../../application_mock.dart';
import '../utils.dart';
void main() {
group(
@ -16,10 +17,10 @@ void main() {
'Open & close with select',
(tester) async {
await tester.pumpApplication();
await tester.openAnimatedPicker<IsoValuePicker>();
expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
await tester.openAnimatedPicker<AnimatedDialogPicker<int>>();
expect(find.byType(DialogPicker<int>), findsOneWidget);
await tester.tapSelectButton();
expect(find.byType(DialogPicker<IsoValue>), findsNothing);
expect(find.byType(DialogPicker<int>), findsNothing);
},
);
@ -27,10 +28,10 @@ void main() {
'Open & close with cancel',
(tester) async {
await tester.pumpApplication();
await tester.openAnimatedPicker<IsoValuePicker>();
expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
await tester.openAnimatedPicker<AnimatedDialogPicker<int>>();
expect(find.byType(DialogPicker<int>), findsOneWidget);
await tester.tapCancelButton();
expect(find.byType(DialogPicker<IsoValue>), findsNothing);
expect(find.byType(DialogPicker<int>), findsNothing);
},
);
@ -38,15 +39,15 @@ void main() {
'Open & close with tap outside',
(tester) async {
await tester.pumpApplication();
await tester.openAnimatedPicker<IsoValuePicker>();
expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
await tester.openAnimatedPicker<AnimatedDialogPicker<int>>();
expect(find.byType(DialogPicker<int>), findsOneWidget);
/// tester taps the center of the found widget,
/// which results in tap on the dialog instead of the underlying barrier
/// therefore just tap at offset outside the dialog
await tester.longPressAt(const Offset(16, 16));
await tester.pumpAndSettle(Dimens.durationML);
expect(find.byType(DialogPicker<IsoValue>), findsNothing);
expect(find.byType(DialogPicker<int>), findsNothing);
},
);
@ -54,8 +55,8 @@ void main() {
'Open & close with back gesture',
(tester) async {
await tester.pumpApplication();
await tester.openAnimatedPicker<IsoValuePicker>();
expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
await tester.openAnimatedPicker<AnimatedDialogPicker<int>>();
expect(find.byType(DialogPicker<int>), findsOneWidget);
//// https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/router_test.dart#L970-L971
//// final ByteData message = const JSONMethodCodec().encodeMethodCall(const MethodCall('popRoute'));
@ -63,7 +64,7 @@ void main() {
/// https://github.com/flutter/packages/blob/main/packages/animations/test/open_container_test.dart#L234
(tester.state(find.byType(Navigator)) as NavigatorState).pop();
await tester.pumpAndSettle(Dimens.durationML);
expect(find.byType(DialogPicker<IsoValue>), findsNothing);
expect(find.byType(DialogPicker<int>), findsNothing);
},
);
},
@ -77,10 +78,21 @@ extension WidgetTesterActions on WidgetTester {
child: Row(
children: [
Expanded(
child: IsoValuePicker(
selectedValue: const IsoValue(400, StopType.full),
values: IsoValue.values,
child: AnimatedDialogPicker<int>(
icon: Icons.iso,
title: '',
subtitle: '',
selectedValue: 0,
values: List.generate(10, (index) => index),
itemTitleBuilder: (_, value) => Text(value.toString()),
itemTrailingBuilder: (selected, value) => null,
onChanged: (_) {},
closedChild: ReadingValueContainer.singleValue(
value: ReadingValue(
label: '',
value: 0.toString(),
),
),
),
),
],
@ -90,11 +102,6 @@ extension WidgetTesterActions on WidgetTester {
await pumpAndSettle();
}
Future<void> openAnimatedPicker<T>() async {
await tap(find.byType(T));
await pumpAndSettle(Dimens.durationL);
}
Future<void> tapSelectButton() async {
final cancelButton = find.byWidgetPredicate(
(widget) => widget is TextButton && widget.child is Text && (widget.child as Text?)?.data == S.current.select,

View file

@ -1,13 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/iso_picker/widget_picker_iso.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/widget_picker_dialog_animated.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/reading_value_container/widget_container_reading_value.dart';
import 'package:mocktail/mocktail.dart';
import '../../../../../../application_mock.dart';
import '../utils.dart';
class _ValueChanged {
void onChanged<T>(T value) {}
@ -25,11 +25,11 @@ void main() {
'other',
(tester) async {
await tester.pumpApplication(functions.onChanged);
await tester.openAnimatedPicker<IsoValuePicker>();
expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
await tester.tapListTile(500);
await tester.openAnimatedPicker<AnimatedDialogPicker<int>>();
expect(find.byType(DialogPicker<int>), findsOneWidget);
await tester.tapListTile(1);
await tester.tapSelectButton();
verify(() => functions.onChanged(const IsoValue(500, StopType.third))).called(1);
verify(() => functions.onChanged(1)).called(1);
},
);
@ -37,11 +37,11 @@ void main() {
'same',
(tester) async {
await tester.pumpApplication(functions.onChanged);
await tester.openAnimatedPicker<IsoValuePicker>();
expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
await tester.tapListTile(400);
await tester.openAnimatedPicker<AnimatedDialogPicker<int>>();
expect(find.byType(DialogPicker<int>), findsOneWidget);
await tester.tapListTile(0);
await tester.tapSelectButton();
verify(() => functions.onChanged(const IsoValue(400, StopType.full))).called(1);
verify(() => functions.onChanged(0)).called(1);
},
);
},
@ -49,16 +49,27 @@ void main() {
}
extension WidgetTesterActions on WidgetTester {
Future<void> pumpApplication(ValueChanged<IsoValue> onChanged) async {
Future<void> pumpApplication(ValueChanged<int> onChanged) async {
await pumpWidget(
WidgetTestApplicationMock(
child: Row(
children: [
Expanded(
child: IsoValuePicker(
selectedValue: const IsoValue(400, StopType.full),
values: IsoValue.values,
child: AnimatedDialogPicker<int>(
icon: Icons.iso,
title: '',
subtitle: '',
selectedValue: 0,
values: List.generate(10, (index) => index),
itemTitleBuilder: (_, value) => Text(value.toString()),
itemTrailingBuilder: (selected, value) => null,
onChanged: onChanged,
closedChild: ReadingValueContainer.singleValue(
value: ReadingValue(
label: '',
value: 0.toString(),
),
),
),
),
],
@ -68,14 +79,9 @@ extension WidgetTesterActions on WidgetTester {
await pumpAndSettle();
}
Future<void> openAnimatedPicker<T>() async {
await tap(find.byType(T));
await pumpAndSettle(Dimens.durationL);
}
Future<void> tapListTile(int iso) async {
expect(find.descendant(of: find.byType(RadioListTile<IsoValue>), matching: find.text('$iso')), findsOneWidget);
await tap(find.descendant(of: find.byType(RadioListTile<IsoValue>), matching: find.text('$iso')));
expect(find.descendant(of: find.byType(RadioListTile<int>), matching: find.text('$iso')), findsOneWidget);
await tap(find.descendant(of: find.byType(RadioListTile<int>), matching: find.text('$iso')));
}
Future<void> tapSelectButton() async {

View file

@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/reading_value_container/widget_container_reading_value.dart';
extension WidgetTesterActions on WidgetTester {
Future<void> openAnimatedPicker<T>() async {
await tap(find.byType(T));
await pumpAndSettle(Dimens.durationL);
}
}
void expectReadingValueContainerText(String text) => _expectTextDescendantOf<ReadingValueContainer>(text);
void expectDialogPickerText<T>(String text) => _expectTextDescendantOf<DialogPicker<T>>(text);
void _expectTextDescendantOf<T>(String text) {
expect(find.descendant(of: find.byType(T), matching: find.text(text)), findsOneWidget);
}
void expectRadioListTile<T>(String text, {bool isSelected = false}) {
expect(
find.descendant(of: find.byType(RadioListTile<T>), matching: find.text(text)),
findsOneWidget,
);
}

View file

@ -1,4 +1,5 @@
flutter test --coverage
flutter test integration_test --flavor=dev --coverage
file=test/coverage_helper_test.dart
echo "// Helper file to make coverage work for all dart files\n" > $file