From 1c41abbde94cb96ec28106e32e7104c1bd5e1f2e Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Sat, 14 Oct 2023 19:24:00 +0200 Subject: [PATCH] `FilmPicker` tests --- .../nd_picker/widget_picker_nd.dart | 7 +- .../readings_container/film_picker_test.dart | 44 ++++-------- .../readings_container/nd_picker_test.dart | 71 +++++++++++++++++++ .../shared/animated_dialog_test.dart | 6 +- .../shared/dialog_picker_test.dart | 7 +- .../shared/readings_container/utils.dart | 27 +++++++ 6 files changed, 117 insertions(+), 45 deletions(-) create mode 100644 test/screens/metering/components/shared/readings_container/nd_picker_test.dart create mode 100644 test/screens/metering/components/shared/readings_container/utils.dart diff --git a/lib/screens/metering/components/shared/readings_container/components/nd_picker/widget_picker_nd.dart b/lib/screens/metering/components/shared/readings_container/components/nd_picker/widget_picker_nd.dart index eda016c..fdd8f0a 100644 --- a/lib/screens/metering/components/shared/readings_container/components/nd_picker/widget_picker_nd.dart +++ b/lib/screens/metering/components/shared/readings_container/components/nd_picker/widget_picker_nd.dart @@ -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(), ), ), ); diff --git a/test/screens/metering/components/shared/readings_container/film_picker_test.dart b/test/screens/metering/components/shared/readings_container/film_picker_test.dart index 8cc4d38..19f4840 100644 --- a/test/screens/metering/components/shared/readings_container/film_picker_test.dart +++ b/test/screens/metering/components/shared/readings_container/film_picker_test.dart @@ -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(); + expectRadioListTile(S.current.none, isSelected: true); + expectRadioListTile(_films[1].name); + expectRadioListTile(_films[2].name); + expectRadioListTile(_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), matching: find.text(filmName)), - findsOneWidget, - ); -} diff --git a/test/screens/metering/components/shared/readings_container/nd_picker_test.dart b/test/screens/metering/components/shared/readings_container/nd_picker_test.dart new file mode 100644 index 0000000..3deb824 --- /dev/null +++ b/test/screens/metering/components/shared/readings_container/nd_picker_test.dart @@ -0,0 +1,71 @@ +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 pumpApplication( + WidgetTester tester, { + List 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(); + expect(find.byIcon(Icons.filter_b_and_w), findsOneWidget); + expectDialogPickerText(S.current.nd); + expectDialogPickerText(S.current.ndFilterFactor); + }, + ); + + group( + 'Display selected value', + () { + testWidgets( + 'None', + (tester) async { + await pumpApplication(tester); + expectReadingValueContainerText(S.current.none); + await tester.openAnimatedPicker(); + expectRadioListTile(S.current.none, isSelected: true); + }, + ); + + testWidgets( + 'ND2', + (tester) async { + await pumpApplication(tester, selectedValue: const NdValue(2)); + expectReadingValueContainerText('2'); + await tester.openAnimatedPicker(); + expectRadioListTile('2', isSelected: true); + }, + ); + }, + ); +} diff --git a/test/screens/metering/components/shared/readings_container/shared/animated_dialog_test.dart b/test/screens/metering/components/shared/readings_container/shared/animated_dialog_test.dart index 86d2b73..b7481ea 100644 --- a/test/screens/metering/components/shared/readings_container/shared/animated_dialog_test.dart +++ b/test/screens/metering/components/shared/readings_container/shared/animated_dialog_test.dart @@ -7,6 +7,7 @@ import 'package:lightmeter/screens/metering/components/shared/readings_container import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import '../../../../../../application_mock.dart'; +import '../utils.dart'; void main() { group( @@ -90,11 +91,6 @@ extension WidgetTesterActions on WidgetTester { await pumpAndSettle(); } - Future openAnimatedPicker() async { - await tap(find.byType(T)); - await pumpAndSettle(Dimens.durationL); - } - Future tapSelectButton() async { final cancelButton = find.byWidgetPredicate( (widget) => widget is TextButton && widget.child is Text && (widget.child as Text?)?.data == S.current.select, diff --git a/test/screens/metering/components/shared/readings_container/shared/dialog_picker_test.dart b/test/screens/metering/components/shared/readings_container/shared/dialog_picker_test.dart index 88c9961..0e80b8c 100644 --- a/test/screens/metering/components/shared/readings_container/shared/dialog_picker_test.dart +++ b/test/screens/metering/components/shared/readings_container/shared/dialog_picker_test.dart @@ -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:mocktail/mocktail.dart'; import '../../../../../../application_mock.dart'; +import '../utils.dart'; class _ValueChanged { void onChanged(T value) {} @@ -68,11 +68,6 @@ extension WidgetTesterActions on WidgetTester { await pumpAndSettle(); } - Future openAnimatedPicker() async { - await tap(find.byType(T)); - await pumpAndSettle(Dimens.durationL); - } - Future tapListTile(int iso) async { expect(find.descendant(of: find.byType(RadioListTile), matching: find.text('$iso')), findsOneWidget); await tap(find.descendant(of: find.byType(RadioListTile), matching: find.text('$iso'))); diff --git a/test/screens/metering/components/shared/readings_container/utils.dart b/test/screens/metering/components/shared/readings_container/utils.dart new file mode 100644 index 0000000..0ffba27 --- /dev/null +++ b/test/screens/metering/components/shared/readings_container/utils.dart @@ -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 openAnimatedPicker() async { + await tap(find.byType(T)); + await pumpAndSettle(Dimens.durationL); + } +} + +void expectReadingValueContainerText(String text) => _expectTextDescendantOf(text); + +void expectDialogPickerText(String text) => _expectTextDescendantOf>(text); + +void _expectTextDescendantOf(String text) { + expect(find.descendant(of: find.byType(T), matching: find.text(text)), findsOneWidget); +} + +void expectRadioListTile(String text, {bool isSelected = false}) { + expect( + find.descendant(of: find.byType(RadioListTile), matching: find.text(text)), + findsOneWidget, + ); +}