Fixed integration tests

This commit is contained in:
Vadim 2024-05-23 11:34:11 +02:00
parent 7f8ea54c6e
commit 90bfe7c7b8
8 changed files with 44 additions and 16 deletions

View file

@ -17,6 +17,7 @@ import 'package:lightmeter/screens/settings/components/shared/dialog_filter/widg
import 'package:lightmeter/screens/settings/components/shared/dialog_range_picker/widget_dialog_picker_range.dart'; import 'package:lightmeter/screens/settings/components/shared/dialog_range_picker/widget_dialog_picker_range.dart';
import 'package:lightmeter/screens/settings/screen_settings.dart'; import 'package:lightmeter/screens/settings/screen_settings.dart';
import 'package:lightmeter/utils/double_to_zoom.dart'; import 'package:lightmeter/utils/double_to_zoom.dart';
import 'package:lightmeter/utils/platform_utils.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -27,7 +28,7 @@ import 'utils/expectations.dart';
@isTest @isTest
void testE2E(String description) { void testE2E(String description) {
setUp(() { setUp(() async {
SharedPreferences.setMockInitialValues({ SharedPreferences.setMockInitialValues({
/// Metering values /// Metering values
UserPreferencesService.evSourceTypeKey: EvSourceType.camera.index, UserPreferencesService.evSourceTypeKey: EvSourceType.camera.index,
@ -38,6 +39,8 @@ void testE2E(String description) {
MeteringScreenLayoutFeature.filmPicker: true, MeteringScreenLayoutFeature.filmPicker: true,
}.toJson(), }.toJson(),
), ),
UserPreferencesService.seenChangelogVersionKey: await const PlatformUtils().version,
}); });
}); });

View file

@ -10,6 +10,7 @@ import 'package:lightmeter/screens/metering/components/shared/readings_container
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/extreme_exposure_pairs_container/widget_container_extreme_exposure_pairs.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/extreme_exposure_pairs_container/widget_container_extreme_exposure_pairs.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/film_picker/widget_picker_film.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/film_picker/widget_picker_film.dart';
import 'package:lightmeter/screens/settings/screen_settings.dart'; import 'package:lightmeter/screens/settings/screen_settings.dart';
import 'package:lightmeter/utils/platform_utils.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -22,7 +23,7 @@ void testToggleLayoutFeatures(String description) {
group( group(
description, description,
() { () {
setUp(() { setUp(() async {
SharedPreferences.setMockInitialValues({ SharedPreferences.setMockInitialValues({
/// Metering values /// Metering values
UserPreferencesService.evSourceTypeKey: EvSourceType.camera.index, UserPreferencesService.evSourceTypeKey: EvSourceType.camera.index,
@ -33,6 +34,7 @@ void testToggleLayoutFeatures(String description) {
MeteringScreenLayoutFeature.filmPicker: true, MeteringScreenLayoutFeature.filmPicker: true,
}.toJson(), }.toJson(),
), ),
UserPreferencesService.seenChangelogVersionKey: await const PlatformUtils().version,
}); });
}); });

View file

@ -14,6 +14,7 @@ import 'package:lightmeter/screens/metering/components/shared/readings_container
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/nd_picker/widget_picker_nd.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/nd_picker/widget_picker_nd.dart';
import 'package:lightmeter/screens/settings/components/shared/disable/widget_disable.dart'; import 'package:lightmeter/screens/settings/components/shared/disable/widget_disable.dart';
import 'package:lightmeter/screens/settings/screen_settings.dart'; import 'package:lightmeter/screens/settings/screen_settings.dart';
import 'package:lightmeter/utils/platform_utils.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -38,6 +39,7 @@ void testPurchases(String description) {
MeteringScreenLayoutFeature.filmPicker: true, MeteringScreenLayoutFeature.filmPicker: true,
}.toJson(), }.toJson(),
), ),
UserPreferencesService.seenChangelogVersionKey: await const PlatformUtils().version,
}); });
await tester.pumpApplication(productStatus: IAPProductStatus.purchasable); await tester.pumpApplication(productStatus: IAPProductStatus.purchasable);

View file

@ -1,15 +1,15 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/screens/shared/release_notes_dialog/widget_dialog_release_notes.dart'; import 'package:lightmeter/screens/shared/release_notes_dialog/widget_dialog_release_notes.dart';
import 'package:package_info_plus/package_info_plus.dart'; import 'package:lightmeter/utils/platform_utils.dart';
class VersionListTile extends StatelessWidget { class VersionListTile extends StatelessWidget {
const VersionListTile({super.key}); const VersionListTile({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FutureBuilder<PackageInfo>( return FutureBuilder<({String buildNumber, String version})>(
future: PackageInfo.fromPlatform(), future: const PlatformUtils().buildVersion,
builder: (context, snapshot) => ListTile( builder: (context, snapshot) => ListTile(
leading: const Icon(Icons.info_outline), leading: const Icon(Icons.info_outline),
title: Text(S.of(context).version), title: Text(S.of(context).version),

View file

@ -3,19 +3,23 @@ import 'dart:async';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/shared_prefs_service.dart'; import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/screens/shared/release_notes_dialog/state_release_notes.dart'; import 'package:lightmeter/screens/shared/release_notes_dialog/state_release_notes.dart';
import 'package:package_info_plus/package_info_plus.dart'; import 'package:lightmeter/utils/platform_utils.dart';
class ReleaseNotesBloc extends Cubit<ReleaseNotesState> { class ReleaseNotesBloc extends Cubit<ReleaseNotesState> {
final UserPreferencesService _userPreferencesService; final UserPreferencesService _userPreferencesService;
final PlatformUtils _platformUtils;
ReleaseNotesBloc(this._userPreferencesService) : super(const HiddenReleaseNotesDialogState()) { ReleaseNotesBloc(
this._userPreferencesService,
this._platformUtils,
) : super(const HiddenReleaseNotesDialogState()) {
_showDialogIfNeeded(); _showDialogIfNeeded();
} }
Future<void> _showDialogIfNeeded() async { Future<void> _showDialogIfNeeded() async {
PackageInfo.fromPlatform().then((value) { _platformUtils.version.then((version) {
if (value.version != _userPreferencesService.seenChangelogVersion) { if (version != _userPreferencesService.seenChangelogVersion) {
emit(ShowReleaseNotesDialogState(value.version)); emit(ShowReleaseNotesDialogState(version));
} }
}); });
} }

View file

@ -4,6 +4,7 @@ import 'package:lightmeter/providers/services_provider.dart';
import 'package:lightmeter/screens/shared/release_notes_dialog/bloc_release_notes.dart'; import 'package:lightmeter/screens/shared/release_notes_dialog/bloc_release_notes.dart';
import 'package:lightmeter/screens/shared/release_notes_dialog/state_release_notes.dart'; import 'package:lightmeter/screens/shared/release_notes_dialog/state_release_notes.dart';
import 'package:lightmeter/screens/shared/release_notes_dialog/widget_dialog_release_notes.dart'; import 'package:lightmeter/screens/shared/release_notes_dialog/widget_dialog_release_notes.dart';
import 'package:lightmeter/utils/platform_utils.dart';
class ReleaseNotesFlow extends StatelessWidget { class ReleaseNotesFlow extends StatelessWidget {
final Widget child; final Widget child;
@ -13,7 +14,10 @@ class ReleaseNotesFlow extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider( return BlocProvider(
create: (context) => ReleaseNotesBloc(ServicesProvider.of(context).userPreferencesService), create: (context) => ReleaseNotesBloc(
ServicesProvider.of(context).userPreferencesService,
const PlatformUtils(),
),
child: BlocListener<ReleaseNotesBloc, ReleaseNotesState>( child: BlocListener<ReleaseNotesBloc, ReleaseNotesState>(
listener: (context, state) { listener: (context, state) {
if (state is ShowReleaseNotesDialogState) { if (state is ShowReleaseNotesDialogState) {

View file

@ -0,0 +1,10 @@
import 'package:package_info_plus/package_info_plus.dart';
class PlatformUtils {
const PlatformUtils();
Future<String> get version async => (await PackageInfo.fromPlatform()).version;
Future<({String version, String buildNumber})> get buildVersion async =>
PackageInfo.fromPlatform().then((value) => (version: value.version, buildNumber: value.buildNumber));
}

View file

@ -22,6 +22,7 @@ import 'package:lightmeter/screens/settings/components/metering/components/equip
import 'package:lightmeter/screens/settings/screen_settings.dart'; import 'package:lightmeter/screens/settings/screen_settings.dart';
import 'package:lightmeter/screens/shared/animated_circular_button/widget_button_circular_animated.dart'; import 'package:lightmeter/screens/shared/animated_circular_button/widget_button_circular_animated.dart';
import 'package:lightmeter/screens/timer/screen_timer.dart'; import 'package:lightmeter/screens/timer/screen_timer.dart';
import 'package:lightmeter/utils/platform_utils.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -42,13 +43,13 @@ void main() {
final binding = IntegrationTestWidgetsFlutterBinding(); final binding = IntegrationTestWidgetsFlutterBinding();
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); IntegrationTestWidgetsFlutterBinding.ensureInitialized();
void mockSharedPrefs({ Future<void> mockSharedPrefs({
int iso = 400, int iso = 400,
int nd = 0, int nd = 0,
double calibration = 0.0, double calibration = 0.0,
required ThemeType theme, required ThemeType theme,
required Color color, required Color color,
}) { }) async {
SharedPreferences.setMockInitialValues({ SharedPreferences.setMockInitialValues({
/// Metering values /// Metering values
UserPreferencesService.evSourceTypeKey: EvSourceType.camera.index, UserPreferencesService.evSourceTypeKey: EvSourceType.camera.index,
@ -78,6 +79,8 @@ void main() {
UserPreferencesService.themeTypeKey: theme.index, UserPreferencesService.themeTypeKey: theme.index,
UserPreferencesService.primaryColorKey: color.value, UserPreferencesService.primaryColorKey: color.value,
UserPreferencesService.dynamicColorKey: false, UserPreferencesService.dynamicColorKey: false,
UserPreferencesService.seenChangelogVersionKey: await const PlatformUtils().version,
}); });
} }
@ -87,7 +90,7 @@ void main() {
/// Generates several screenshots with the light theme /// Generates several screenshots with the light theme
testWidgets('Generate light theme screenshots', (tester) async { testWidgets('Generate light theme screenshots', (tester) async {
mockSharedPrefs(theme: ThemeType.light, color: _lightThemeColor); await mockSharedPrefs(theme: ThemeType.light, color: _lightThemeColor);
await tester.pumpApplication( await tester.pumpApplication(
availableFilms: [_mockFilm], availableFilms: [_mockFilm],
filmsInUse: [_mockFilm], filmsInUse: [_mockFilm],
@ -127,7 +130,7 @@ void main() {
testWidgets( testWidgets(
'Generate dark theme screenshots', 'Generate dark theme screenshots',
(tester) async { (tester) async {
mockSharedPrefs(theme: ThemeType.dark, color: _darkThemeColor); await mockSharedPrefs(theme: ThemeType.dark, color: _darkThemeColor);
await tester.pumpApplication( await tester.pumpApplication(
availableFilms: [_mockFilm], availableFilms: [_mockFilm],
filmsInUse: [_mockFilm], filmsInUse: [_mockFilm],
@ -146,7 +149,7 @@ void main() {
ApertureValue(16, StopType.full), ApertureValue(16, StopType.full),
ShutterSpeedValue(8, false, StopType.full), ShutterSpeedValue(8, false, StopType.full),
); );
mockSharedPrefs( await mockSharedPrefs(
iso: 100, iso: 100,
nd: 8, nd: 8,
calibration: -0.3, calibration: -0.3,