mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 15:30:59 +00:00
Compare commits
3 commits
b68e6384d9
...
e91d0f88c7
Author | SHA1 | Date | |
---|---|---|---|
|
e91d0f88c7 | ||
|
4f1908c200 | ||
|
5a06669372 |
8 changed files with 206 additions and 251 deletions
|
@ -1,200 +1,129 @@
|
||||||
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:integration_test/integration_test.dart';
|
import 'package:integration_test/integration_test.dart';
|
||||||
import 'package:lightmeter/application.dart';
|
|
||||||
import 'package:lightmeter/data/caffeine_service.dart';
|
|
||||||
import 'package:lightmeter/data/haptics_service.dart';
|
|
||||||
import 'package:lightmeter/data/light_sensor_service.dart';
|
|
||||||
import 'package:lightmeter/data/models/ev_source_type.dart';
|
import 'package:lightmeter/data/models/ev_source_type.dart';
|
||||||
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||||
import 'package:lightmeter/data/models/supported_locale.dart';
|
|
||||||
import 'package:lightmeter/data/models/theme_type.dart';
|
import 'package:lightmeter/data/models/theme_type.dart';
|
||||||
import 'package:lightmeter/data/models/volume_action.dart';
|
import 'package:lightmeter/data/models/volume_action.dart';
|
||||||
import 'package:lightmeter/data/permissions_service.dart';
|
|
||||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||||
import 'package:lightmeter/data/volume_events_service.dart';
|
|
||||||
import 'package:lightmeter/environment.dart';
|
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/services_provider.dart';
|
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
import 'package:lightmeter/res/theme.dart';
|
import 'package:lightmeter/res/theme.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.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/iso_picker/widget_picker_iso.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/shared/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart';
|
|
||||||
import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/widget_container_equipment_profile.dart';
|
import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/widget_container_equipment_profile.dart';
|
||||||
import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart';
|
|
||||||
import 'package:lightmeter/screens/settings/screen_settings.dart';
|
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
import 'package:mocktail/mocktail.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
|
||||||
|
|
||||||
import 'mocks/paid_features_mock.dart';
|
import 'utils/platform_channel_mock.dart';
|
||||||
|
import 'utils/widget_tester_actions.dart';
|
||||||
class _MockUserPreferencesService extends Mock implements UserPreferencesService {}
|
|
||||||
|
|
||||||
class _MockCaffeineService extends Mock implements CaffeineService {}
|
|
||||||
|
|
||||||
class _MockHapticsService extends Mock implements HapticsService {}
|
|
||||||
|
|
||||||
class _MockPermissionsService extends Mock implements PermissionsService {}
|
|
||||||
|
|
||||||
class _MockLightSensorService extends Mock implements LightSensorService {}
|
|
||||||
|
|
||||||
class _MockVolumeEventsService extends Mock implements VolumeEventsService {}
|
|
||||||
|
|
||||||
//https://stackoverflow.com/a/67186625/13167574
|
//https://stackoverflow.com/a/67186625/13167574
|
||||||
void main() {
|
void main() {
|
||||||
late _MockUserPreferencesService mockUserPreferencesService;
|
|
||||||
late _MockCaffeineService mockCaffeineService;
|
|
||||||
late _MockHapticsService mockHapticsService;
|
|
||||||
late _MockPermissionsService mockPermissionsService;
|
|
||||||
late _MockLightSensorService mockLightSensorService;
|
|
||||||
late _MockVolumeEventsService mockVolumeEventsService;
|
|
||||||
|
|
||||||
final binding = IntegrationTestWidgetsFlutterBinding();
|
final binding = IntegrationTestWidgetsFlutterBinding();
|
||||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
final Color lightThemeColor = primaryColorsList[5];
|
||||||
|
final Color darkThemeColor = primaryColorsList[3];
|
||||||
|
|
||||||
setUpAll(() {
|
void mockSharedPrefs(ThemeType theme, Color color) {
|
||||||
mockUserPreferencesService = _MockUserPreferencesService();
|
SharedPreferences.setMockInitialValues({
|
||||||
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.camera);
|
/// Metering values
|
||||||
when(() => mockUserPreferencesService.stopType).thenReturn(StopType.third);
|
UserPreferencesService.evSourceTypeKey: EvSourceType.camera.index,
|
||||||
when(() => mockUserPreferencesService.locale).thenReturn(SupportedLocale.en);
|
UserPreferencesService.isoKey: 400,
|
||||||
when(() => mockUserPreferencesService.caffeine).thenReturn(true);
|
UserPreferencesService.ndFilterKey: 0,
|
||||||
when(() => mockUserPreferencesService.volumeAction).thenReturn(VolumeAction.shutter);
|
|
||||||
when(() => mockUserPreferencesService.cameraEvCalibration).thenReturn(0.0);
|
|
||||||
when(() => mockUserPreferencesService.lightSensorEvCalibration).thenReturn(0.0);
|
|
||||||
when(() => mockUserPreferencesService.iso).thenReturn(const IsoValue(400, StopType.full));
|
|
||||||
when(() => mockUserPreferencesService.ndFilter).thenReturn(NdValue.values.first);
|
|
||||||
when(() => mockUserPreferencesService.haptics).thenReturn(true);
|
|
||||||
when(() => mockUserPreferencesService.meteringScreenLayout).thenReturn({
|
|
||||||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
|
||||||
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
|
||||||
MeteringScreenLayoutFeature.filmPicker: true,
|
|
||||||
MeteringScreenLayoutFeature.histogram: false,
|
|
||||||
});
|
|
||||||
when(() => mockUserPreferencesService.themeType).thenReturn(ThemeType.light);
|
|
||||||
when(() => mockUserPreferencesService.dynamicColor).thenReturn(false);
|
|
||||||
|
|
||||||
mockCaffeineService = _MockCaffeineService();
|
/// Metering settings
|
||||||
when(() => mockCaffeineService.isKeepScreenOn()).thenAnswer((_) async => false);
|
UserPreferencesService.stopTypeKey: StopType.third.index,
|
||||||
when(() => mockCaffeineService.keepScreenOn(true)).thenAnswer((_) async => true);
|
UserPreferencesService.cameraEvCalibrationKey: 0.0,
|
||||||
when(() => mockCaffeineService.keepScreenOn(false)).thenAnswer((_) async => false);
|
UserPreferencesService.lightSensorEvCalibrationKey: 0.0,
|
||||||
|
UserPreferencesService.meteringScreenLayoutKey: json.encode(
|
||||||
mockHapticsService = _MockHapticsService();
|
{
|
||||||
when(() => mockHapticsService.quickVibration()).thenAnswer((_) async {});
|
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||||
when(() => mockHapticsService.responseVibration()).thenAnswer((_) async {});
|
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
||||||
when(() => mockHapticsService.errorVibration()).thenAnswer((_) async {});
|
MeteringScreenLayoutFeature.filmPicker: true,
|
||||||
|
MeteringScreenLayoutFeature.histogram: false,
|
||||||
mockPermissionsService = _MockPermissionsService();
|
}.toJson(),
|
||||||
when(() => mockPermissionsService.requestCameraPermission())
|
|
||||||
.thenAnswer((_) async => PermissionStatus.granted);
|
|
||||||
when(() => mockPermissionsService.checkCameraPermission())
|
|
||||||
.thenAnswer((_) async => PermissionStatus.granted);
|
|
||||||
|
|
||||||
mockLightSensorService = _MockLightSensorService();
|
|
||||||
when(() => mockLightSensorService.hasSensor()).thenAnswer((_) async => true);
|
|
||||||
when(() => mockLightSensorService.luxStream()).thenAnswer((_) => Stream.fromIterable([100]));
|
|
||||||
|
|
||||||
mockVolumeEventsService = _MockVolumeEventsService();
|
|
||||||
when(() => mockVolumeEventsService.setVolumeHandling(true)).thenAnswer((_) async => true);
|
|
||||||
when(() => mockVolumeEventsService.setVolumeHandling(false)).thenAnswer((_) async => false);
|
|
||||||
when(() => mockVolumeEventsService.volumeButtonsEventStream())
|
|
||||||
.thenAnswer((_) => const Stream<int>.empty());
|
|
||||||
|
|
||||||
when(() => mockHapticsService.quickVibration()).thenAnswer((_) async {});
|
|
||||||
when(() => mockHapticsService.responseVibration()).thenAnswer((_) async {});
|
|
||||||
});
|
|
||||||
|
|
||||||
Future<void> pumpApplication(WidgetTester tester) async {
|
|
||||||
await tester.pumpWidget(
|
|
||||||
MockIAPProviders.purchased(
|
|
||||||
selectedFilm: mockFilms.first,
|
|
||||||
child: ServicesProvider(
|
|
||||||
environment: const Environment.prod().copyWith(hasLightSensor: true),
|
|
||||||
userPreferencesService: mockUserPreferencesService,
|
|
||||||
caffeineService: mockCaffeineService,
|
|
||||||
hapticsService: mockHapticsService,
|
|
||||||
permissionsService: mockPermissionsService,
|
|
||||||
lightSensorService: mockLightSensorService,
|
|
||||||
volumeEventsService: mockVolumeEventsService,
|
|
||||||
child: const UserPreferencesProvider(child: Application()),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
|
||||||
await tester.pumpAndSettle();
|
/// General settings
|
||||||
|
UserPreferencesService.caffeineKey: true,
|
||||||
|
UserPreferencesService.hapticsKey: true,
|
||||||
|
UserPreferencesService.volumeActionKey: VolumeAction.shutter.toString(),
|
||||||
|
UserPreferencesService.localeKey: 'en',
|
||||||
|
|
||||||
|
/// Theme settings
|
||||||
|
UserPreferencesService.themeTypeKey: theme.index,
|
||||||
|
UserPreferencesService.primaryColorKey: color.value,
|
||||||
|
UserPreferencesService.dynamicColorKey: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates several screenshots with the light theme
|
/// Generates several screenshots with the light theme
|
||||||
/// and the additionally the first one with the dark theme
|
testWidgets(
|
||||||
void generateScreenshots(Color color) {
|
'Generate light theme screenshots',
|
||||||
testWidgets('${color.value}_light', (tester) async {
|
(tester) async {
|
||||||
when(() => mockUserPreferencesService.themeType).thenReturn(ThemeType.light);
|
mockSharedPrefs(ThemeType.light, lightThemeColor);
|
||||||
when(() => mockUserPreferencesService.primaryColor).thenReturn(color);
|
await tester.pumpApplication();
|
||||||
await pumpApplication(tester);
|
|
||||||
|
|
||||||
await tester.takePhoto();
|
await tester.takePhoto();
|
||||||
await tester.takeScreenshot(binding, '${color.value}_metering_reflected');
|
await tester.takeScreenshot(binding, '${lightThemeColor.value}_metering_reflected');
|
||||||
|
|
||||||
await tester.tap(find.byTooltip(S.current.tooltipUseLightSensor));
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
await tester.tap(find.byType(MeteringMeasureButton));
|
|
||||||
await tester.tap(find.byType(MeteringMeasureButton));
|
|
||||||
await tester.takeScreenshot(binding, '${color.value}_metering_incident');
|
|
||||||
|
|
||||||
expect(find.byType(IsoValuePicker), findsOneWidget);
|
|
||||||
await tester.tap(find.byType(IsoValuePicker));
|
|
||||||
await tester.pumpAndSettle(Dimens.durationL);
|
|
||||||
expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
|
|
||||||
await tester.takeScreenshot(binding, '${color.value}_metering_iso_picker');
|
|
||||||
|
|
||||||
await tester.tapCancelButton();
|
|
||||||
expect(find.byType(DialogPicker<IsoValue>), findsNothing);
|
|
||||||
expect(find.byTooltip(S.current.tooltipOpenSettings), findsOneWidget);
|
|
||||||
await tester.tap(find.byTooltip(S.current.tooltipOpenSettings));
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
expect(find.byType(SettingsScreen), findsOneWidget);
|
|
||||||
await tester.takeScreenshot(binding, '${color.value}_settings');
|
|
||||||
|
|
||||||
await tester.tapListTile(S.current.meteringScreenLayout);
|
|
||||||
await tester.takeScreenshot(binding, '${color.value}_settings_metering_screen_layout');
|
|
||||||
|
|
||||||
await tester.tapCancelButton();
|
|
||||||
await tester.tapListTile(S.current.equipmentProfiles);
|
|
||||||
expect(find.byType(EquipmentProfilesScreen), findsOneWidget);
|
|
||||||
await tester.tap(find.byType(EquipmentProfileContainer).first);
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
await tester.takeScreenshot(binding, '${color.value}-equipment_profiles');
|
|
||||||
|
|
||||||
await tester.tap(find.byIcon(Icons.iso).first);
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
await tester.takeScreenshot(binding, '${color.value}_equipment_profiles_iso_picker');
|
|
||||||
});
|
|
||||||
|
|
||||||
testWidgets(
|
|
||||||
'${color.value}_dark',
|
|
||||||
(tester) async {
|
|
||||||
when(() => mockUserPreferencesService.themeType).thenReturn(ThemeType.dark);
|
|
||||||
when(() => mockUserPreferencesService.primaryColor).thenReturn(color);
|
|
||||||
await pumpApplication(tester);
|
|
||||||
|
|
||||||
await tester.takePhoto();
|
|
||||||
await tester.takeScreenshot(binding, '${color.value}_metering_reflected_dark');
|
|
||||||
|
|
||||||
|
if (Platform.isAndroid) {
|
||||||
await tester.tap(find.byTooltip(S.current.tooltipUseLightSensor));
|
await tester.tap(find.byTooltip(S.current.tooltipUseLightSensor));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
await tester.tap(find.byType(MeteringMeasureButton));
|
await tester.tap(find.byType(MeteringMeasureButton));
|
||||||
|
await sendMockIncidentEv(7.3);
|
||||||
await tester.tap(find.byType(MeteringMeasureButton));
|
await tester.tap(find.byType(MeteringMeasureButton));
|
||||||
await tester.takeScreenshot(binding, '${color.value}_metering_incident_dark');
|
await tester.takeScreenshot(binding, '${lightThemeColor.value}_metering_incident');
|
||||||
},
|
}
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
generateScreenshots(primaryColorsList[5]);
|
await tester.tap(find.byType(IsoValuePicker));
|
||||||
generateScreenshots(primaryColorsList[3]);
|
await tester.pumpAndSettle(Dimens.durationL);
|
||||||
generateScreenshots(primaryColorsList[9]);
|
await tester.takeScreenshot(binding, '${lightThemeColor.value}_metering_iso_picker');
|
||||||
|
|
||||||
|
await tester.tapCancelButton();
|
||||||
|
await tester.tap(find.byTooltip(S.current.tooltipOpenSettings));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.takeScreenshot(binding, '${lightThemeColor.value}_settings');
|
||||||
|
|
||||||
|
await tester.tapListTile(S.current.meteringScreenLayout);
|
||||||
|
await tester.takeScreenshot(binding, '${lightThemeColor.value}_settings_metering_screen_layout');
|
||||||
|
|
||||||
|
await tester.tapCancelButton();
|
||||||
|
await tester.tapListTile(S.current.equipmentProfiles);
|
||||||
|
await tester.tap(find.byType(EquipmentProfileContainer).first);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.takeScreenshot(binding, '${lightThemeColor.value}-equipment_profiles');
|
||||||
|
|
||||||
|
await tester.tap(find.byIcon(Icons.iso).first);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.takeScreenshot(binding, '${lightThemeColor.value}_equipment_profiles_iso_picker');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
/// and the additionally the first one with the dark theme
|
||||||
|
testWidgets(
|
||||||
|
'Generate dark theme screenshots',
|
||||||
|
(tester) async {
|
||||||
|
mockSharedPrefs(ThemeType.dark, darkThemeColor);
|
||||||
|
await tester.pumpApplication();
|
||||||
|
|
||||||
|
await tester.takePhoto();
|
||||||
|
await tester.takeScreenshot(binding, '${darkThemeColor.value}_metering_reflected');
|
||||||
|
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
await tester.tap(find.byTooltip(S.current.tooltipUseLightSensor));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.tap(find.byType(MeteringMeasureButton));
|
||||||
|
await sendMockIncidentEv(7.3);
|
||||||
|
await tester.tap(find.byType(MeteringMeasureButton));
|
||||||
|
await tester.takeScreenshot(binding, '${darkThemeColor.value}_metering_incident');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
extension on WidgetTester {
|
extension on WidgetTester {
|
||||||
|
@ -214,22 +143,9 @@ extension on WidgetTester {
|
||||||
await pumpAndSettle();
|
await pumpAndSettle();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> tapCancelButton() async {
|
|
||||||
final cancelButton = find.byWidgetPredicate(
|
|
||||||
(widget) =>
|
|
||||||
widget is TextButton &&
|
|
||||||
widget.child is Text &&
|
|
||||||
(widget.child as Text?)?.data == S.current.cancel,
|
|
||||||
);
|
|
||||||
expect(cancelButton, findsOneWidget);
|
|
||||||
await tap(cancelButton);
|
|
||||||
await pumpAndSettle();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> tapListTile(String title) async {
|
Future<void> tapListTile(String title) async {
|
||||||
final listTile = find.byWidgetPredicate(
|
final listTile = find.byWidgetPredicate(
|
||||||
(widget) =>
|
(widget) => widget is ListTile && widget.title is Text && (widget.title as Text?)?.data == title,
|
||||||
widget is ListTile && widget.title is Text && (widget.title as Text?)?.data == title,
|
|
||||||
);
|
);
|
||||||
expect(listTile, findsOneWidget);
|
expect(listTile, findsOneWidget);
|
||||||
await tap(listTile);
|
await tap(listTile);
|
||||||
|
|
|
@ -8,7 +8,6 @@ import 'package:mocktail/mocktail.dart';
|
||||||
class _MockIAPStorageService extends Mock implements IAPStorageService {}
|
class _MockIAPStorageService extends Mock implements IAPStorageService {}
|
||||||
|
|
||||||
class MockIAPProviders extends StatefulWidget {
|
class MockIAPProviders extends StatefulWidget {
|
||||||
final IAPProductStatus purchaseStatus;
|
|
||||||
final String selectedEquipmentProfileId;
|
final String selectedEquipmentProfileId;
|
||||||
final Film selectedFilm;
|
final Film selectedFilm;
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
@ -16,25 +15,10 @@ class MockIAPProviders extends StatefulWidget {
|
||||||
const MockIAPProviders({
|
const MockIAPProviders({
|
||||||
this.selectedEquipmentProfileId = '',
|
this.selectedEquipmentProfileId = '',
|
||||||
this.selectedFilm = const Film.other(),
|
this.selectedFilm = const Film.other(),
|
||||||
required this.purchaseStatus,
|
|
||||||
required this.child,
|
required this.child,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
const MockIAPProviders.purchasable({
|
|
||||||
this.selectedEquipmentProfileId = '',
|
|
||||||
this.selectedFilm = const Film.other(),
|
|
||||||
required this.child,
|
|
||||||
super.key,
|
|
||||||
}) : purchaseStatus = IAPProductStatus.purchasable;
|
|
||||||
|
|
||||||
const MockIAPProviders.purchased({
|
|
||||||
this.selectedEquipmentProfileId = '',
|
|
||||||
this.selectedFilm = const Film.other(),
|
|
||||||
required this.child,
|
|
||||||
super.key,
|
|
||||||
}) : purchaseStatus = IAPProductStatus.purchased;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<MockIAPProviders> createState() => _MockIAPProvidersState();
|
State<MockIAPProviders> createState() => _MockIAPProvidersState();
|
||||||
}
|
}
|
||||||
|
@ -47,30 +31,19 @@ class _MockIAPProvidersState extends State<MockIAPProviders> {
|
||||||
super.initState();
|
super.initState();
|
||||||
mockIAPStorageService = _MockIAPStorageService();
|
mockIAPStorageService = _MockIAPStorageService();
|
||||||
when(() => mockIAPStorageService.equipmentProfiles).thenReturn(mockEquipmentProfiles);
|
when(() => mockIAPStorageService.equipmentProfiles).thenReturn(mockEquipmentProfiles);
|
||||||
when(() => mockIAPStorageService.selectedEquipmentProfileId)
|
when(() => mockIAPStorageService.selectedEquipmentProfileId).thenReturn(widget.selectedEquipmentProfileId);
|
||||||
.thenReturn(widget.selectedEquipmentProfileId);
|
|
||||||
when(() => mockIAPStorageService.filmsInUse).thenReturn(mockFilms);
|
when(() => mockIAPStorageService.filmsInUse).thenReturn(mockFilms);
|
||||||
when(() => mockIAPStorageService.selectedFilm).thenReturn(widget.selectedFilm);
|
when(() => mockIAPStorageService.selectedFilm).thenReturn(widget.selectedFilm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return IAPProductsProvider(
|
return EquipmentProfileProvider(
|
||||||
child: IAPProducts(
|
storageService: mockIAPStorageService,
|
||||||
products: [
|
child: FilmsProvider(
|
||||||
IAPProduct(
|
storageService: mockIAPStorageService,
|
||||||
storeId: IAPProductType.paidFeatures.storeId,
|
availableFilms: mockFilms,
|
||||||
status: widget.purchaseStatus,
|
child: widget.child,
|
||||||
)
|
|
||||||
],
|
|
||||||
child: EquipmentProfileProvider(
|
|
||||||
storageService: mockIAPStorageService,
|
|
||||||
child: FilmsProvider(
|
|
||||||
storageService: mockIAPStorageService,
|
|
||||||
availableFilms: mockFilms,
|
|
||||||
child: widget.child,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -120,18 +93,13 @@ final mockEquipmentProfiles = [
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
const mockFilms = [_MockFilm2x(), _MockFilm3x()];
|
const mockFilms = [_MockFilm(400, 2), _MockFilm(3, 800), _MockFilm(400, 1.5)];
|
||||||
|
|
||||||
class _MockFilm2x extends Film {
|
class _MockFilm extends Film {
|
||||||
const _MockFilm2x() : super('Mock film 2x', 400);
|
final double reciprocityMultiplier;
|
||||||
|
|
||||||
|
const _MockFilm(int iso, this.reciprocityMultiplier) : super('Mock film $iso x$reciprocityMultiplier', iso);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
double reciprocityFormula(double t) => t * 2;
|
double reciprocityFormula(double t) => t * reciprocityMultiplier;
|
||||||
}
|
|
||||||
|
|
||||||
class _MockFilm3x extends Film {
|
|
||||||
const _MockFilm3x() : super('Mock film 3x', 800);
|
|
||||||
|
|
||||||
@override
|
|
||||||
double reciprocityFormula(double t) => t * 3;
|
|
||||||
}
|
}
|
||||||
|
|
20
integration_test/utils/platform_channel_mock.dart
Normal file
20
integration_test/utils/platform_channel_mock.dart
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
Future<void> sendMockLux([int lux = 100]) async {
|
||||||
|
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
|
||||||
|
"light.eventChannel",
|
||||||
|
const StandardMethodCodec().encodeSuccessEnvelope(lux),
|
||||||
|
(ByteData? data) {},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> sendMockIncidentEv(double ev) async {
|
||||||
|
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
|
||||||
|
"light.eventChannel",
|
||||||
|
const StandardMethodCodec().encodeSuccessEnvelope((2.5 * pow(2, ev)).toInt()),
|
||||||
|
(ByteData? data) {},
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,8 +1,49 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:lightmeter/application.dart';
|
||||||
|
import 'package:lightmeter/application_wrapper.dart';
|
||||||
|
import 'package:lightmeter/environment.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.dart';
|
import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.dart';
|
||||||
|
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
||||||
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
|
import '../mocks/paid_features_mock.dart';
|
||||||
|
|
||||||
|
extension WidgetTesterCommonActions on WidgetTester {
|
||||||
|
Future<void> pumpApplication({
|
||||||
|
IAPProductStatus productStatus = IAPProductStatus.purchased,
|
||||||
|
String selectedEquipmentProfileId = '',
|
||||||
|
Film selectedFilm = const Film.other(),
|
||||||
|
}) async {
|
||||||
|
await pumpWidget(
|
||||||
|
MockIAPProductsProvider(
|
||||||
|
productStatus: productStatus,
|
||||||
|
child: ApplicationWrapper(
|
||||||
|
const Environment.dev(),
|
||||||
|
child: MockIAPProviders(
|
||||||
|
selectedEquipmentProfileId: selectedEquipmentProfileId,
|
||||||
|
selectedFilm: selectedFilm,
|
||||||
|
child: const Application(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> toggleIncidentMetering() async {
|
||||||
|
await tap(find.byType(MeteringMeasureButton));
|
||||||
|
await tap(find.byType(MeteringMeasureButton));
|
||||||
|
await pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> openAnimatedPicker<T>() async {
|
||||||
|
await tap(find.byType(T));
|
||||||
|
await pumpAndSettle(Dimens.durationL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension WidgetTesterTextButtonActions on WidgetTester {
|
extension WidgetTesterTextButtonActions on WidgetTester {
|
||||||
Future<void> tapSelectButton() => _tapTextButton(S.current.select);
|
Future<void> tapSelectButton() => _tapTextButton(S.current.select);
|
||||||
|
@ -20,16 +61,3 @@ extension WidgetTesterTextButtonActions on WidgetTester {
|
||||||
await pumpAndSettle();
|
await pumpAndSettle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension WidgetTesterCommonActions on WidgetTester {
|
|
||||||
Future<void> toggleIncidentMetering() async {
|
|
||||||
await tap(find.byType(MeteringMeasureButton));
|
|
||||||
await tap(find.byType(MeteringMeasureButton));
|
|
||||||
await pumpAndSettle();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> openAnimatedPicker<T>() async {
|
|
||||||
await tap(find.byType(T));
|
|
||||||
await pumpAndSettle(Dimens.durationL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -30,23 +30,21 @@ class ApplicationWrapper extends StatelessWidget {
|
||||||
builder: (_, snapshot) {
|
builder: (_, snapshot) {
|
||||||
if (snapshot.data != null) {
|
if (snapshot.data != null) {
|
||||||
final iapService = IAPStorageService(snapshot.data![0] as SharedPreferences);
|
final iapService = IAPStorageService(snapshot.data![0] as SharedPreferences);
|
||||||
return IAPProductsProvider(
|
return ServicesProvider(
|
||||||
child: ServicesProvider(
|
caffeineService: const CaffeineService(),
|
||||||
caffeineService: const CaffeineService(),
|
environment: env.copyWith(hasLightSensor: snapshot.data![1] as bool),
|
||||||
environment: env.copyWith(hasLightSensor: snapshot.data![1] as bool),
|
hapticsService: const HapticsService(),
|
||||||
hapticsService: const HapticsService(),
|
lightSensorService: const LightSensorService(LocalPlatform()),
|
||||||
lightSensorService: const LightSensorService(LocalPlatform()),
|
permissionsService: const PermissionsService(),
|
||||||
permissionsService: const PermissionsService(),
|
userPreferencesService:
|
||||||
userPreferencesService:
|
UserPreferencesService(snapshot.data![0] as SharedPreferences),
|
||||||
UserPreferencesService(snapshot.data![0] as SharedPreferences),
|
volumeEventsService: const VolumeEventsService(LocalPlatform()),
|
||||||
volumeEventsService: const VolumeEventsService(LocalPlatform()),
|
child: EquipmentProfileProvider(
|
||||||
child: EquipmentProfileProvider(
|
storageService: iapService,
|
||||||
|
child: FilmsProvider(
|
||||||
storageService: iapService,
|
storageService: iapService,
|
||||||
child: FilmsProvider(
|
child: UserPreferencesProvider(
|
||||||
storageService: iapService,
|
child: child,
|
||||||
child: UserPreferencesProvider(
|
|
||||||
child: child,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -2,8 +2,17 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/application.dart';
|
import 'package:lightmeter/application.dart';
|
||||||
import 'package:lightmeter/application_wrapper.dart';
|
import 'package:lightmeter/application_wrapper.dart';
|
||||||
import 'package:lightmeter/environment.dart';
|
import 'package:lightmeter/environment.dart';
|
||||||
|
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
runApp(const ApplicationWrapper(Environment.dev(), child: Application()));
|
runApp(
|
||||||
|
const MockIAPProductsProvider(
|
||||||
|
productStatus: IAPProductStatus.purchasable,
|
||||||
|
child: ApplicationWrapper(
|
||||||
|
Environment.dev(),
|
||||||
|
child: Application(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,17 @@ import 'package:lightmeter/application.dart';
|
||||||
import 'package:lightmeter/application_wrapper.dart';
|
import 'package:lightmeter/application_wrapper.dart';
|
||||||
import 'package:lightmeter/environment.dart';
|
import 'package:lightmeter/environment.dart';
|
||||||
import 'package:lightmeter/firebase.dart';
|
import 'package:lightmeter/firebase.dart';
|
||||||
|
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await initializeFirebase(handleErrors: true);
|
await initializeFirebase(handleErrors: true);
|
||||||
runApp(const ApplicationWrapper(Environment.prod(), child: Application()));
|
runApp(
|
||||||
|
const IAPProductsProvider(
|
||||||
|
child: ApplicationWrapper(
|
||||||
|
Environment.prod(),
|
||||||
|
child: Application(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,17 @@ import 'package:lightmeter/application.dart';
|
||||||
import 'package:lightmeter/application_wrapper.dart';
|
import 'package:lightmeter/application_wrapper.dart';
|
||||||
import 'package:lightmeter/environment.dart';
|
import 'package:lightmeter/environment.dart';
|
||||||
import 'package:lightmeter/firebase.dart';
|
import 'package:lightmeter/firebase.dart';
|
||||||
|
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await initializeFirebase(handleErrors: false);
|
await initializeFirebase(handleErrors: false);
|
||||||
runApp(const ApplicationWrapper(Environment.prod(), child: Application()));
|
runApp(
|
||||||
|
const IAPProductsProvider(
|
||||||
|
child: ApplicationWrapper(
|
||||||
|
Environment.prod(),
|
||||||
|
child: Application(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue