showBuyProDialog tests

This commit is contained in:
Vadim 2023-11-01 21:38:14 +01:00
parent a41add2f97
commit 73ebc671f2
4 changed files with 64 additions and 3 deletions

View file

@ -4,7 +4,7 @@ import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/remote_config_provider.dart'; import 'package:lightmeter/providers/remote_config_provider.dart';
import 'package:lightmeter/providers/services_provider.dart'; import 'package:lightmeter/providers/services_provider.dart';
import 'package:lightmeter/res/dimens.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'; import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
class BuyProListTile extends StatelessWidget { class BuyProListTile extends StatelessWidget {

View file

@ -28,7 +28,7 @@ Future<void> showBuyProDialog(BuildContext context) {
FilledButton( FilledButton(
onPressed: () { onPressed: () {
Navigator.of(context).pop(); 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), child: Text(unlockFeaturesEnabled ? S.of(context).unlock : S.of(context).buy),
), ),

View file

@ -28,7 +28,7 @@ dependencies:
m3_lightmeter_iap: m3_lightmeter_iap:
git: git:
url: "https://github.com/vodemn/m3_lightmeter_iap" url: "https://github.com/vodemn/m3_lightmeter_iap"
ref: v0.6.3 ref: v0.7.0
m3_lightmeter_resources: m3_lightmeter_resources:
git: git:
url: "https://github.com/vodemn/m3_lightmeter_resources" url: "https://github.com/vodemn/m3_lightmeter_resources"

View file

@ -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<void> 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);
},
);
}