mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-21 15:00:40 +00:00
ML-62 Utils tests (#133)
* removed redundant `UserPreferencesService` from `MeteringBloc` * wip * post-merge fixes * `MeasureEvent` tests * `MeasureEvent` tests revision * `MeasureEvent` tests added timeout * added stubs for other `MeteringBloc` events * rewritten `MeteringBloc` logic * wip * `IsoChangedEvent` tests * refined `IsoChangedEvent` tests * `NdChangedEvent` tests * `FilmChangedEvent` tests * `MeteringCommunicationBloc` tests * added test run to ci * overriden `==` for `MeasuredState` * `LuxMeteringEvent` tests * refined `LuxMeteringEvent` tests * rename * wip * wip * `InitializeEvent`/`DeinitializeEvent` tests * clamp minZoomLevel * fixed `MeteringCommunicationBloc` tests * wip * `ZoomChangedEvent` tests * `ExposureOffsetChangedEvent`/`ExposureOffsetResetEvent` tests * renamed test groups * added test coverage script * improved `CameraContainerBloc` test coverage * `EquipmentProfileChangedEvent` tests * verify response vibration * fixed running all tests * `MeteringCommunicationBloc` equality tests * `CameraContainerBloc` equality tests * removed generated code from coverage * `MeteringScreenLayoutFeature` tests * `SupportedLocale` tests * `Film` tests * `CaffeineService` tests * `UserPreferencesService` tests (wip) * `LightSensorService` tests (wip) * `migrateOldKeys()` tests * ignore currently unused getters & setters * gradle upgrade * `reset(sharedPreferences);` calls count * typo * `MeteringInteractor` tests * `SettingsInteractor` tests (wip) * `MeteringInteractor` tests (wip) * `SettingsInteractor` tests * AnimatedDialog picker standalone tests * Moved Animated dialog picker to widget tests * `ExtremeExposurePairsContainer` widget test * dialog picker test * Match extreme exposure pairs & pairs list edge values * `FilmPicker` widget tests * fixed animated dialog picker tests * add not hit files to coverage percentage * Moved `EquipmentProfileProvider` & `FilmsProvider` to the main repo * Synced _iap_ stub with repo * `FilmsProvider` tests * `EquipmentProfileProvider` tests * Pass `availableFilms` to `FilmsProvider` * `FilmPicker` tests * removed unnecessary imports * Metering layout features tests * split integration tests by screens * Films in use test * mock light meter lux stream * removed mockito mocks for integration tests From no on these are the only mocks in use: - Mock shared prefs initial values - Mock platform responses (camera/light sensor) * set sharedprefs mock without redundant group * unified granting camera permission on Android * fixed metering screen tests * extracted common values * `FilmPicker` integration tests * fixed light sensor platform mocks * wip * removed integration tests for now * moved screenshots generator to screenshots folder * typo * removed `MockIAPProductsProvider` * implemented platform mocks for unit tests * data/models/ 100% coverage * `IsoValuePicker` tests * `EquipmentProfileProvider` tests * extended PR check timeout * typo * added storage action verification for `FilmsProvider` tests * `UserPreferencesProvider` tests * Update README.md * added //coverage:ignore to `ServicesProvider` * typo * typo * `toStringSignedAsFixed` tests * `SelectableInheritedModel` tests * removed unused `TextLineHeight` util * `VolumeKeysNotifier` tests * import * `EquipmentProfileListener` tests * typo * split `EquipmentProfileListener` tests * `showBuyProDialog` tests * added `maybeOf` getter for iap stub
This commit is contained in:
parent
37a3b79f04
commit
3bb3f12641
25 changed files with 379 additions and 52 deletions
|
@ -6,8 +6,10 @@ class IAPProductsProvider extends StatefulWidget {
|
|||
|
||||
const IAPProductsProvider({required this.child, super.key});
|
||||
|
||||
static IAPProductsProviderState of(BuildContext context) {
|
||||
return context.findAncestorStateOfType<IAPProductsProviderState>()!;
|
||||
static IAPProductsProviderState of(BuildContext context) => IAPProductsProvider.maybeOf(context)!;
|
||||
|
||||
static IAPProductsProviderState? maybeOf(BuildContext context) {
|
||||
return context.findAncestorStateOfType<IAPProductsProviderState>();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -54,8 +56,7 @@ class IAPProducts extends InheritedModel<IAPProductType> {
|
|||
bool updateShouldNotify(IAPProducts oldWidget) => false;
|
||||
|
||||
@override
|
||||
bool updateShouldNotifyDependent(IAPProducts oldWidget, Set<IAPProductType> dependencies) =>
|
||||
false;
|
||||
bool updateShouldNotifyDependent(IAPProducts oldWidget, Set<IAPProductType> dependencies) => false;
|
||||
|
||||
IAPProduct? _findProduct(IAPProductType type) {
|
||||
try {
|
||||
|
|
|
@ -3,7 +3,7 @@ import 'package:flutter/services.dart';
|
|||
import 'package:platform/platform.dart';
|
||||
|
||||
class VolumeEventsService {
|
||||
final LocalPlatform localPlatform;
|
||||
final LocalPlatform _localPlatform;
|
||||
|
||||
@visibleForTesting
|
||||
static const volumeHandlingChannel = MethodChannel("com.vodemn.lightmeter/volumeHandling");
|
||||
|
@ -11,12 +11,12 @@ class VolumeEventsService {
|
|||
@visibleForTesting
|
||||
static const volumeEventsChannel = EventChannel("com.vodemn.lightmeter/volumeEvents");
|
||||
|
||||
const VolumeEventsService(this.localPlatform);
|
||||
const VolumeEventsService(this._localPlatform);
|
||||
|
||||
/// If set to `false` we allow system to handle key events.
|
||||
/// Returns current status of volume handling.
|
||||
Future<bool> setVolumeHandling(bool enableHandling) async {
|
||||
if (!localPlatform.isAndroid) {
|
||||
if (!_localPlatform.isAndroid) {
|
||||
return false;
|
||||
}
|
||||
return volumeHandlingChannel
|
||||
|
@ -29,7 +29,7 @@ class VolumeEventsService {
|
|||
/// KEYCODE_VOLUME_DOWN = 25;
|
||||
/// pressed
|
||||
Stream<int> volumeButtonsEventStream() {
|
||||
if (!localPlatform.isAndroid) {
|
||||
if (!_localPlatform.isAndroid) {
|
||||
return const Stream.empty();
|
||||
}
|
||||
return volumeEventsChannel
|
||||
|
|
|
@ -54,9 +54,7 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
|||
_defaultProfile,
|
||||
if (IAPProducts.isPurchased(context, IAPProductType.paidFeatures)) ..._customProfiles,
|
||||
],
|
||||
selected: IAPProducts.isPurchased(context, IAPProductType.paidFeatures)
|
||||
? _selectedProfile
|
||||
: _defaultProfile,
|
||||
selected: IAPProducts.isPurchased(context, IAPProductType.paidFeatures) ? _selectedProfile : _defaultProfile,
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
|
@ -85,7 +83,7 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
|||
_refreshSavedProfiles();
|
||||
}
|
||||
|
||||
void updateProdile(EquipmentProfile data) {
|
||||
void updateProfile(EquipmentProfile data) {
|
||||
final indexToUpdate = _customProfiles.indexWhere((element) => element.id == data.id);
|
||||
if (indexToUpdate >= 0) {
|
||||
_customProfiles[indexToUpdate] = data;
|
||||
|
@ -118,13 +116,14 @@ class EquipmentProfiles extends SelectableInheritedModel<EquipmentProfile> {
|
|||
|
||||
/// [_defaultProfile] + profiles created by the user
|
||||
static List<EquipmentProfile> of(BuildContext context) {
|
||||
return InheritedModel.inheritFrom<EquipmentProfiles>(context, aspect: SelectableAspect.list)!
|
||||
.values;
|
||||
return InheritedModel.inheritFrom<EquipmentProfiles>(context, aspect: SelectableAspect.list)!.values;
|
||||
}
|
||||
|
||||
static EquipmentProfile selectedOf(BuildContext context) {
|
||||
return InheritedModel.inheritFrom<EquipmentProfiles>(context,
|
||||
aspect: SelectableAspect.selected,)!
|
||||
return InheritedModel.inheritFrom<EquipmentProfiles>(
|
||||
context,
|
||||
aspect: SelectableAspect.selected,
|
||||
)!
|
||||
.selected;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,9 @@ import 'package:lightmeter/screens/metering/communication/event_communication_me
|
|||
as communication_events;
|
||||
import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart'
|
||||
as communication_states;
|
||||
import 'package:lightmeter/screens/metering/components/shared/volume_keys_notifier/notifier_volume_keys.dart';
|
||||
import 'package:lightmeter/screens/metering/event_metering.dart';
|
||||
import 'package:lightmeter/screens/metering/state_metering.dart';
|
||||
import 'package:lightmeter/screens/metering/utils/notifier_volume_keys.dart';
|
||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||
|
||||
class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
||||
|
|
|
@ -72,7 +72,7 @@ class _Ruler extends StatelessWidget {
|
|||
children: [
|
||||
if (showValue)
|
||||
Text(
|
||||
(index + min).toStringSigned(),
|
||||
(index + min).toStringSignedAsFixed(0),
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
const SizedBox(width: Dimens.grid8),
|
||||
|
|
|
@ -4,8 +4,8 @@ import 'package:lightmeter/interactors/metering_interactor.dart';
|
|||
import 'package:lightmeter/providers/services_provider.dart';
|
||||
import 'package:lightmeter/screens/metering/bloc_metering.dart';
|
||||
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
||||
import 'package:lightmeter/screens/metering/components/shared/volume_keys_notifier/notifier_volume_keys.dart';
|
||||
import 'package:lightmeter/screens/metering/screen_metering.dart';
|
||||
import 'package:lightmeter/screens/metering/utils/notifier_volume_keys.dart';
|
||||
|
||||
class MeteringFlow extends StatefulWidget {
|
||||
const MeteringFlow({super.key});
|
||||
|
|
|
@ -13,7 +13,7 @@ import 'package:lightmeter/screens/metering/components/camera_container/provider
|
|||
import 'package:lightmeter/screens/metering/components/light_sensor_container/provider_container_light_sensor.dart';
|
||||
import 'package:lightmeter/screens/metering/event_metering.dart';
|
||||
import 'package:lightmeter/screens/metering/state_metering.dart';
|
||||
import 'package:lightmeter/screens/metering/utils/listsner_equipment_profiles.dart';
|
||||
import 'package:lightmeter/screens/metering/utils/listener_equipment_profiles.dart';
|
||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||
|
||||
class MeteringScreen extends StatelessWidget {
|
||||
|
|
|
@ -5,12 +5,12 @@ import 'package:lightmeter/data/models/volume_action.dart';
|
|||
import 'package:lightmeter/data/volume_events_service.dart';
|
||||
|
||||
class VolumeKeysNotifier extends ChangeNotifier with RouteAware {
|
||||
final VolumeEventsService volumeEventsService;
|
||||
final VolumeEventsService _volumeEventsService;
|
||||
late final StreamSubscription<VolumeKey> _volumeKeysSubscription;
|
||||
VolumeKey _value = VolumeKey.up;
|
||||
|
||||
VolumeKeysNotifier(this.volumeEventsService) {
|
||||
_volumeKeysSubscription = volumeEventsService
|
||||
VolumeKeysNotifier(this._volumeEventsService) {
|
||||
_volumeKeysSubscription = _volumeEventsService
|
||||
.volumeButtonsEventStream()
|
||||
.map((event) => event == 24 ? VolumeKey.up : VolumeKey.down)
|
||||
.listen((event) {
|
||||
|
@ -19,6 +19,8 @@ class VolumeKeysNotifier extends ChangeNotifier with RouteAware {
|
|||
}
|
||||
|
||||
VolumeKey get value => _value;
|
||||
|
||||
@protected
|
||||
set value(VolumeKey newValue) {
|
||||
_value = newValue;
|
||||
notifyListeners();
|
|
@ -4,7 +4,7 @@ import 'package:lightmeter/generated/l10n.dart';
|
|||
import 'package:lightmeter/providers/remote_config_provider.dart';
|
||||
import 'package:lightmeter/providers/services_provider.dart';
|
||||
import 'package:lightmeter/res/dimens.dart';
|
||||
import 'package:lightmeter/screens/settings/components/utils/show_buy_pro_dialog.dart';
|
||||
import 'package:lightmeter/screens/settings/utils/show_buy_pro_dialog.dart';
|
||||
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
||||
|
||||
class BuyProListTile extends StatelessWidget {
|
||||
|
|
|
@ -90,7 +90,7 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
|
|||
}
|
||||
|
||||
void _updateProfileAt(EquipmentProfile data) {
|
||||
EquipmentProfileProvider.of(context).updateProdile(data);
|
||||
EquipmentProfileProvider.of(context).updateProfile(data);
|
||||
}
|
||||
|
||||
void _removeProfileAt(EquipmentProfile data) {
|
||||
|
|
|
@ -28,7 +28,7 @@ Future<void> showBuyProDialog(BuildContext context) {
|
|||
FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
IAPProductsProvider.of(context).buy(IAPProductType.paidFeatures);
|
||||
IAPProductsProvider.maybeOf(context)?.buy(IAPProductType.paidFeatures);
|
||||
},
|
||||
child: Text(unlockFeaturesEnabled ? S.of(context).unlock : S.of(context).buy),
|
||||
),
|
|
@ -1,5 +0,0 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
|
||||
extension TextLineHeight on TextStyle {
|
||||
double get lineHeight => fontSize! * height!;
|
||||
}
|
|
@ -1,13 +1,4 @@
|
|||
extension SignedString on num {
|
||||
String toStringSigned() {
|
||||
if (this > 0) {
|
||||
return "+${toString()}";
|
||||
} else {
|
||||
return toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns value in form -1 or + 1. The only exception - 0.
|
||||
extension SignedStringDouble on double {
|
||||
String toStringSignedAsFixed(int fractionDigits) {
|
||||
if (this > 0) {
|
||||
|
|
|
@ -28,7 +28,7 @@ dependencies:
|
|||
m3_lightmeter_iap:
|
||||
git:
|
||||
url: "https://github.com/vodemn/m3_lightmeter_iap"
|
||||
ref: v0.6.3
|
||||
ref: v0.7.0
|
||||
m3_lightmeter_resources:
|
||||
git:
|
||||
url: "https://github.com/vodemn/m3_lightmeter_resources"
|
||||
|
|
7
test/function_mock.dart
Normal file
7
test/function_mock.dart
Normal file
|
@ -0,0 +1,7 @@
|
|||
import 'package:mocktail/mocktail.dart';
|
||||
|
||||
class _ValueChanged<T> {
|
||||
void onChanged(T value) {}
|
||||
}
|
||||
|
||||
class MockValueChanged<T> extends Mock implements _ValueChanged<T> {}
|
|
@ -236,7 +236,7 @@ void main() {
|
|||
);
|
||||
|
||||
group(
|
||||
'Haptics',
|
||||
'Light sensor',
|
||||
() {
|
||||
test('hasAmbientLightSensor() - true', () async {
|
||||
when(() => mockLightSensorService.hasSensor()).thenAnswer((_) async => true);
|
||||
|
|
|
@ -260,7 +260,7 @@ class _Application extends StatelessWidget {
|
|||
ElevatedButton(
|
||||
key: updateProfileButtonKey(profile.id),
|
||||
onPressed: () {
|
||||
EquipmentProfileProvider.of(context).updateProdile(
|
||||
EquipmentProfileProvider.of(context).updateProfile(
|
||||
profile.copyWith(
|
||||
name: '${profile.name} updated',
|
||||
isoValues: _customProfiles.first.isoValues,
|
||||
|
|
|
@ -7,9 +7,9 @@ import 'package:lightmeter/screens/metering/communication/event_communication_me
|
|||
as communication_events;
|
||||
import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart'
|
||||
as communication_states;
|
||||
import 'package:lightmeter/screens/metering/components/shared/volume_keys_notifier/notifier_volume_keys.dart';
|
||||
import 'package:lightmeter/screens/metering/event_metering.dart';
|
||||
import 'package:lightmeter/screens/metering/state_metering.dart';
|
||||
import 'package:lightmeter/screens/metering/utils/notifier_volume_keys.dart';
|
||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
|
|
@ -7,16 +7,11 @@ import 'package:lightmeter/screens/metering/components/shared/readings_container
|
|||
import 'package:mocktail/mocktail.dart';
|
||||
|
||||
import '../../../../../../application_mock.dart';
|
||||
import '../../../../../../function_mock.dart';
|
||||
import '../utils.dart';
|
||||
|
||||
class _ValueChanged {
|
||||
void onChanged<T>(T value) {}
|
||||
}
|
||||
|
||||
class _MockValueChanged extends Mock implements _ValueChanged {}
|
||||
|
||||
void main() {
|
||||
final functions = _MockValueChanged();
|
||||
final functions = MockValueChanged<int>();
|
||||
|
||||
group(
|
||||
'onChanged',
|
||||
|
|
|
@ -0,0 +1,138 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
||||
import 'package:lightmeter/screens/metering/utils/listener_equipment_profiles.dart';
|
||||
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
|
||||
import '../../../function_mock.dart';
|
||||
|
||||
class _MockIAPStorageService extends Mock implements IAPStorageService {}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
final storageService = _MockIAPStorageService();
|
||||
final equipmentProfileProviderKey = GlobalKey<EquipmentProfileProviderState>();
|
||||
final onDidChangeDependencies = MockValueChanged<EquipmentProfile>();
|
||||
|
||||
tearDown(() {
|
||||
reset(onDidChangeDependencies);
|
||||
reset(storageService);
|
||||
});
|
||||
|
||||
Future<void> pumpTestWidget(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
IAPProducts(
|
||||
products: [
|
||||
IAPProduct(
|
||||
storeId: IAPProductType.paidFeatures.storeId,
|
||||
status: IAPProductStatus.purchased,
|
||||
),
|
||||
],
|
||||
child: EquipmentProfileProvider(
|
||||
key: equipmentProfileProviderKey,
|
||||
storageService: storageService,
|
||||
child: MaterialApp(
|
||||
home: EquipmentProfileListener(
|
||||
onDidChangeDependencies: onDidChangeDependencies.onChanged,
|
||||
child: Builder(builder: (context) => Text(EquipmentProfiles.selectedOf(context).name)),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'Trigger `onDidChangeDependencies` by selecting a new profile',
|
||||
(tester) async {
|
||||
when(() => storageService.equipmentProfiles).thenReturn(List.from(_customProfiles));
|
||||
when(() => storageService.selectedEquipmentProfileId).thenReturn('');
|
||||
await pumpTestWidget(tester);
|
||||
|
||||
equipmentProfileProviderKey.currentState!.setProfile(_customProfiles[0]);
|
||||
await tester.pump();
|
||||
verify(() => onDidChangeDependencies.onChanged(_customProfiles[0])).called(1);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'Trigger `onDidChangeDependencies` by updating the selected profile',
|
||||
(tester) async {
|
||||
when(() => storageService.equipmentProfiles).thenReturn(List.from(_customProfiles));
|
||||
when(() => storageService.selectedEquipmentProfileId).thenReturn(_customProfiles[0].id);
|
||||
await pumpTestWidget(tester);
|
||||
|
||||
final updatedProfile1 = _customProfiles[0].copyWith(name: 'Test 1 updated');
|
||||
equipmentProfileProviderKey.currentState!.updateProfile(updatedProfile1);
|
||||
await tester.pump();
|
||||
verify(() => onDidChangeDependencies.onChanged(updatedProfile1)).called(1);
|
||||
|
||||
/// Verify that updating the not selected profile doesn't trigger the callback
|
||||
final updatedProfile2 = _customProfiles[1].copyWith(name: 'Test 2 updated');
|
||||
equipmentProfileProviderKey.currentState!.updateProfile(updatedProfile2);
|
||||
await tester.pump();
|
||||
verifyNever(() => onDidChangeDependencies.onChanged(updatedProfile2));
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
"Don't trigger `onDidChangeDependencies` by updating the unselected profile",
|
||||
(tester) async {
|
||||
when(() => storageService.equipmentProfiles).thenReturn(List.from(_customProfiles));
|
||||
when(() => storageService.selectedEquipmentProfileId).thenReturn(_customProfiles[0].id);
|
||||
await pumpTestWidget(tester);
|
||||
|
||||
final updatedProfile2 = _customProfiles[1].copyWith(name: 'Test 2 updated');
|
||||
equipmentProfileProviderKey.currentState!.updateProfile(updatedProfile2);
|
||||
await tester.pump();
|
||||
verifyNever(() => onDidChangeDependencies.onChanged(updatedProfile2));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
final List<EquipmentProfile> _customProfiles = [
|
||||
const EquipmentProfile(
|
||||
id: '1',
|
||||
name: 'Test 1',
|
||||
apertureValues: [
|
||||
ApertureValue(4.0, StopType.full),
|
||||
ApertureValue(4.5, StopType.third),
|
||||
ApertureValue(4.8, StopType.half),
|
||||
ApertureValue(5.0, StopType.third),
|
||||
ApertureValue(5.6, StopType.full),
|
||||
ApertureValue(6.3, StopType.third),
|
||||
ApertureValue(6.7, StopType.half),
|
||||
ApertureValue(7.1, StopType.third),
|
||||
ApertureValue(8, StopType.full),
|
||||
],
|
||||
ndValues: [
|
||||
NdValue(0),
|
||||
NdValue(2),
|
||||
NdValue(4),
|
||||
NdValue(8),
|
||||
NdValue(16),
|
||||
NdValue(32),
|
||||
NdValue(64),
|
||||
],
|
||||
shutterSpeedValues: ShutterSpeedValue.values,
|
||||
isoValues: [
|
||||
IsoValue(100, StopType.full),
|
||||
IsoValue(125, StopType.third),
|
||||
IsoValue(160, StopType.third),
|
||||
IsoValue(200, StopType.full),
|
||||
IsoValue(250, StopType.third),
|
||||
IsoValue(320, StopType.third),
|
||||
IsoValue(400, StopType.full),
|
||||
],
|
||||
),
|
||||
const EquipmentProfile(
|
||||
id: '2',
|
||||
name: 'Test 2',
|
||||
apertureValues: ApertureValue.values,
|
||||
ndValues: NdValue.values,
|
||||
shutterSpeedValues: ShutterSpeedValue.values,
|
||||
isoValues: IsoValue.values,
|
||||
),
|
||||
];
|
46
test/screens/metering/utils/notifier_volume_keys_test.dart
Normal file
46
test/screens/metering/utils/notifier_volume_keys_test.dart
Normal file
|
@ -0,0 +1,46 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:lightmeter/data/models/volume_action.dart';
|
||||
import 'package:lightmeter/data/volume_events_service.dart';
|
||||
import 'package:lightmeter/screens/metering/utils/notifier_volume_keys.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../function_mock.dart';
|
||||
|
||||
class _MockVolumeEventsService extends Mock implements VolumeEventsService {}
|
||||
|
||||
void main() {
|
||||
late _MockVolumeEventsService mockVolumeEventsService;
|
||||
|
||||
setUp(() {
|
||||
mockVolumeEventsService = _MockVolumeEventsService();
|
||||
});
|
||||
|
||||
test(
|
||||
'Listen to `volumeButtonsEventStream()`',
|
||||
() async {
|
||||
final StreamController<int> volumeButtonsEvents = StreamController<int>();
|
||||
when(() => mockVolumeEventsService.volumeButtonsEventStream()).thenAnswer((_) => volumeButtonsEvents.stream);
|
||||
|
||||
final volumeKeysNotifier = VolumeKeysNotifier(mockVolumeEventsService);
|
||||
final functions = MockValueChanged<VolumeKey>();
|
||||
volumeKeysNotifier.addListener(() => functions.onChanged(volumeKeysNotifier.value));
|
||||
expect(volumeKeysNotifier.value, VolumeKey.up);
|
||||
|
||||
volumeButtonsEvents.add(25);
|
||||
volumeButtonsEvents.add(25);
|
||||
volumeButtonsEvents.add(25);
|
||||
volumeButtonsEvents.add(24);
|
||||
volumeButtonsEvents.add(24);
|
||||
volumeButtonsEvents.add(25);
|
||||
await Future.delayed(Duration.zero);
|
||||
verify(() => functions.onChanged(VolumeKey.up)).called(2);
|
||||
verify(() => functions.onChanged(VolumeKey.down)).called(4);
|
||||
|
||||
volumeKeysNotifier.removeListener(() => functions.onChanged(volumeKeysNotifier.value));
|
||||
await volumeKeysNotifier.dispose();
|
||||
await volumeButtonsEvents.close();
|
||||
},
|
||||
);
|
||||
}
|
61
test/screens/settings/utils/show_buy_pro_dialog_test.dart
Normal file
61
test/screens/settings/utils/show_buy_pro_dialog_test.dart
Normal file
|
@ -0,0 +1,61 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lightmeter/data/models/feature.dart';
|
||||
import 'package:lightmeter/generated/l10n.dart';
|
||||
import 'package:lightmeter/providers/remote_config_provider.dart';
|
||||
import 'package:lightmeter/screens/settings/utils/show_buy_pro_dialog.dart';
|
||||
|
||||
import '../../../application_mock.dart';
|
||||
|
||||
void main() {
|
||||
Future<void> pumpApplication(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
RemoteConfig(
|
||||
config: const {Feature.unlockProFeaturesText: false},
|
||||
child: WidgetTestApplicationMock(
|
||||
child: Builder(
|
||||
builder: (context) => ElevatedButton(
|
||||
onPressed: () => showBuyProDialog(context),
|
||||
child: const SizedBox(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'`showBuyProDialog` and buy',
|
||||
(tester) async {
|
||||
await pumpApplication(tester);
|
||||
await tester.tap(find.byType(ElevatedButton));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
expect(find.text(S.current.lightmeterPro), findsOneWidget);
|
||||
expect(find.text(S.current.cancel), findsOneWidget);
|
||||
expect(find.text(S.current.buy), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text(S.current.buy));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'`showBuyProDialog` and cancel',
|
||||
(tester) async {
|
||||
await pumpApplication(tester);
|
||||
await tester.tap(find.byType(ElevatedButton));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
expect(find.text(S.current.lightmeterPro), findsOneWidget);
|
||||
expect(find.text(S.current.cancel), findsOneWidget);
|
||||
expect(find.text(S.current.buy), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text(S.current.cancel));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
},
|
||||
);
|
||||
}
|
76
test/utils/selectable_provider_test.dart
Normal file
76
test/utils/selectable_provider_test.dart
Normal file
|
@ -0,0 +1,76 @@
|
|||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lightmeter/utils/selectable_provider.dart';
|
||||
|
||||
void main() {
|
||||
group('SelectableInheritedModel.updateShouldNotifyDependent', () {
|
||||
final model = SelectableInheritedModel<int>(
|
||||
values: List.generate(25, (index) => index),
|
||||
selected: 1,
|
||||
child: const SizedBox(),
|
||||
);
|
||||
|
||||
test(
|
||||
'`{}`',
|
||||
() {
|
||||
expect(
|
||||
model.updateShouldNotifyDependent(
|
||||
SelectableInheritedModel<int>(
|
||||
values: List.generate(25, (index) => index),
|
||||
selected: 1,
|
||||
child: const SizedBox(),
|
||||
),
|
||||
{},
|
||||
),
|
||||
false,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'`{SelectableAspect.list}`',
|
||||
() {
|
||||
expect(
|
||||
model.updateShouldNotifyDependent(
|
||||
SelectableInheritedModel<int>(
|
||||
values: List.generate(25, (index) => index),
|
||||
selected: 1,
|
||||
child: const SizedBox(),
|
||||
),
|
||||
{SelectableAspect.list},
|
||||
),
|
||||
true,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'`{SelectableAspect.selected}`',
|
||||
() {
|
||||
expect(
|
||||
model.updateShouldNotifyDependent(
|
||||
SelectableInheritedModel<int>(
|
||||
values: List.generate(25, (index) => index),
|
||||
selected: 1,
|
||||
child: const SizedBox(),
|
||||
),
|
||||
{SelectableAspect.selected},
|
||||
),
|
||||
false,
|
||||
);
|
||||
expect(
|
||||
model.updateShouldNotifyDependent(
|
||||
SelectableInheritedModel<int>(
|
||||
values: List.generate(25, (index) => index),
|
||||
selected: 2,
|
||||
child: const SizedBox(),
|
||||
),
|
||||
{SelectableAspect.selected},
|
||||
),
|
||||
true,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
16
test/utils/to_string_signed_test.dart
Normal file
16
test/utils/to_string_signed_test.dart
Normal file
|
@ -0,0 +1,16 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lightmeter/utils/to_string_signed.dart';
|
||||
|
||||
void main() {
|
||||
test('toStringSignedAsFixed(0)', () {
|
||||
expect(1.5.toStringSignedAsFixed(0), '+2');
|
||||
expect((-1.5).toStringSignedAsFixed(0), '-2');
|
||||
expect(0.0.toStringSignedAsFixed(0), '0');
|
||||
});
|
||||
|
||||
test('toStringSignedAsFixed(1)', () {
|
||||
expect(1.5.toStringSignedAsFixed(1), '+1.5');
|
||||
expect((-1.5).toStringSignedAsFixed(1), '-1.5');
|
||||
expect(0.0.toStringSignedAsFixed(1), '0.0');
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue