2023-10-20 14:12:43 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:lightmeter/application.dart';
|
|
|
|
import 'package:lightmeter/application_wrapper.dart';
|
|
|
|
import 'package:lightmeter/environment.dart';
|
|
|
|
import 'package:lightmeter/generated/l10n.dart';
|
|
|
|
import 'package:lightmeter/res/dimens.dart';
|
2024-03-13 14:34:26 +00:00
|
|
|
import 'package:lightmeter/screens/metering/components/shared/exposure_pairs_list/widget_list_exposure_pairs.dart';
|
|
|
|
import 'package:lightmeter/screens/metering/screen_metering.dart';
|
2023-10-20 14:12:43 +00:00
|
|
|
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
|
|
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
|
|
|
|
2024-03-13 14:34:26 +00:00
|
|
|
import '../mocks/iap_products_mock.dart';
|
2023-10-20 14:12:43 +00:00
|
|
|
import '../mocks/paid_features_mock.dart';
|
2024-05-07 17:24:51 +00:00
|
|
|
import 'finder_actions.dart';
|
2023-10-20 14:12:43 +00:00
|
|
|
import 'platform_channel_mock.dart';
|
|
|
|
|
2024-03-13 14:34:26 +00:00
|
|
|
const mockPhotoEv100 = 8.3;
|
|
|
|
|
2023-10-20 14:12:43 +00:00
|
|
|
extension WidgetTesterCommonActions on WidgetTester {
|
|
|
|
Future<void> pumpApplication({
|
|
|
|
IAPProductStatus productStatus = IAPProductStatus.purchased,
|
2024-11-11 13:27:03 +00:00
|
|
|
TogglableMap<EquipmentProfile>? equipmentProfiles,
|
2023-10-20 14:12:43 +00:00
|
|
|
String selectedEquipmentProfileId = '',
|
2024-11-11 13:27:03 +00:00
|
|
|
TogglableMap<Film>? predefinedFilms,
|
|
|
|
TogglableMap<FilmExponential>? customFilms,
|
2024-11-03 19:16:01 +00:00
|
|
|
String selectedFilmId = '',
|
2023-10-20 14:12:43 +00:00
|
|
|
}) async {
|
|
|
|
await pumpWidget(
|
2024-03-13 14:34:26 +00:00
|
|
|
MockIAPProductsProvider(
|
|
|
|
initialyPurchased: productStatus == IAPProductStatus.purchased,
|
2023-10-20 14:12:43 +00:00
|
|
|
child: ApplicationWrapper(
|
|
|
|
const Environment.dev(),
|
|
|
|
child: MockIAPProviders(
|
2024-03-13 14:34:26 +00:00
|
|
|
equipmentProfiles: equipmentProfiles,
|
2023-10-20 14:12:43 +00:00
|
|
|
selectedEquipmentProfileId: selectedEquipmentProfileId,
|
2024-11-03 19:16:01 +00:00
|
|
|
predefinedFilms: predefinedFilms,
|
|
|
|
customFilms: customFilms,
|
|
|
|
selectedFilmId: selectedFilmId,
|
2023-10-20 14:12:43 +00:00
|
|
|
child: const Application(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
await pumpAndSettle();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> takePhoto() async {
|
2024-05-07 17:24:51 +00:00
|
|
|
await tap(find.measureButton());
|
2023-10-20 14:12:43 +00:00
|
|
|
await pump(const Duration(seconds: 2)); // wait for circular progress indicator
|
|
|
|
await pump(const Duration(seconds: 1)); // wait for circular progress indicator
|
|
|
|
await pumpAndSettle();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> toggleIncidentMetering(double ev) async {
|
2024-05-07 17:24:51 +00:00
|
|
|
await tap(find.measureButton());
|
2023-10-20 14:12:43 +00:00
|
|
|
await sendMockIncidentEv(ev);
|
2024-05-07 17:24:51 +00:00
|
|
|
await tap(find.measureButton());
|
2023-10-20 14:12:43 +00:00
|
|
|
await pumpAndSettle();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> openAnimatedPicker<T>() async {
|
|
|
|
await tap(find.byType(T));
|
|
|
|
await pumpAndSettle(Dimens.durationL);
|
|
|
|
}
|
2024-03-13 14:34:26 +00:00
|
|
|
|
|
|
|
Future<void> openSettings() async {
|
|
|
|
await tap(find.byTooltip(S.current.tooltipOpenSettings));
|
|
|
|
await pumpAndSettle();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> navigatorPop() async {
|
|
|
|
(state(find.byType(Navigator)) as NavigatorState).pop();
|
|
|
|
await pumpAndSettle(Dimens.durationML);
|
|
|
|
}
|
2023-10-20 14:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extension WidgetTesterListTileActions on WidgetTester {
|
|
|
|
/// Useful for tapping a specific [ListTile] inside a specific screen or dialog
|
|
|
|
Future<void> tapDescendantTextOf<T>(String text) async {
|
|
|
|
await tap(find.descendant(of: find.byType(T), matching: find.text(text)));
|
2024-02-21 11:33:25 +00:00
|
|
|
await pumpAndSettle();
|
2023-10-20 14:12:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension WidgetTesterTextButtonActions on WidgetTester {
|
|
|
|
Future<void> tapSelectButton() => _tapTextButton(S.current.select);
|
|
|
|
|
|
|
|
Future<void> tapCancelButton() => _tapTextButton(S.current.cancel);
|
|
|
|
|
|
|
|
Future<void> tapSaveButton() => _tapTextButton(S.current.save);
|
|
|
|
|
|
|
|
Future<void> _tapTextButton(String text) async {
|
|
|
|
final button = find.byWidgetPredicate(
|
|
|
|
(widget) => widget is TextButton && widget.child is Text && (widget.child as Text?)?.data == text,
|
|
|
|
);
|
|
|
|
expect(button, findsOneWidget);
|
|
|
|
await tap(button);
|
|
|
|
await pumpAndSettle();
|
|
|
|
}
|
|
|
|
}
|
2024-03-13 14:34:26 +00:00
|
|
|
|
|
|
|
extension WidgetTesterExposurePairsListActions on WidgetTester {
|
|
|
|
Future<void> scrollToTheLastExposurePair({
|
|
|
|
double ev = mockPhotoEv100,
|
|
|
|
StopType stopType = StopType.third,
|
|
|
|
EquipmentProfile equipmentProfile = defaultEquipmentProfile,
|
|
|
|
}) async {
|
|
|
|
final exposurePairs = MeteringContainerBuidler.buildExposureValues(
|
|
|
|
ev,
|
|
|
|
StopType.third,
|
|
|
|
equipmentProfile,
|
|
|
|
);
|
|
|
|
await scrollUntilVisible(
|
|
|
|
find.byWidgetPredicate((widget) => widget is Row && widget.key == ValueKey(exposurePairs.length - 1)),
|
|
|
|
56,
|
|
|
|
scrollable: find.descendant(of: find.byType(ExposurePairsList), matching: find.byType(Scrollable)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|