mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-21 23:10:40 +00:00
fixed integration tests
This commit is contained in:
parent
7db43fb83b
commit
274cfc3469
6 changed files with 88 additions and 40 deletions
|
@ -47,7 +47,11 @@ void testE2E(String description) {
|
||||||
testWidgets(
|
testWidgets(
|
||||||
description,
|
description,
|
||||||
(tester) async {
|
(tester) async {
|
||||||
await tester.pumpApplication(equipmentProfiles: [], filmsInUse: []);
|
await tester.pumpApplication(
|
||||||
|
equipmentProfiles: [],
|
||||||
|
predefinedFilms: mockFilms.toFilmsMap(isUsed: true),
|
||||||
|
customFilms: {},
|
||||||
|
);
|
||||||
|
|
||||||
/// Create Praktica + Zenitar profile from scratch
|
/// Create Praktica + Zenitar profile from scratch
|
||||||
await tester.openSettings();
|
await tester.openSettings();
|
||||||
|
@ -76,11 +80,6 @@ void testE2E(String description) {
|
||||||
expect(find.text('f/3.5 - f/22'), findsOneWidget);
|
expect(find.text('f/3.5 - f/22'), findsOneWidget);
|
||||||
expect(find.text('1/1000 - B'), findsNWidgets(2));
|
expect(find.text('1/1000 - B'), findsNWidgets(2));
|
||||||
await tester.navigatorPop();
|
await tester.navigatorPop();
|
||||||
|
|
||||||
/// Select some films
|
|
||||||
await tester.tap(find.text(S.current.filmsInUse));
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
await tester.setDialogFilterValues<Film>([mockFilms[0], mockFilms[1]], deselectAll: false);
|
|
||||||
await tester.navigatorPop();
|
await tester.navigatorPop();
|
||||||
|
|
||||||
/// Select some initial settings according to the selected gear and film
|
/// Select some initial settings according to the selected gear and film
|
||||||
|
|
|
@ -135,7 +135,7 @@ void testToggleLayoutFeatures(String description) {
|
||||||
testWidgets(
|
testWidgets(
|
||||||
'Film picker',
|
'Film picker',
|
||||||
(tester) async {
|
(tester) async {
|
||||||
await tester.pumpApplication(selectedFilm: mockFilms.first);
|
await tester.pumpApplication(selectedFilmId: mockFilms.first.id);
|
||||||
await tester.takePhoto();
|
await tester.takePhoto();
|
||||||
expectPickerTitle<FilmPicker>(mockFilms.first.name);
|
expectPickerTitle<FilmPicker>(mockFilms.first.name);
|
||||||
expectExtremeExposurePairs('f/1.0 - 1/320', 'f/45 - 12"');
|
expectExtremeExposurePairs('f/1.0 - 1/320', 'f/45 - 12"');
|
||||||
|
|
|
@ -7,24 +7,27 @@ import 'package:mocktail/mocktail.dart';
|
||||||
|
|
||||||
class _MockIAPStorageService extends Mock implements IAPStorageService {}
|
class _MockIAPStorageService extends Mock implements IAPStorageService {}
|
||||||
|
|
||||||
|
class _MockFilmsStorageService extends Mock implements FilmsStorageService {}
|
||||||
|
|
||||||
class MockIAPProviders extends StatefulWidget {
|
class MockIAPProviders extends StatefulWidget {
|
||||||
final List<EquipmentProfile>? equipmentProfiles;
|
final List<EquipmentProfile>? equipmentProfiles;
|
||||||
final String selectedEquipmentProfileId;
|
final String selectedEquipmentProfileId;
|
||||||
final List<Film> availableFilms;
|
final Map<String, SelectableFilm<Film>> predefinedFilms;
|
||||||
final List<Film> filmsInUse;
|
final Map<String, SelectableFilm<FilmExponential>> customFilms;
|
||||||
final Film selectedFilm;
|
final String selectedFilmId;
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
|
||||||
const MockIAPProviders({
|
MockIAPProviders({
|
||||||
this.equipmentProfiles = const [],
|
this.equipmentProfiles = const [],
|
||||||
this.selectedEquipmentProfileId = '',
|
this.selectedEquipmentProfileId = '',
|
||||||
List<Film>? availableFilms,
|
Map<String, SelectableFilm<Film>>? predefinedFilms,
|
||||||
List<Film>? filmsInUse,
|
Map<String, SelectableFilm<FilmExponential>>? customFilms,
|
||||||
this.selectedFilm = const FilmStub(),
|
String? selectedFilmId,
|
||||||
required this.child,
|
required this.child,
|
||||||
super.key,
|
super.key,
|
||||||
}) : availableFilms = availableFilms ?? mockFilms,
|
}) : predefinedFilms = predefinedFilms ?? mockFilms.toFilmsMap(),
|
||||||
filmsInUse = filmsInUse ?? mockFilms;
|
customFilms = customFilms ?? mockFilms.toFilmsMap(),
|
||||||
|
selectedFilmId = selectedFilmId ?? const FilmStub().id;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<MockIAPProviders> createState() => _MockIAPProvidersState();
|
State<MockIAPProviders> createState() => _MockIAPProvidersState();
|
||||||
|
@ -32,6 +35,7 @@ class MockIAPProviders extends StatefulWidget {
|
||||||
|
|
||||||
class _MockIAPProvidersState extends State<MockIAPProviders> {
|
class _MockIAPProvidersState extends State<MockIAPProviders> {
|
||||||
late final _MockIAPStorageService mockIAPStorageService;
|
late final _MockIAPStorageService mockIAPStorageService;
|
||||||
|
late final _MockFilmsStorageService mockFilmsStorageService;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
@ -39,8 +43,11 @@ class _MockIAPProvidersState extends State<MockIAPProviders> {
|
||||||
mockIAPStorageService = _MockIAPStorageService();
|
mockIAPStorageService = _MockIAPStorageService();
|
||||||
when(() => mockIAPStorageService.equipmentProfiles).thenReturn(widget.equipmentProfiles ?? mockEquipmentProfiles);
|
when(() => mockIAPStorageService.equipmentProfiles).thenReturn(widget.equipmentProfiles ?? mockEquipmentProfiles);
|
||||||
when(() => mockIAPStorageService.selectedEquipmentProfileId).thenReturn(widget.selectedEquipmentProfileId);
|
when(() => mockIAPStorageService.selectedEquipmentProfileId).thenReturn(widget.selectedEquipmentProfileId);
|
||||||
when(() => mockIAPStorageService.filmsInUse).thenReturn(widget.filmsInUse);
|
|
||||||
when(() => mockIAPStorageService.selectedFilm).thenReturn(widget.selectedFilm);
|
mockFilmsStorageService = _MockFilmsStorageService();
|
||||||
|
when(() => mockFilmsStorageService.getPredefinedFilms()).thenAnswer((_) => Future.value(widget.predefinedFilms));
|
||||||
|
when(() => mockFilmsStorageService.getCustomFilms()).thenAnswer((_) => Future.value(widget.customFilms));
|
||||||
|
when(() => mockFilmsStorageService.selectedFilmId).thenReturn(widget.selectedFilmId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -48,8 +55,7 @@ class _MockIAPProvidersState extends State<MockIAPProviders> {
|
||||||
return EquipmentProfileProvider(
|
return EquipmentProfileProvider(
|
||||||
storageService: mockIAPStorageService,
|
storageService: mockIAPStorageService,
|
||||||
child: FilmsProvider(
|
child: FilmsProvider(
|
||||||
storageService: mockIAPStorageService,
|
filmsStorageService: mockFilmsStorageService,
|
||||||
availableFilms: widget.availableFilms,
|
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -129,8 +135,51 @@ final mockEquipmentProfiles = [
|
||||||
];
|
];
|
||||||
|
|
||||||
const mockFilms = [
|
const mockFilms = [
|
||||||
FilmExponential(id: '1', name: 'Mock film 1', iso: 100, exponent: 1.34),
|
FilmMultiplying(id: '1', name: 'Mock film 1', iso: 100, reciprocityMultiplier: 2),
|
||||||
FilmExponential(id: '2', name: 'Mock film 2', iso: 400, exponent: 1.34),
|
FilmMultiplying(id: '2', name: 'Mock film 2', iso: 400, reciprocityMultiplier: 2),
|
||||||
FilmExponential(id: '3', name: 'Mock film 3', iso: 800, exponent: 1.34),
|
FilmMultiplying(id: '3', name: 'Mock film 3', iso: 800, reciprocityMultiplier: 3),
|
||||||
FilmExponential(id: '4', name: 'Mock film 4', iso: 1200, exponent: 1.34),
|
FilmMultiplying(id: '4', name: 'Mock film 4', iso: 1200, reciprocityMultiplier: 1.5),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
extension FilmMapper on List<Film> {
|
||||||
|
Map<String, ({T film, bool isUsed})> toFilmsMap<T extends Film>({bool isUsed = true}) =>
|
||||||
|
Map.fromEntries(map((e) => MapEntry(e.id, (film: e as T, isUsed: isUsed))));
|
||||||
|
}
|
||||||
|
|
||||||
|
class FilmMultiplying extends FilmExponential {
|
||||||
|
final double reciprocityMultiplier;
|
||||||
|
|
||||||
|
const FilmMultiplying({
|
||||||
|
String? id,
|
||||||
|
required super.name,
|
||||||
|
required super.iso,
|
||||||
|
required this.reciprocityMultiplier,
|
||||||
|
}) : super(id: id ?? name, exponent: 1);
|
||||||
|
|
||||||
|
@override
|
||||||
|
ShutterSpeedValue reciprocityFailure(ShutterSpeedValue shutterSpeed) {
|
||||||
|
if (shutterSpeed.isFraction) {
|
||||||
|
return shutterSpeed;
|
||||||
|
} else {
|
||||||
|
return ShutterSpeedValue(
|
||||||
|
shutterSpeed.rawValue * reciprocityMultiplier,
|
||||||
|
shutterSpeed.isFraction,
|
||||||
|
shutterSpeed.stopType,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (identical(this, other)) return true;
|
||||||
|
if (other.runtimeType != runtimeType) return false;
|
||||||
|
return other is FilmMultiplying &&
|
||||||
|
other.id == id &&
|
||||||
|
other.name == name &&
|
||||||
|
other.iso == iso &&
|
||||||
|
other.reciprocityMultiplier == reciprocityMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => Object.hash(id, name, iso, reciprocityMultiplier, runtimeType);
|
||||||
|
}
|
||||||
|
|
|
@ -22,9 +22,9 @@ extension WidgetTesterCommonActions on WidgetTester {
|
||||||
IAPProductStatus productStatus = IAPProductStatus.purchased,
|
IAPProductStatus productStatus = IAPProductStatus.purchased,
|
||||||
List<EquipmentProfile>? equipmentProfiles,
|
List<EquipmentProfile>? equipmentProfiles,
|
||||||
String selectedEquipmentProfileId = '',
|
String selectedEquipmentProfileId = '',
|
||||||
List<Film>? availableFilms,
|
Map<String, SelectableFilm<Film>>? predefinedFilms,
|
||||||
List<Film>? filmsInUse,
|
Map<String, SelectableFilm<FilmExponential>>? customFilms,
|
||||||
Film selectedFilm = const FilmStub(),
|
String selectedFilmId = '',
|
||||||
}) async {
|
}) async {
|
||||||
await pumpWidget(
|
await pumpWidget(
|
||||||
MockIAPProductsProvider(
|
MockIAPProductsProvider(
|
||||||
|
@ -34,9 +34,9 @@ extension WidgetTesterCommonActions on WidgetTester {
|
||||||
child: MockIAPProviders(
|
child: MockIAPProviders(
|
||||||
equipmentProfiles: equipmentProfiles,
|
equipmentProfiles: equipmentProfiles,
|
||||||
selectedEquipmentProfileId: selectedEquipmentProfileId,
|
selectedEquipmentProfileId: selectedEquipmentProfileId,
|
||||||
availableFilms: availableFilms,
|
predefinedFilms: predefinedFilms,
|
||||||
filmsInUse: filmsInUse,
|
customFilms: customFilms,
|
||||||
selectedFilm: selectedFilm,
|
selectedFilmId: selectedFilmId,
|
||||||
child: const Application(),
|
child: const Application(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -92,9 +92,9 @@ void main() {
|
||||||
testWidgets('Generate light theme screenshots', (tester) async {
|
testWidgets('Generate light theme screenshots', (tester) async {
|
||||||
await mockSharedPrefs(theme: ThemeType.light, color: _lightThemeColor);
|
await mockSharedPrefs(theme: ThemeType.light, color: _lightThemeColor);
|
||||||
await tester.pumpApplication(
|
await tester.pumpApplication(
|
||||||
availableFilms: [_mockFilm],
|
predefinedFilms: [_mockFilm].toFilmsMap(),
|
||||||
filmsInUse: [_mockFilm],
|
customFilms: {},
|
||||||
selectedFilm: _mockFilm,
|
selectedFilmId: _mockFilm.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
await tester.takePhoto();
|
await tester.takePhoto();
|
||||||
|
@ -132,9 +132,9 @@ void main() {
|
||||||
(tester) async {
|
(tester) async {
|
||||||
await mockSharedPrefs(theme: ThemeType.dark, color: _darkThemeColor);
|
await mockSharedPrefs(theme: ThemeType.dark, color: _darkThemeColor);
|
||||||
await tester.pumpApplication(
|
await tester.pumpApplication(
|
||||||
availableFilms: [_mockFilm],
|
predefinedFilms: [_mockFilm].toFilmsMap(),
|
||||||
filmsInUse: [_mockFilm],
|
customFilms: {},
|
||||||
selectedFilm: _mockFilm,
|
selectedFilmId: _mockFilm.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
await tester.takePhoto();
|
await tester.takePhoto();
|
||||||
|
@ -157,9 +157,9 @@ void main() {
|
||||||
color: _lightThemeColor,
|
color: _lightThemeColor,
|
||||||
);
|
);
|
||||||
await tester.pumpApplication(
|
await tester.pumpApplication(
|
||||||
availableFilms: [_mockFilm],
|
predefinedFilms: [_mockFilm].toFilmsMap(),
|
||||||
filmsInUse: [_mockFilm],
|
customFilms: {},
|
||||||
selectedFilm: _mockFilm,
|
selectedFilmId: _mockFilm.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
await tester.takePhoto();
|
await tester.takePhoto();
|
||||||
|
|
|
@ -99,7 +99,7 @@ class _GoldenTestApplicationMockState extends State<GoldenTestApplicationMock> {
|
||||||
child: MockIAPProviders(
|
child: MockIAPProviders(
|
||||||
equipmentProfiles: mockEquipmentProfiles,
|
equipmentProfiles: mockEquipmentProfiles,
|
||||||
selectedEquipmentProfileId: mockEquipmentProfiles.first.id,
|
selectedEquipmentProfileId: mockEquipmentProfiles.first.id,
|
||||||
selectedFilm: mockFilms.first,
|
selectedFilmId: mockFilms.first.id,
|
||||||
child: Builder(
|
child: Builder(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
|
|
Loading…
Reference in a new issue