Compare commits

...

5 commits

Author SHA1 Message Date
Vadim
54898ba42e Match extreme exposure pairs & pairs list edge values 2023-10-06 15:42:16 +02:00
Vadim
0776a3b829 dialog picker test 2023-10-06 12:53:08 +02:00
Vadim
c7abfdedb2 ExtremeExposurePairsContainer widget test 2023-10-06 12:04:13 +02:00
Vadim
9203db5d02 Moved Animated dialog picker to widget tests 2023-10-06 11:18:40 +02:00
Vadim
5798916f6f AnimatedDialog picker standalone tests 2023-10-05 23:01:58 +02:00
10 changed files with 701 additions and 3 deletions

View file

@ -7,10 +7,9 @@
"files.watcherExclude": { "files.watcherExclude": {
"**/.fvm": true "**/.fvm": true
}, },
"dart.lineLength": 100, "dart.lineLength": 120,
"[dart]": { "[dart]": {
"editor.rulers": [ "editor.rulers": [
100,
120, 120,
], ],
"editor.selectionHighlight": true, "editor.selectionHighlight": true,

View file

@ -0,0 +1,268 @@
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/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/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 'mocks/paid_features_mock.dart';
import 'utils/expectations.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.camera);
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);
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) async {
await tester.pumpWidget(
MockIAPProviders(
purchaseStatus: purchaseStatus,
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('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));
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',
(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),
);
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);
},
);
});
group(
'Free version',
() {
testWidgets(
'Initial state',
(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);
await tester.openAnimatedPicker<FilmPicker>();
await tester.openAnimatedPicker<IsoValuePicker>();
await tester.openAnimatedPicker<NdValuePicker>();
},
);
},
skip: true,
);
group(
'Pro version',
() {
testWidgets(
'Initial state',
(tester) async {
await pumpApplication(tester, IAPProductStatus.purchased);
},
);
testWidgets(
'Film (push/pull)',
(tester) async {
await pumpApplication(tester, IAPProductStatus.purchased);
},
);
},
skip: true,
);
}
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();
}
}

View file

@ -0,0 +1,105 @@
import 'package:flutter/material.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:shared_preferences/shared_preferences.dart';
class _MockSharedPreferences extends Mock implements SharedPreferences {}
class MockIAPProviders extends StatelessWidget {
final IAPProductStatus purchaseStatus;
final Widget child;
const MockIAPProviders({
required this.purchaseStatus,
required this.child,
super.key,
});
const MockIAPProviders.purchasable({
required this.child,
super.key,
}) : purchaseStatus = IAPProductStatus.purchasable;
const MockIAPProviders.purchased({
required this.child,
super.key,
}) : purchaseStatus = IAPProductStatus.purchased;
@override
Widget build(BuildContext context) {
if (purchaseStatus == IAPProductStatus.purchased) {
return IAPProviders(
sharedPreferences: _MockSharedPreferences(),
child: EquipmentProfiles(
selected: _mockEquipmentProfiles[0],
values: _mockEquipmentProfiles,
child: Films(
selected: const Film('Ilford HP5+', 400),
values: const [Film.other(), Film('Ilford HP5+', 400)],
filmsInUse: const [Film.other(), Film('Ilford HP5+', 400)],
child: child,
),
),
);
}
return IAPProviders(
sharedPreferences: _MockSharedPreferences(),
child: EquipmentProfiles(
selected: _defaultEquipmentProfile,
values: const [_defaultEquipmentProfile],
child: Films(
selected: const Film.other(),
values: const [Film.other()],
filmsInUse: const [Film.other()],
child: child,
),
),
);
}
}
const _defaultEquipmentProfile = EquipmentProfile(
id: '',
name: '',
apertureValues: ApertureValue.values,
ndValues: NdValue.values,
shutterSpeedValues: ShutterSpeedValue.values,
isoValues: IsoValue.values,
);
final _mockEquipmentProfiles = [
_defaultEquipmentProfile,
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

@ -0,0 +1,14 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/screens/settings/components/shared/dialog_picker/widget_dialog_picker.dart';
void expectAnimatedPicker<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);
}
/// Finds exactly one dialog picker of the provided value type
void expectDialogPicker<T>() {
expect(find.byType(DialogPicker<T>), findsOneWidget);
}

View file

@ -33,6 +33,7 @@ class ExposurePairsList extends StatelessWidget {
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
Row( Row(
key: ValueKey(index),
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Expanded( Expanded(

View file

@ -118,7 +118,11 @@ class _DialogPickerState<T> extends State<DialogPicker<T>> {
), ),
const SizedBox(width: Dimens.grid16), const SizedBox(width: Dimens.grid16),
TextButton( TextButton(
onPressed: () => widget.onSelect(_selectedValue), onPressed: () {
if (widget.initialValue != _selectedValue) {
widget.onSelect(_selectedValue);
}
},
child: Text(S.of(context).select), child: Text(S.of(context).select),
), ),
], ],

View file

@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/res/theme.dart';
/// Provides [MaterialApp] with default theme and "en" localization
class WidgetTestApplicationMock extends StatelessWidget {
final Widget child;
const WidgetTestApplicationMock({required this.child, super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: themeFrom(primaryColorsList[5], Brightness.light),
locale: const Locale('en'),
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: child!,
),
home: Scaffold(body: child),
);
}
}

View file

@ -0,0 +1,72 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/data/models/exposure_pair.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/extreme_exposure_pairs_container/widget_container_extreme_exposure_pairs.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import '../../../../../application_mock.dart';
void main() {
testWidgets(
'No exposure pairs',
(tester) async {
await tester.pumpApplication(
fastest: null,
slowest: null,
);
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));
},
);
testWidgets(
'Has pairs',
(tester) async {
await tester.pumpApplication(
fastest: ExposurePair(ApertureValue.values.first, ShutterSpeedValue.values.first),
slowest: ExposurePair(ApertureValue.values.last, ShutterSpeedValue.values.last),
);
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/2000')), findsOneWidget);
expect(find.descendant(of: pickerFinder, matching: find.text('f/45 - 16"')), findsOneWidget);
},
);
}
extension WidgetTesterActions on WidgetTester {
Future<void> pumpApplication({
required ExposurePair? fastest,
required ExposurePair? slowest,
}) async {
await pumpWidget(
Films(
values: const [Film.other()],
filmsInUse: const [Film.other()],
selected: const Film.other(),
child: WidgetTestApplicationMock(
child: Row(
children: [
Expanded(
child: ExtremeExposurePairsContainer(
fastest: fastest,
slowest: slowest,
),
),
],
),
),
),
);
await pumpAndSettle();
}
}

View file

@ -0,0 +1,115 @@
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 '../../../../../../application_mock.dart';
void main() {
group(
'Open & close tests',
() {
testWidgets(
'Open & close with select',
(tester) async {
await tester.pumpApplication();
await tester.openAnimatedPicker<IsoValuePicker>();
expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
await tester.tapSelectButton();
expect(find.byType(DialogPicker<IsoValue>), findsNothing);
},
);
testWidgets(
'Open & close with cancel',
(tester) async {
await tester.pumpApplication();
await tester.openAnimatedPicker<IsoValuePicker>();
expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
await tester.tapCancelButton();
expect(find.byType(DialogPicker<IsoValue>), findsNothing);
},
);
testWidgets(
'Open & close with tap outside',
(tester) async {
await tester.pumpApplication();
await tester.openAnimatedPicker<IsoValuePicker>();
expect(find.byType(DialogPicker<IsoValue>), 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);
},
);
testWidgets(
'Open & close with back gesture',
(tester) async {
await tester.pumpApplication();
await tester.openAnimatedPicker<IsoValuePicker>();
expect(find.byType(DialogPicker<IsoValue>), 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'));
//// await tester.binding.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) {});
/// 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);
},
);
},
);
}
extension WidgetTesterActions on WidgetTester {
Future<void> pumpApplication() async {
await pumpWidget(
WidgetTestApplicationMock(
child: Row(
children: [
Expanded(
child: IsoValuePicker(
selectedValue: const IsoValue(400, StopType.full),
values: IsoValue.values,
onChanged: (_) {},
),
),
],
),
),
);
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,
);
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();
}
}

View file

@ -0,0 +1,89 @@
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:mocktail/mocktail.dart';
import '../../../../../../application_mock.dart';
class _ValueChanged {
void onChanged<T>(T value) {}
}
class _MockValueChanged extends Mock implements _ValueChanged {}
void main() {
final functions = _MockValueChanged();
group(
'onChanged',
() {
testWidgets(
'other',
(tester) async {
await tester.pumpApplication(functions.onChanged);
await tester.openAnimatedPicker<IsoValuePicker>();
expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
await tester.tapListTile(500);
await tester.tapSelectButton();
verify(() => functions.onChanged(const IsoValue(500, StopType.third))).called(1);
},
);
testWidgets(
'same',
(tester) async {
await tester.pumpApplication(functions.onChanged);
await tester.openAnimatedPicker<IsoValuePicker>();
expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
await tester.tapListTile(400);
await tester.tapSelectButton();
verifyNever(() => functions.onChanged(const IsoValue(400, StopType.full)));
},
);
},
);
}
extension WidgetTesterActions on WidgetTester {
Future<void> pumpApplication(ValueChanged<IsoValue> onChanged) async {
await pumpWidget(
WidgetTestApplicationMock(
child: Row(
children: [
Expanded(
child: IsoValuePicker(
selectedValue: const IsoValue(400, StopType.full),
values: IsoValue.values,
onChanged: onChanged,
),
),
],
),
),
);
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')));
}
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();
}
}