ExtremeExposurePairsContainer widget test

This commit is contained in:
Vadim 2023-10-06 12:04:13 +02:00
parent 9203db5d02
commit c7abfdedb2
3 changed files with 115 additions and 28 deletions

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

@ -1,13 +1,13 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/res/dimens.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/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: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:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import '../../../../../../application_mock.dart';
void main() { void main() {
group( group(
'Open & close tests', 'Open & close tests',
@ -73,23 +73,8 @@ void main() {
extension WidgetTesterActions on WidgetTester { extension WidgetTesterActions on WidgetTester {
Future<void> pumpApplication() async { Future<void> pumpApplication() async {
await pumpWidget( await pumpWidget(
MaterialApp( WidgetTestApplicationMock(
title: 'Flutter Demo', child: Row(
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: [ children: [
Expanded( Expanded(
child: IsoValuePicker( child: IsoValuePicker(
@ -101,7 +86,6 @@ extension WidgetTesterActions on WidgetTester {
], ],
), ),
), ),
),
); );
await pumpAndSettle(); await pumpAndSettle();
} }