m3_lightmeter/integration_test/purchases_test.dart
Vadim 7787558713
ML-160 Integration tests (#161)
* test granting and revoking pro features

* extracted common widget tester actions

* test disabling & enabling of the metering screen layout features

* added integration tests to CI

* added integration tests to PR check

* allow matrix jobs to fail

* use base64 -d

* downgraded iphone version to the supported one

* use proper android device name

* typo in macos version

* upgraded iphone version to the supported one

* updated android compileSdkVersion

* added google services json restoration

* combined all tests in one file

* removed ipa signing for ios test

* debug prints :)

* lints

* refined tester extension and expectations

* e2e test (wip)

* added more expectations to e2e test

* changed pickers order a bit in e2e test

* added equipment profiles creation to e2e test

* added film selection to e2e test

* set android emulator API level to 32

* use flutter drive for integration tests

* removed app pre-build

* try running tests only for one platform

* added no-dds to flutter drive

* try running only on ios

* bumped macos version

* increased tests timeout

* set IPHONEOS_DEPLOYMENT_TARGET = 12.0

* removed prints

* Update Podfile

* restore firebase_app_id_file.json

* Delete run_integration_tests.sh

* run e2e with all tests

* reverted pr-check
2024-03-13 15:34:26 +01:00

109 lines
4.9 KiB
Dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/data/models/ev_source_type.dart';
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/equipment_profile_picker/widget_picker_equipment_profiles.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/extreme_exposure_pairs_container/widget_container_extreme_exposure_pairs.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/film_picker/widget_picker_film.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/nd_picker/widget_picker_nd.dart';
import 'package:lightmeter/screens/settings/components/shared/disable/widget_disable.dart';
import 'package:lightmeter/screens/settings/screen_settings.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:meta/meta.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../integration_test/utils/widget_tester_actions.dart';
import 'mocks/iap_products_mock.dart';
@isTest
void testPurchases(String description) {
testWidgets(
description,
(tester) async {
SharedPreferences.setMockInitialValues({
/// Metering values
UserPreferencesService.evSourceTypeKey: EvSourceType.camera.index,
UserPreferencesService.showEv100Key: true,
UserPreferencesService.meteringScreenLayoutKey: json.encode(
{
MeteringScreenLayoutFeature.equipmentProfiles: true,
MeteringScreenLayoutFeature.extremeExposurePairs: true,
MeteringScreenLayoutFeature.filmPicker: true,
}.toJson(),
),
});
await tester.pumpApplication(productStatus: IAPProductStatus.purchasable);
await tester.takePhoto();
/// Expect the bare minimum free functionallity
_expectProMeteringScreen(enabled: false);
/// Check, that premium settings are disabled
await tester.openSettings();
await _expectProSettingsScreen(tester, enabled: false);
/// Make purchase
(tester.state(find.byType(MockIAPProductsProvider)) as MockIAPProductsProviderState).buy();
await tester.pumpAndSettle();
/// Check, that premium settings are enabled
await _expectProSettingsScreen(tester, enabled: true);
/// Expect, that all the premium controls are now available to user
await tester.navigatorPop();
_expectProMeteringScreen(enabled: true);
/// Refund
(tester.state(find.byType(MockIAPProductsProvider)) as MockIAPProductsProviderState).clearPurchases();
await tester.pumpAndSettle();
/// Expect the bare minimum free functionallity
_expectProMeteringScreen(enabled: false);
/// Check, that premium settings are disabled
await tester.openSettings();
await _expectProSettingsScreen(tester, enabled: false);
},
);
}
void _expectProMeteringScreen({required bool enabled}) {
expect(find.byType(EquipmentProfilePicker), enabled ? findsOneWidget : findsNothing);
expect(find.byType(ExtremeExposurePairsContainer), findsOneWidget);
expect(find.byType(FilmPicker), enabled ? findsOneWidget : findsNothing);
expect(find.byType(IsoValuePicker), findsOneWidget);
expect(find.byType(NdValuePicker), findsOneWidget);
expect(
find.descendant(
of: find.byType(MeteringMeasureButton),
matching: find.byWidgetPredicate((widget) => widget is Text && widget.data!.contains('\u2081\u2080\u2080')),
),
enabled ? findsOneWidget : findsNothing,
);
}
Future<void> _expectProSettingsScreen(WidgetTester tester, {required bool enabled}) async {
void expectDisabled(String title, bool disabled) {
find.ancestor(
of: find.text(title),
matching: find.byWidgetPredicate((widget) => widget is Disable && widget.disable == disabled),
);
}
expectDisabled(S.current.showEv100, !enabled);
expectDisabled(S.current.equipmentProfiles, !enabled);
expectDisabled(S.current.filmsInUse, !enabled);
expectDisabled(S.current.cameraFeatures, !enabled);
await tester.tapDescendantTextOf<SettingsScreen>(S.current.meteringScreenLayout);
expectDisabled(S.current.meteringScreenLayoutHintEquipmentProfiles, !enabled);
expectDisabled(S.current.meteringScreenFeatureExtremeExposurePairs, false); // must be always enabled
expectDisabled(S.current.meteringScreenFeatureFilmPicker, !enabled);
await tester.tapCancelButton();
}