fixed tests

This commit is contained in:
Vadim 2024-01-12 16:03:04 +01:00
parent 084138a23f
commit 8cf5d38c37
3 changed files with 67 additions and 62 deletions

View file

@ -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) {

View file

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

View file

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