From 73ebc671f2fa07fd654d04af40d39e6678fe06eb Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Wed, 1 Nov 2023 21:38:14 +0100 Subject: [PATCH] `showBuyProDialog` tests --- .../buy_pro/widget_list_tile_buy_pro.dart | 2 +- .../utils/show_buy_pro_dialog.dart | 2 +- pubspec.yaml | 2 +- .../utils/show_buy_pro_dialog_test.dart | 61 +++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) rename lib/screens/settings/{components => }/utils/show_buy_pro_dialog.dart (94%) create mode 100644 test/screens/settings/utils/show_buy_pro_dialog_test.dart diff --git a/lib/screens/settings/components/lightmeter_pro/components/buy_pro/widget_list_tile_buy_pro.dart b/lib/screens/settings/components/lightmeter_pro/components/buy_pro/widget_list_tile_buy_pro.dart index 5f8adcd..854a914 100644 --- a/lib/screens/settings/components/lightmeter_pro/components/buy_pro/widget_list_tile_buy_pro.dart +++ b/lib/screens/settings/components/lightmeter_pro/components/buy_pro/widget_list_tile_buy_pro.dart @@ -4,7 +4,7 @@ import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/providers/remote_config_provider.dart'; import 'package:lightmeter/providers/services_provider.dart'; import 'package:lightmeter/res/dimens.dart'; -import 'package:lightmeter/screens/settings/components/utils/show_buy_pro_dialog.dart'; +import 'package:lightmeter/screens/settings/utils/show_buy_pro_dialog.dart'; import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; class BuyProListTile extends StatelessWidget { diff --git a/lib/screens/settings/components/utils/show_buy_pro_dialog.dart b/lib/screens/settings/utils/show_buy_pro_dialog.dart similarity index 94% rename from lib/screens/settings/components/utils/show_buy_pro_dialog.dart rename to lib/screens/settings/utils/show_buy_pro_dialog.dart index 50edbd1..7ce3ff6 100644 --- a/lib/screens/settings/components/utils/show_buy_pro_dialog.dart +++ b/lib/screens/settings/utils/show_buy_pro_dialog.dart @@ -28,7 +28,7 @@ Future showBuyProDialog(BuildContext context) { FilledButton( onPressed: () { Navigator.of(context).pop(); - IAPProductsProvider.of(context).buy(IAPProductType.paidFeatures); + IAPProductsProvider.maybeOf(context)?.buy(IAPProductType.paidFeatures); }, child: Text(unlockFeaturesEnabled ? S.of(context).unlock : S.of(context).buy), ), diff --git a/pubspec.yaml b/pubspec.yaml index 6fd97bc..ed5fc90 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -28,7 +28,7 @@ dependencies: m3_lightmeter_iap: git: url: "https://github.com/vodemn/m3_lightmeter_iap" - ref: v0.6.3 + ref: v0.7.0 m3_lightmeter_resources: git: url: "https://github.com/vodemn/m3_lightmeter_resources" diff --git a/test/screens/settings/utils/show_buy_pro_dialog_test.dart b/test/screens/settings/utils/show_buy_pro_dialog_test.dart new file mode 100644 index 0000000..16a8e19 --- /dev/null +++ b/test/screens/settings/utils/show_buy_pro_dialog_test.dart @@ -0,0 +1,61 @@ +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); + }, + ); +}