FilmPicker tests

This commit is contained in:
Vadim 2023-10-14 19:24:00 +02:00
parent 2e929d3630
commit 1c41abbde9
6 changed files with 117 additions and 45 deletions

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

@ -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,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<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);
},
);
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

@ -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<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:mocktail/mocktail.dart';
import '../../../../../../application_mock.dart';
import '../utils.dart';
class _ValueChanged {
void onChanged<T>(T value) {}
@ -68,11 +68,6 @@ 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')));

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