diff --git a/lib/screens/lightmeter_pro/screen_lightmeter_pro.dart b/lib/screens/lightmeter_pro/screen_lightmeter_pro.dart index b208c5f..35bdf83 100644 --- a/lib/screens/lightmeter_pro/screen_lightmeter_pro.dart +++ b/lib/screens/lightmeter_pro/screen_lightmeter_pro.dart @@ -1,5 +1,4 @@ -import 'dart:io'; - +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:lightmeter/data/models/app_feature.dart'; import 'package:lightmeter/generated/l10n.dart'; @@ -11,7 +10,8 @@ import 'package:lightmeter/utils/text_height.dart'; import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; class LightmeterProScreen extends StatelessWidget { - final features = Platform.isAndroid ? AppFeature.androidFeatures : AppFeature.iosFeatures; + final features = + defaultTargetPlatform == TargetPlatform.android ? AppFeature.androidFeatures : AppFeature.iosFeatures; LightmeterProScreen({super.key}); @@ -38,7 +38,7 @@ class LightmeterProScreen extends StatelessWidget { Dimens.paddingM, 0, Dimens.paddingM, - Dimens.paddingM, + Dimens.paddingS, ), child: Text( S.of(context).proFeaturesWhatsIncluded, diff --git a/test/screens/lightmeter_pro/goldens/lightmeter_pro_screen.png b/test/screens/lightmeter_pro/goldens/lightmeter_pro_screen.png new file mode 100644 index 0000000..7db028a Binary files /dev/null and b/test/screens/lightmeter_pro/goldens/lightmeter_pro_screen.png differ diff --git a/test/screens/lightmeter_pro/lightmeter_pro_screen_golden_test.dart b/test/screens/lightmeter_pro/lightmeter_pro_screen_golden_test.dart new file mode 100644 index 0000000..a70327f --- /dev/null +++ b/test/screens/lightmeter_pro/lightmeter_pro_screen_golden_test.dart @@ -0,0 +1,49 @@ +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:golden_toolkit/golden_toolkit.dart'; +import 'package:lightmeter/data/models/theme_type.dart'; +import 'package:lightmeter/screens/lightmeter_pro/screen_lightmeter_pro.dart'; +import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +import '../../application_mock.dart'; +import '../../utils/golden_test_set_theme.dart'; + +void main() { + setUpAll(() { + SharedPreferences.setMockInitialValues({}); + }); + + testGoldens( + 'LightmeterProScreen golden test', + (tester) async { + final builder = DeviceBuilder(); + builder.addScenario( + name: 'Get Pro', + widget: const _MockLightmeterProFlow(), + onCreate: (scenarioWidgetKey) async { + if (scenarioWidgetKey.toString().contains('Dark')) { + await setTheme(tester, scenarioWidgetKey, ThemeType.dark); + } + }, + ); + await tester.pumpDeviceBuilder(builder); + await screenMatchesGolden( + tester, + 'lightmeter_pro_screen', + ); + }, + ); +} + +class _MockLightmeterProFlow extends StatelessWidget { + const _MockLightmeterProFlow(); + + @override + Widget build(BuildContext context) { + return GoldenTestApplicationMock( + productStatus: IAPProductStatus.purchasable, + child: LightmeterProScreen(), + ); + } +} diff --git a/test/screens/metering/goldens/metering_screen.png b/test/screens/metering/goldens/metering_screen.png index a88dc2c..db22284 100644 Binary files a/test/screens/metering/goldens/metering_screen.png and b/test/screens/metering/goldens/metering_screen.png differ diff --git a/test/screens/metering/screen_metering_golden_test.dart b/test/screens/metering/screen_metering_golden_test.dart index 8c7e15f..9ca908f 100644 --- a/test/screens/metering/screen_metering_golden_test.dart +++ b/test/screens/metering/screen_metering_golden_test.dart @@ -15,6 +15,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import '../../../integration_test/utils/finder_actions.dart'; import '../../../integration_test/utils/platform_channel_mock.dart'; import '../../application_mock.dart'; +import '../../utils/golden_test_set_theme.dart'; class _MeteringScreenConfig { final IAPProductStatus iapProductStatus; @@ -54,16 +55,6 @@ void main() { await tester.pumpAndSettle(); } - Future setTheme(WidgetTester tester, Key scenarioWidgetKey, ThemeType themeType) async { - final flow = find.descendant( - of: find.byKey(scenarioWidgetKey), - matching: find.byType(MeteringFlow), - ); - final BuildContext context = tester.element(flow); - UserPreferencesProvider.of(context).setThemeType(themeType); - await tester.pumpAndSettle(); - } - Future takePhoto(WidgetTester tester, Key scenarioWidgetKey) async { final button = find.descendant( of: find.byKey(scenarioWidgetKey), @@ -110,7 +101,7 @@ void main() { onCreate: (scenarioWidgetKey) async { await setEvSource(tester, scenarioWidgetKey, scenario.evSourceType); if (scenarioWidgetKey.toString().contains('Dark')) { - await setTheme(tester, scenarioWidgetKey, ThemeType.dark); + await setTheme(tester, scenarioWidgetKey, ThemeType.dark); } if (scenario.evSourceType == EvSourceType.camera) { await takePhoto(tester, scenarioWidgetKey); diff --git a/test/screens/settings/goldens/settings_screen.png b/test/screens/settings/goldens/settings_screen.png index 1c65c19..870dbf1 100644 Binary files a/test/screens/settings/goldens/settings_screen.png and b/test/screens/settings/goldens/settings_screen.png differ diff --git a/test/screens/settings/settings_screen_golden_test.dart b/test/screens/settings/settings_screen_golden_test.dart index c1deae5..6c34522 100644 --- a/test/screens/settings/settings_screen_golden_test.dart +++ b/test/screens/settings/settings_screen_golden_test.dart @@ -7,13 +7,13 @@ 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/shared_prefs_service.dart'; -import 'package:lightmeter/providers/user_preferences_provider.dart'; import 'package:lightmeter/screens/settings/flow_settings.dart'; import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '../../application_mock.dart'; +import '../../utils/golden_test_set_theme.dart'; class _SettingsScreenConfig { final IAPProductStatus iapProductStatus; @@ -33,16 +33,6 @@ final _testScenarios = [IAPProductStatus.purchased, IAPProductStatus.purchasable ); void main() { - Future setTheme(WidgetTester tester, Key scenarioWidgetKey, ThemeType themeType) async { - final flow = find.descendant( - of: find.byKey(scenarioWidgetKey), - matching: find.byType(SettingsFlow), - ); - final BuildContext context = tester.element(flow); - UserPreferencesProvider.of(context).setThemeType(themeType); - await tester.pumpAndSettle(); - } - setUpAll(() { SharedPreferences.setMockInitialValues({ UserPreferencesService.evSourceTypeKey: EvSourceType.camera.index, @@ -73,7 +63,7 @@ void main() { widget: _MockSettingsFlow(productStatus: scenario.iapProductStatus), onCreate: (scenarioWidgetKey) async { if (scenarioWidgetKey.toString().contains('Dark')) { - await setTheme(tester, scenarioWidgetKey, ThemeType.dark); + await setTheme(tester, scenarioWidgetKey, ThemeType.dark); } }, ); diff --git a/test/screens/timer/screen_timer_golden_test.dart b/test/screens/timer/screen_timer_golden_test.dart index 41b682a..f0b601b 100644 --- a/test/screens/timer/screen_timer_golden_test.dart +++ b/test/screens/timer/screen_timer_golden_test.dart @@ -4,7 +4,6 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:lightmeter/data/models/exposure_pair.dart'; import 'package:lightmeter/data/models/theme_type.dart'; import 'package:lightmeter/data/shared_prefs_service.dart'; -import 'package:lightmeter/providers/user_preferences_provider.dart'; import 'package:lightmeter/res/dimens.dart'; import 'package:lightmeter/screens/shared/animated_circular_button/widget_button_circular_animated.dart'; import 'package:lightmeter/screens/timer/flow_timer.dart'; @@ -13,6 +12,7 @@ import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '../../application_mock.dart'; +import '../../utils/golden_test_set_theme.dart'; class _TimerScreenConfig { final ShutterSpeedValue shutterSpeedValue; @@ -52,16 +52,6 @@ final _testScenarios = [ ); void main() { - Future setTheme(WidgetTester tester, Key scenarioWidgetKey, ThemeType themeType) async { - final flow = find.descendant( - of: find.byKey(scenarioWidgetKey), - matching: find.byType(TimerFlow), - ); - final BuildContext context = tester.element(flow); - UserPreferencesProvider.of(context).setThemeType(themeType); - await tester.pumpAndSettle(); - } - Future toggleTimer(WidgetTester tester, Key scenarioWidgetKey) async { final button = find.descendant( of: find.byKey(scenarioWidgetKey), @@ -98,7 +88,7 @@ void main() { widget: _MockTimerFlow(scenario.shutterSpeedValue), onCreate: (scenarioWidgetKey) async { if (scenarioWidgetKey.toString().contains('Dark')) { - await setTheme(tester, scenarioWidgetKey, ThemeType.dark); + await setTheme(tester, scenarioWidgetKey, ThemeType.dark); } if (!scenario.isStopped) { await toggleTimer(tester, scenarioWidgetKey); diff --git a/test/utils/golden_test_set_theme.dart b/test/utils/golden_test_set_theme.dart new file mode 100644 index 0000000..dbeef13 --- /dev/null +++ b/test/utils/golden_test_set_theme.dart @@ -0,0 +1,14 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:lightmeter/data/models/theme_type.dart'; +import 'package:lightmeter/providers/user_preferences_provider.dart'; + +Future setTheme(WidgetTester tester, Key scenarioWidgetKey, ThemeType themeType) async { + final flow = find.descendant( + of: find.byKey(scenarioWidgetKey), + matching: find.byType(T), + ); + final BuildContext context = tester.element(flow); + UserPreferencesProvider.of(context).setThemeType(themeType); + await tester.pumpAndSettle(); +}