m3_lightmeter/integration_test/mocks/iap_products_mock.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

45 lines
1.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
@visibleForTesting
class MockIAPProductsProvider extends StatefulWidget {
final bool initialyPurchased;
final Widget child;
const MockIAPProductsProvider({this.initialyPurchased = true, required this.child, super.key});
static MockIAPProductsProviderState of(BuildContext context) => MockIAPProductsProvider.maybeOf(context)!;
static MockIAPProductsProviderState? maybeOf(BuildContext context) {
return context.findAncestorStateOfType<MockIAPProductsProviderState>();
}
@override
State<MockIAPProductsProvider> createState() => MockIAPProductsProviderState();
}
class MockIAPProductsProviderState extends State<MockIAPProductsProvider> {
late bool _purchased = widget.initialyPurchased;
@override
Widget build(BuildContext context) {
return IAPProducts(
products: List.from([
IAPProduct(
storeId: IAPProductType.paidFeatures.storeId,
status: _purchased ? IAPProductStatus.purchased : IAPProductStatus.purchasable,
)
]),
child: widget.child,
);
}
void buy() {
_purchased = true;
setState(() {});
}
void clearPurchases() {
_purchased = false;
setState(() {});
}
}