From 8cf5d38c37adc4d9b715182e180519b50d84928f Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Fri, 12 Jan 2024 16:03:04 +0100 Subject: [PATCH] fixed tests --- test/application_mock.dart | 8 ++- ..._settings_section_lightmeter_pro_test.dart | 60 ++++++++++++++++++ .../utils/show_buy_pro_dialog_test.dart | 61 ------------------- 3 files changed, 67 insertions(+), 62 deletions(-) create mode 100644 test/screens/settings/components/widget_settings_section_lightmeter_pro_test.dart delete mode 100644 test/screens/settings/utils/show_buy_pro_dialog_test.dart diff --git a/test/application_mock.dart b/test/application_mock.dart index dbcf260..a5aecb3 100644 --- a/test/application_mock.dart +++ b/test/application_mock.dart @@ -2,12 +2,18 @@ import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/res/theme.dart'; +import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; /// Provides [MaterialApp] with default theme and "en" localization class WidgetTestApplicationMock extends StatelessWidget { + final IAPProductStatus productStatus; final Widget child; - const WidgetTestApplicationMock({required this.child, super.key}); + const WidgetTestApplicationMock({ + this.productStatus = IAPProductStatus.purchased, + required this.child, + super.key, + }); @override Widget build(BuildContext context) { diff --git a/test/screens/settings/components/widget_settings_section_lightmeter_pro_test.dart b/test/screens/settings/components/widget_settings_section_lightmeter_pro_test.dart new file mode 100644 index 0000000..1ae99f4 --- /dev/null +++ b/test/screens/settings/components/widget_settings_section_lightmeter_pro_test.dart @@ -0,0 +1,60 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:lightmeter/generated/l10n.dart'; +import 'package:lightmeter/screens/settings/components/lightmeter_pro/components/buy_pro/widget_list_tile_buy_pro.dart'; +import 'package:lightmeter/screens/settings/components/lightmeter_pro/widget_settings_section_lightmeter_pro.dart'; +import 'package:lightmeter/screens/shared/transparent_dialog/widget_dialog_transparent.dart'; +import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; + +import '../../../application_mock.dart'; + +void main() { + Future pumpApplication(WidgetTester tester) async { + await tester.pumpWidget( + IAPProducts( + products: [ + IAPProduct( + storeId: IAPProductType.paidFeatures.storeId, + ), + ], + child: const WidgetTestApplicationMock( + child: LightmeterProSettingsSection(), + ), + ), + ); + await tester.pumpAndSettle(); + } + + testWidgets( + '`showBuyProDialog` and buy', + (tester) async { + await pumpApplication(tester); + await tester.tap(find.byType(BuyProListTile)); + await tester.pumpAndSettle(); + expect(find.byType(TransparentDialog), findsOneWidget); + expect(find.text(S.current.proFeatures), findsNWidgets(2)); + expect(find.text(S.current.cancel), findsOneWidget); + expect(find.text(S.current.unlock), findsOneWidget); + + await tester.tap(find.text(S.current.unlock)); + await tester.pumpAndSettle(); + expect(find.byType(TransparentDialog), findsNothing); + }, + ); + + testWidgets( + '`showBuyProDialog` and cancel', + (tester) async { + await pumpApplication(tester); + await tester.tap(find.byType(BuyProListTile)); + await tester.pumpAndSettle(); + expect(find.byType(TransparentDialog), findsOneWidget); + expect(find.text(S.current.proFeatures), findsNWidgets(2)); + expect(find.text(S.current.cancel), findsOneWidget); + expect(find.text(S.current.unlock), findsOneWidget); + + await tester.tap(find.text(S.current.cancel)); + await tester.pumpAndSettle(); + expect(find.byType(TransparentDialog), findsNothing); + }, + ); +} diff --git a/test/screens/settings/utils/show_buy_pro_dialog_test.dart b/test/screens/settings/utils/show_buy_pro_dialog_test.dart deleted file mode 100644 index 16a8e19..0000000 --- a/test/screens/settings/utils/show_buy_pro_dialog_test.dart +++ /dev/null @@ -1,61 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:lightmeter/data/models/feature.dart'; -import 'package:lightmeter/generated/l10n.dart'; -import 'package:lightmeter/providers/remote_config_provider.dart'; -import 'package:lightmeter/screens/settings/utils/show_buy_pro_dialog.dart'; - -import '../../../application_mock.dart'; - -void main() { - Future pumpApplication(WidgetTester tester) async { - await tester.pumpWidget( - RemoteConfig( - config: const {Feature.unlockProFeaturesText: false}, - child: WidgetTestApplicationMock( - child: Builder( - builder: (context) => ElevatedButton( - onPressed: () => showBuyProDialog(context), - child: const SizedBox(), - ), - ), - ), - ), - ); - await tester.pumpAndSettle(); - } - - testWidgets( - '`showBuyProDialog` and buy', - (tester) async { - await pumpApplication(tester); - await tester.tap(find.byType(ElevatedButton)); - await tester.pumpAndSettle(); - expect(find.byType(AlertDialog), findsOneWidget); - expect(find.text(S.current.lightmeterPro), findsOneWidget); - expect(find.text(S.current.cancel), findsOneWidget); - expect(find.text(S.current.buy), findsOneWidget); - - await tester.tap(find.text(S.current.buy)); - await tester.pumpAndSettle(); - expect(find.byType(AlertDialog), findsNothing); - }, - ); - - testWidgets( - '`showBuyProDialog` and cancel', - (tester) async { - await pumpApplication(tester); - await tester.tap(find.byType(ElevatedButton)); - await tester.pumpAndSettle(); - expect(find.byType(AlertDialog), findsOneWidget); - expect(find.text(S.current.lightmeterPro), findsOneWidget); - expect(find.text(S.current.cancel), findsOneWidget); - expect(find.text(S.current.buy), findsOneWidget); - - await tester.tap(find.text(S.current.cancel)); - await tester.pumpAndSettle(); - expect(find.byType(AlertDialog), findsNothing); - }, - ); -}