From e15d64b10f7857e346c0bce911e2d61a1b76a80c Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Fri, 6 Oct 2023 23:14:04 +0200 Subject: [PATCH] `FilmPicker` widget tests --- .../readings_container/film_picker_test.dart | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 test/screens/metering/components/shared/readings_container/film_picker_test.dart 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 new file mode 100644 index 0000000..5d44bcb --- /dev/null +++ b/test/screens/metering/components/shared/readings_container/film_picker_test.dart @@ -0,0 +1,109 @@ +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/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 '../../../../../application_mock.dart'; + +void main() { + group('Film push/pull label', () { + testWidgets( + 'Film.other()', + (tester) async { + await tester.pumpApplication(_films[0]); + _expectReadingValueContainerText(S.current.film); + _expectReadingValueContainerText(S.current.none); + }, + ); + + testWidgets( + 'Film with the same ISO', + (tester) async { + await tester.pumpApplication(_films[2]); + _expectReadingValueContainerText(S.current.film); + _expectReadingValueContainerText(_films[2].name); + }, + ); + + testWidgets( + 'Film with greater ISO', + (tester) async { + await tester.pumpApplication(_films[3]); + _expectReadingValueContainerText(S.current.filmPull); + _expectReadingValueContainerText(_films[3].name); + }, + ); + + testWidgets( + 'Film with lower ISO', + (tester) async { + await tester.pumpApplication(_films[1]); + _expectReadingValueContainerText(S.current.filmPush); + _expectReadingValueContainerText(_films[1].name); + }, + ); + }); + + testWidgets( + 'Film picker shows only films in use', + (tester) async { + await tester.pumpApplication(_films[1]); + 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); + }, + ); +} + +extension WidgetTesterActions on WidgetTester { + Future pumpApplication(Film selectedFilm) async { + await pumpWidget( + FilmsProvider( + child: Films( + values: _films, + filmsInUse: _films.sublist(0, _films.length - 1), + selected: selectedFilm, + child: const WidgetTestApplicationMock( + child: Row( + children: [ + Expanded( + child: FilmPicker(selectedIso: IsoValue(400, StopType.full)), + ), + ], + ), + ), + ), + ), + ); + await pumpAndSettle(); + } +} + +const _films = [ + Film.other(), + Film('ISO 100 Film', 100), + Film('ISO 400 Film', 400), + 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, + ); +}