2024-05-21 17:13:33 +00:00
|
|
|
// ignore_for_file: invalid_use_of_visible_for_testing_member
|
|
|
|
|
2023-10-20 14:12:43 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:integration_test/integration_test.dart';
|
|
|
|
import 'package:lightmeter/data/models/ev_source_type.dart';
|
2024-05-21 17:13:33 +00:00
|
|
|
import 'package:lightmeter/data/models/exposure_pair.dart';
|
2023-10-20 14:12:43 +00:00
|
|
|
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
|
|
|
import 'package:lightmeter/data/models/theme_type.dart';
|
|
|
|
import 'package:lightmeter/data/models/volume_action.dart';
|
|
|
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
|
|
|
import 'package:lightmeter/generated/l10n.dart';
|
2024-05-21 17:13:33 +00:00
|
|
|
import 'package:lightmeter/res/dimens.dart';
|
2023-10-20 14:12:43 +00:00
|
|
|
import 'package:lightmeter/res/theme.dart';
|
2024-05-21 17:13:33 +00:00
|
|
|
import 'package:lightmeter/screens/metering/components/shared/exposure_pairs_list/widget_list_exposure_pairs.dart';
|
2023-10-20 14:12:43 +00:00
|
|
|
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/iso_picker/widget_picker_iso.dart';
|
2024-05-21 17:13:33 +00:00
|
|
|
import 'package:lightmeter/screens/metering/screen_metering.dart';
|
2023-10-20 14:12:43 +00:00
|
|
|
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';
|
2024-05-21 17:13:33 +00:00
|
|
|
import 'package:lightmeter/screens/shared/animated_circular_button/widget_button_circular_animated.dart';
|
|
|
|
import 'package:lightmeter/screens/timer/screen_timer.dart';
|
2024-05-23 09:34:11 +00:00
|
|
|
import 'package:lightmeter/utils/platform_utils.dart';
|
2023-10-20 14:12:43 +00:00
|
|
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
import '../integration_test/mocks/paid_features_mock.dart';
|
|
|
|
import '../integration_test/utils/widget_tester_actions.dart';
|
2024-05-21 17:13:33 +00:00
|
|
|
import 'models/screenshot_args.dart';
|
2023-10-20 14:12:43 +00:00
|
|
|
|
|
|
|
//https://stackoverflow.com/a/67186625/13167574
|
|
|
|
|
2024-10-06 18:26:40 +00:00
|
|
|
const _mockFilm = FilmExponential(id: '1', name: 'Ilford HP5+', iso: 400, exponent: 1.34);
|
2024-05-21 17:13:33 +00:00
|
|
|
final Color _lightThemeColor = primaryColorsList[5];
|
|
|
|
final Color _darkThemeColor = primaryColorsList[3];
|
|
|
|
final ThemeData _themeLight = themeFrom(_lightThemeColor, Brightness.light);
|
|
|
|
final ThemeData _themeDark = themeFrom(_darkThemeColor, Brightness.dark);
|
2024-04-19 14:59:00 +00:00
|
|
|
|
2023-10-20 14:12:43 +00:00
|
|
|
/// Just a screenshot generator. No expectations here.
|
|
|
|
void main() {
|
|
|
|
final binding = IntegrationTestWidgetsFlutterBinding();
|
|
|
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
2024-05-23 09:34:11 +00:00
|
|
|
Future<void> mockSharedPrefs({
|
2024-05-21 17:13:33 +00:00
|
|
|
int iso = 400,
|
|
|
|
int nd = 0,
|
|
|
|
double calibration = 0.0,
|
|
|
|
required ThemeType theme,
|
|
|
|
required Color color,
|
2024-05-23 09:34:11 +00:00
|
|
|
}) async {
|
2023-10-20 14:12:43 +00:00
|
|
|
SharedPreferences.setMockInitialValues({
|
|
|
|
/// Metering values
|
|
|
|
UserPreferencesService.evSourceTypeKey: EvSourceType.camera.index,
|
2024-05-21 17:13:33 +00:00
|
|
|
UserPreferencesService.isoKey: iso,
|
|
|
|
UserPreferencesService.ndFilterKey: nd,
|
2023-10-20 14:12:43 +00:00
|
|
|
|
|
|
|
/// Metering settings
|
|
|
|
UserPreferencesService.stopTypeKey: StopType.third.index,
|
2024-05-21 17:13:33 +00:00
|
|
|
UserPreferencesService.cameraEvCalibrationKey: calibration,
|
|
|
|
UserPreferencesService.lightSensorEvCalibrationKey: calibration,
|
2023-10-20 14:12:43 +00:00
|
|
|
UserPreferencesService.meteringScreenLayoutKey: json.encode(
|
|
|
|
{
|
|
|
|
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
|
|
|
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
|
|
|
MeteringScreenLayoutFeature.filmPicker: true,
|
|
|
|
}.toJson(),
|
|
|
|
),
|
|
|
|
|
|
|
|
/// General settings
|
2024-05-21 17:13:33 +00:00
|
|
|
UserPreferencesService.autostartTimerKey: false,
|
2023-10-20 14:12:43 +00:00
|
|
|
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,
|
2024-05-23 09:34:11 +00:00
|
|
|
|
|
|
|
UserPreferencesService.seenChangelogVersionKey: await const PlatformUtils().version,
|
2023-10-20 14:12:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-04-19 14:59:00 +00:00
|
|
|
setUpAll(() async {
|
|
|
|
if (Platform.isAndroid) await binding.convertFlutterSurfaceToImage();
|
|
|
|
});
|
|
|
|
|
2023-10-20 14:12:43 +00:00
|
|
|
/// Generates several screenshots with the light theme
|
2024-04-19 14:59:00 +00:00
|
|
|
testWidgets('Generate light theme screenshots', (tester) async {
|
2024-05-23 09:34:11 +00:00
|
|
|
await mockSharedPrefs(theme: ThemeType.light, color: _lightThemeColor);
|
2024-04-19 14:59:00 +00:00
|
|
|
await tester.pumpApplication(
|
2024-10-29 12:41:36 +00:00
|
|
|
predefinedFilms: [_mockFilm].toFilmsMap(),
|
|
|
|
customFilms: {},
|
|
|
|
selectedFilmId: _mockFilm.id,
|
2024-04-19 14:59:00 +00:00
|
|
|
);
|
2023-10-20 14:12:43 +00:00
|
|
|
|
2024-04-19 14:59:00 +00:00
|
|
|
await tester.takePhoto();
|
2024-05-21 17:13:33 +00:00
|
|
|
await tester.takeScreenshotLight(binding, 'metering-reflected');
|
2023-10-20 14:12:43 +00:00
|
|
|
|
2024-04-19 14:59:00 +00:00
|
|
|
if (Platform.isAndroid) {
|
|
|
|
await tester.tap(find.byTooltip(S.current.tooltipUseLightSensor));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.toggleIncidentMetering(7.3);
|
2024-05-21 17:13:33 +00:00
|
|
|
await tester.takeScreenshotLight(binding, 'metering-incident');
|
2024-04-19 14:59:00 +00:00
|
|
|
}
|
2023-10-20 14:12:43 +00:00
|
|
|
|
2024-04-19 14:59:00 +00:00
|
|
|
await tester.openAnimatedPicker<IsoValuePicker>();
|
2024-05-21 17:13:33 +00:00
|
|
|
await tester.takeScreenshotLight(binding, 'metering-iso-picker');
|
2023-10-20 14:12:43 +00:00
|
|
|
|
2024-04-19 14:59:00 +00:00
|
|
|
await tester.tapCancelButton();
|
|
|
|
await tester.tap(find.byTooltip(S.current.tooltipOpenSettings));
|
|
|
|
await tester.pumpAndSettle();
|
2024-05-21 17:13:33 +00:00
|
|
|
await tester.takeScreenshotLight(binding, 'settings');
|
2023-10-20 14:12:43 +00:00
|
|
|
|
2024-04-19 14:59:00 +00:00
|
|
|
await tester.tapDescendantTextOf<SettingsScreen>(S.current.equipmentProfiles);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.tapDescendantTextOf<EquipmentProfilesScreen>(mockEquipmentProfiles.first.name);
|
|
|
|
await tester.pumpAndSettle();
|
2024-05-21 17:13:33 +00:00
|
|
|
await tester.takeScreenshotLight(binding, 'equipment-profiles');
|
2023-10-20 14:12:43 +00:00
|
|
|
|
2024-05-21 17:13:33 +00:00
|
|
|
await tester.tap(find.byIcon(Icons.iso_outlined).first);
|
2024-04-19 14:59:00 +00:00
|
|
|
await tester.pumpAndSettle();
|
2024-05-21 17:13:33 +00:00
|
|
|
await tester.takeScreenshotLight(binding, 'equipment-profiles-iso-picker');
|
2024-04-19 14:59:00 +00:00
|
|
|
});
|
2023-10-20 14:12:43 +00:00
|
|
|
|
|
|
|
/// and the additionally the first one with the dark theme
|
|
|
|
testWidgets(
|
|
|
|
'Generate dark theme screenshots',
|
|
|
|
(tester) async {
|
2024-05-23 09:34:11 +00:00
|
|
|
await mockSharedPrefs(theme: ThemeType.dark, color: _darkThemeColor);
|
2024-04-19 14:59:00 +00:00
|
|
|
await tester.pumpApplication(
|
2024-10-29 12:41:36 +00:00
|
|
|
predefinedFilms: [_mockFilm].toFilmsMap(),
|
|
|
|
customFilms: {},
|
|
|
|
selectedFilmId: _mockFilm.id,
|
2024-04-19 14:59:00 +00:00
|
|
|
);
|
2023-10-20 14:12:43 +00:00
|
|
|
|
|
|
|
await tester.takePhoto();
|
2024-05-21 17:13:33 +00:00
|
|
|
await tester.takeScreenshotDark(binding, 'metering-reflected');
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
testWidgets(
|
|
|
|
'Generate timer screenshot',
|
|
|
|
(tester) async {
|
|
|
|
const timerExposurePair = ExposurePair(
|
|
|
|
ApertureValue(16, StopType.full),
|
|
|
|
ShutterSpeedValue(8, false, StopType.full),
|
|
|
|
);
|
2024-05-23 09:34:11 +00:00
|
|
|
await mockSharedPrefs(
|
2024-05-21 17:13:33 +00:00
|
|
|
iso: 100,
|
|
|
|
nd: 8,
|
|
|
|
calibration: -0.3,
|
|
|
|
theme: ThemeType.light,
|
|
|
|
color: _lightThemeColor,
|
|
|
|
);
|
|
|
|
await tester.pumpApplication(
|
2024-10-29 12:41:36 +00:00
|
|
|
predefinedFilms: [_mockFilm].toFilmsMap(),
|
|
|
|
customFilms: {},
|
|
|
|
selectedFilmId: _mockFilm.id,
|
2024-05-21 17:13:33 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
await tester.takePhoto();
|
|
|
|
await tester.scrollToExposurePair(
|
|
|
|
ev: 5,
|
|
|
|
exposurePair: timerExposurePair,
|
|
|
|
);
|
|
|
|
await tester.tap(find.text(timerExposurePair.shutterSpeed.toString()));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.mockTimerResumedState(timerExposurePair.shutterSpeed);
|
|
|
|
await tester.takeScreenshotLight(binding, 'timer');
|
2023-10-20 14:12:43 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-02-21 11:33:25 +00:00
|
|
|
final String _platformFolder = Platform.isAndroid ? 'android' : 'ios';
|
|
|
|
|
2023-10-20 14:12:43 +00:00
|
|
|
extension on WidgetTester {
|
2024-05-21 17:13:33 +00:00
|
|
|
Future<void> takeScreenshotLight(IntegrationTestWidgetsFlutterBinding binding, String name) =>
|
|
|
|
_takeScreenshot(binding, name, _themeLight);
|
|
|
|
Future<void> takeScreenshotDark(IntegrationTestWidgetsFlutterBinding binding, String name) =>
|
|
|
|
_takeScreenshot(binding, name, _themeDark);
|
|
|
|
|
|
|
|
Future<void> _takeScreenshot(IntegrationTestWidgetsFlutterBinding binding, String name, ThemeData theme) async {
|
|
|
|
final Color backgroundColor = theme.colorScheme.surface;
|
|
|
|
await binding.takeScreenshot(
|
|
|
|
ScreenshotArgs(
|
|
|
|
name: name,
|
|
|
|
deviceName: const String.fromEnvironment('deviceName'),
|
|
|
|
platformFolder: _platformFolder,
|
|
|
|
backgroundColor: backgroundColor.value.toRadixString(16),
|
|
|
|
isDark: theme.brightness == Brightness.dark,
|
|
|
|
).toString(),
|
|
|
|
);
|
2023-10-20 14:12:43 +00:00
|
|
|
await pumpAndSettle();
|
|
|
|
}
|
|
|
|
}
|
2024-05-21 17:13:33 +00:00
|
|
|
|
|
|
|
extension on WidgetTester {
|
|
|
|
Future<void> scrollToExposurePair({
|
|
|
|
double ev = mockPhotoEv100,
|
|
|
|
EquipmentProfile equipmentProfile = defaultEquipmentProfile,
|
|
|
|
required ExposurePair exposurePair,
|
|
|
|
}) async {
|
|
|
|
final exposurePairs = MeteringContainerBuidler.buildExposureValues(
|
|
|
|
ev,
|
|
|
|
StopType.third,
|
|
|
|
equipmentProfile,
|
|
|
|
);
|
|
|
|
|
|
|
|
await scrollUntilVisible(
|
|
|
|
find.byWidgetPredicate((widget) => widget is Row && widget.key == ValueKey(exposurePairs.indexOf(exposurePair))),
|
|
|
|
56,
|
|
|
|
scrollable: find.descendant(of: find.byType(ExposurePairsList), matching: find.byType(Scrollable)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> mockTimerResumedState(ShutterSpeedValue shutterSpeedValue) async {
|
|
|
|
await tap(find.byType(AnimatedCircluarButton));
|
|
|
|
await pump(Dimens.durationS);
|
|
|
|
|
|
|
|
late final skipTimerDuration =
|
|
|
|
Duration(milliseconds: (shutterSpeedValue.value * 0.35 * Duration.millisecondsPerSecond).toInt());
|
|
|
|
await pump(skipTimerDuration);
|
|
|
|
|
|
|
|
final TimerScreenState state = this.state(find.byType(TimerScreen));
|
|
|
|
state.startStopIconController.stop();
|
|
|
|
state.timelineController.stop();
|
|
|
|
await pump();
|
|
|
|
}
|
|
|
|
}
|