From c7abfdedb22ef365f974e0da43290c821c84935e Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Fri, 6 Oct 2023 12:04:13 +0200 Subject: [PATCH] `ExtremeExposurePairsContainer` widget test --- test/application_mock.dart | 31 ++++++++ ...extreme_exposure_pairs_container_test.dart | 72 +++++++++++++++++++ .../shared}/animated_dialog_picker_test.dart | 40 ++++------- 3 files changed, 115 insertions(+), 28 deletions(-) create mode 100644 test/application_mock.dart create mode 100644 test/screens/metering/components/shared/readings_container/extreme_exposure_pairs_container_test.dart rename test/screens/metering/components/shared/{ => readings_container/shared}/animated_dialog_picker_test.dart (79%) diff --git a/test/application_mock.dart b/test/application_mock.dart new file mode 100644 index 0000000..dbcf260 --- /dev/null +++ b/test/application_mock.dart @@ -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), + ); + } +} diff --git a/test/screens/metering/components/shared/readings_container/extreme_exposure_pairs_container_test.dart b/test/screens/metering/components/shared/readings_container/extreme_exposure_pairs_container_test.dart new file mode 100644 index 0000000..4692ee6 --- /dev/null +++ b/test/screens/metering/components/shared/readings_container/extreme_exposure_pairs_container_test.dart @@ -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 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(); + } +} diff --git a/test/screens/metering/components/shared/animated_dialog_picker_test.dart b/test/screens/metering/components/shared/readings_container/shared/animated_dialog_picker_test.dart similarity index 79% rename from test/screens/metering/components/shared/animated_dialog_picker_test.dart rename to test/screens/metering/components/shared/readings_container/shared/animated_dialog_picker_test.dart index 73af0b3..b303a03 100644 --- a/test/screens/metering/components/shared/animated_dialog_picker_test.dart +++ b/test/screens/metering/components/shared/readings_container/shared/animated_dialog_picker_test.dart @@ -1,13 +1,13 @@ import 'package:flutter/material.dart'; -import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/res/dimens.dart'; -import 'package:lightmeter/res/theme.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', @@ -73,33 +73,17 @@ void main() { extension WidgetTesterActions on WidgetTester { Future pumpApplication() async { await pumpWidget( - MaterialApp( - title: 'Flutter Demo', - 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: Row( - children: [ - Expanded( - child: IsoValuePicker( - selectedValue: const IsoValue(400, StopType.full), - values: IsoValue.values, - onChanged: (_) {}, - ), + WidgetTestApplicationMock( + child: Row( + children: [ + Expanded( + child: IsoValuePicker( + selectedValue: const IsoValue(400, StopType.full), + values: IsoValue.values, + onChanged: (_) {}, ), - ], - ), + ), + ], ), ), );