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

135 lines
4.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:lightmeter/providers/equipment_profile_provider.dart';
import 'package:lightmeter/providers/films_provider.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:mocktail/mocktail.dart';
class _MockIAPStorageService extends Mock implements IAPStorageService {}
class MockIAPProviders extends StatefulWidget {
final List<EquipmentProfile>? equipmentProfiles;
final String selectedEquipmentProfileId;
final List<Film>? films;
final Film selectedFilm;
final Widget child;
const MockIAPProviders({
this.equipmentProfiles = const [],
this.selectedEquipmentProfileId = '',
this.films = mockFilms,
this.selectedFilm = const Film.other(),
required this.child,
super.key,
});
@override
State<MockIAPProviders> createState() => _MockIAPProvidersState();
}
class _MockIAPProvidersState extends State<MockIAPProviders> {
late final _MockIAPStorageService mockIAPStorageService;
@override
void initState() {
super.initState();
mockIAPStorageService = _MockIAPStorageService();
when(() => mockIAPStorageService.equipmentProfiles).thenReturn(widget.equipmentProfiles ?? mockEquipmentProfiles);
when(() => mockIAPStorageService.selectedEquipmentProfileId).thenReturn(widget.selectedEquipmentProfileId);
when(() => mockIAPStorageService.filmsInUse).thenReturn(widget.films ?? mockFilms);
when(() => mockIAPStorageService.selectedFilm).thenReturn(widget.selectedFilm);
}
@override
Widget build(BuildContext context) {
return EquipmentProfileProvider(
storageService: mockIAPStorageService,
child: FilmsProvider(
storageService: mockIAPStorageService,
availableFilms: mockFilms,
child: widget.child,
),
);
}
}
const defaultEquipmentProfile = EquipmentProfile(
id: '',
name: '',
apertureValues: ApertureValue.values,
ndValues: NdValue.values,
shutterSpeedValues: ShutterSpeedValue.values,
isoValues: IsoValue.values,
);
final mockEquipmentProfiles = [
EquipmentProfile(
id: '1',
name: 'Praktica + Zenitar',
apertureValues: ApertureValue.values.sublist(
ApertureValue.values.indexOf(const ApertureValue(1.7, StopType.half)),
ApertureValue.values.indexOf(const ApertureValue(16, StopType.full)) + 1,
),
ndValues: const [
NdValue(0),
NdValue(2),
NdValue(4),
NdValue(8),
],
shutterSpeedValues: ShutterSpeedValue.values.sublist(
ShutterSpeedValue.values.indexOf(const ShutterSpeedValue(1000, true, StopType.full)),
ShutterSpeedValue.values.indexOf(const ShutterSpeedValue(16, false, StopType.full)) + 1,
),
isoValues: const [
IsoValue(50, StopType.full),
IsoValue(100, StopType.full),
IsoValue(200, StopType.full),
IsoValue(250, StopType.third),
IsoValue(400, StopType.full),
IsoValue(500, StopType.third),
IsoValue(800, StopType.full),
IsoValue(1600, StopType.full),
IsoValue(3200, StopType.full),
],
),
EquipmentProfile(
id: '2',
name: 'Praktica + Jupiter',
apertureValues: ApertureValue.values.sublist(
ApertureValue.values.indexOf(const ApertureValue(3.5, StopType.third)),
ApertureValue.values.indexOf(const ApertureValue(22, StopType.full)) + 1,
),
ndValues: const [
NdValue(0),
NdValue(2),
NdValue(4),
NdValue(8),
],
shutterSpeedValues: ShutterSpeedValue.values.sublist(
ShutterSpeedValue.values.indexOf(const ShutterSpeedValue(1000, true, StopType.full)),
ShutterSpeedValue.values.indexOf(const ShutterSpeedValue(16, false, StopType.full)) + 1,
),
isoValues: const [
IsoValue(50, StopType.full),
IsoValue(100, StopType.full),
IsoValue(200, StopType.full),
IsoValue(250, StopType.third),
IsoValue(400, StopType.full),
IsoValue(500, StopType.third),
IsoValue(800, StopType.full),
IsoValue(1600, StopType.full),
IsoValue(3200, StopType.full),
],
),
];
const mockFilms = [_MockFilm(100, 2), _MockFilm(400, 2), _MockFilm(3, 800), _MockFilm(400, 1.5)];
class _MockFilm extends Film {
final double reciprocityMultiplier;
const _MockFilm(int iso, this.reciprocityMultiplier) : super('Mock film $iso x$reciprocityMultiplier', iso);
@override
double reciprocityFormula(double t) => t * reciprocityMultiplier;
}