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';
|
|
|
|
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';
|
|
|
|
import 'package:lightmeter/res/theme.dart';
|
|
|
|
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/iso_picker/widget_picker_iso.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:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
import '../integration_test/mocks/paid_features_mock.dart';
|
|
|
|
import '../integration_test/utils/widget_tester_actions.dart';
|
2024-05-14 11:48:28 +00:00
|
|
|
import 'models/screenshot_args.dart';
|
2023-10-20 14:12:43 +00:00
|
|
|
|
|
|
|
//https://stackoverflow.com/a/67186625/13167574
|
|
|
|
|
2024-04-19 14:59:00 +00:00
|
|
|
const _mockFilm = Film('Ilford HP5+', 400);
|
2024-05-11 12:59:28 +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();
|
|
|
|
|
|
|
|
void mockSharedPrefs(ThemeType theme, Color color) {
|
|
|
|
// ignore: invalid_use_of_visible_for_testing_member
|
|
|
|
SharedPreferences.setMockInitialValues({
|
|
|
|
/// Metering values
|
|
|
|
UserPreferencesService.evSourceTypeKey: EvSourceType.camera.index,
|
|
|
|
UserPreferencesService.isoKey: 400,
|
|
|
|
UserPreferencesService.ndFilterKey: 0,
|
|
|
|
|
|
|
|
/// Metering settings
|
|
|
|
UserPreferencesService.stopTypeKey: StopType.third.index,
|
|
|
|
UserPreferencesService.cameraEvCalibrationKey: 0.0,
|
|
|
|
UserPreferencesService.lightSensorEvCalibrationKey: 0.0,
|
|
|
|
UserPreferencesService.meteringScreenLayoutKey: json.encode(
|
|
|
|
{
|
|
|
|
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
|
|
|
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
|
|
|
MeteringScreenLayoutFeature.filmPicker: true,
|
|
|
|
}.toJson(),
|
|
|
|
),
|
|
|
|
|
|
|
|
/// 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,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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-11 12:59:28 +00:00
|
|
|
mockSharedPrefs(ThemeType.light, _lightThemeColor);
|
2024-04-19 14:59:00 +00:00
|
|
|
await tester.pumpApplication(
|
2024-04-30 10:44:01 +00:00
|
|
|
availableFilms: [_mockFilm],
|
|
|
|
filmsInUse: [_mockFilm],
|
2024-04-19 14:59:00 +00:00
|
|
|
selectedFilm: _mockFilm,
|
|
|
|
);
|
2023-10-20 14:12:43 +00:00
|
|
|
|
2024-04-19 14:59:00 +00:00
|
|
|
await tester.takePhoto();
|
2024-05-15 19:47:03 +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-15 19:47:03 +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-15 19:47:03 +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-15 19:47:03 +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-15 19:47:03 +00:00
|
|
|
await tester.takeScreenshotLight(binding, 'equipment-profiles');
|
2023-10-20 14:12:43 +00:00
|
|
|
|
2024-04-19 14:59:00 +00:00
|
|
|
await tester.tap(find.byIcon(Icons.iso).first);
|
|
|
|
await tester.pumpAndSettle();
|
2024-05-15 19:47:03 +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-11 12:59:28 +00:00
|
|
|
mockSharedPrefs(ThemeType.dark, _darkThemeColor);
|
2024-04-19 14:59:00 +00:00
|
|
|
await tester.pumpApplication(
|
2024-04-30 10:44:01 +00:00
|
|
|
availableFilms: [_mockFilm],
|
|
|
|
filmsInUse: [_mockFilm],
|
2024-04-19 14:59:00 +00:00
|
|
|
selectedFilm: _mockFilm,
|
|
|
|
);
|
2023-10-20 14:12:43 +00:00
|
|
|
|
|
|
|
await tester.takePhoto();
|
2024-05-15 19:47:03 +00:00
|
|
|
await tester.takeScreenshotDark(binding, 'metering-reflected');
|
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-15 19:47:03 +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;
|
2024-05-10 14:24:12 +00:00
|
|
|
await binding.takeScreenshot(
|
2024-05-11 12:59:28 +00:00
|
|
|
ScreenshotArgs(
|
|
|
|
name: name,
|
2024-05-15 19:47:03 +00:00
|
|
|
deviceName: const String.fromEnvironment('deviceName'),
|
2024-05-11 12:59:28 +00:00
|
|
|
platformFolder: _platformFolder,
|
2024-05-15 19:47:03 +00:00
|
|
|
backgroundColor: backgroundColor.value.toRadixString(16),
|
|
|
|
isDark: theme.brightness == Brightness.dark,
|
2024-05-11 12:59:28 +00:00
|
|
|
).toString(),
|
2024-05-10 14:24:12 +00:00
|
|
|
);
|
2023-10-20 14:12:43 +00:00
|
|
|
await pumpAndSettle();
|
|
|
|
}
|
|
|
|
}
|