mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-12-25 15:40:40 +00:00
3bb3f12641
* 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
260 lines
11 KiB
Dart
260 lines
11 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:lightmeter/data/caffeine_service.dart';
|
|
import 'package:lightmeter/data/haptics_service.dart';
|
|
import 'package:lightmeter/data/light_sensor_service.dart';
|
|
import 'package:lightmeter/data/models/volume_action.dart';
|
|
import 'package:lightmeter/data/permissions_service.dart';
|
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
|
import 'package:lightmeter/data/volume_events_service.dart';
|
|
import 'package:lightmeter/interactors/metering_interactor.dart';
|
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
|
import 'package:mocktail/mocktail.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
class _MockUserPreferencesService extends Mock implements UserPreferencesService {}
|
|
|
|
class _MockCaffeineService extends Mock implements CaffeineService {}
|
|
|
|
class _MockHapticsService extends Mock implements HapticsService {}
|
|
|
|
class _MockPermissionsService extends Mock implements PermissionsService {}
|
|
|
|
class _MockLightSensorService extends Mock implements LightSensorService {}
|
|
|
|
class _MockVolumeEventsService extends Mock implements VolumeEventsService {}
|
|
|
|
void main() {
|
|
late _MockUserPreferencesService mockUserPreferencesService;
|
|
late _MockCaffeineService mockCaffeineService;
|
|
late _MockHapticsService mockHapticsService;
|
|
late _MockPermissionsService mockPermissionsService;
|
|
late _MockLightSensorService mockLightSensorService;
|
|
late _MockVolumeEventsService mockVolumeEventsService;
|
|
|
|
late MeteringInteractor interactor;
|
|
|
|
setUp(() {
|
|
mockUserPreferencesService = _MockUserPreferencesService();
|
|
mockCaffeineService = _MockCaffeineService();
|
|
mockHapticsService = _MockHapticsService();
|
|
mockPermissionsService = _MockPermissionsService();
|
|
mockLightSensorService = _MockLightSensorService();
|
|
mockVolumeEventsService = _MockVolumeEventsService();
|
|
|
|
interactor = MeteringInteractor(
|
|
mockUserPreferencesService,
|
|
mockCaffeineService,
|
|
mockHapticsService,
|
|
mockPermissionsService,
|
|
mockLightSensorService,
|
|
mockVolumeEventsService,
|
|
);
|
|
});
|
|
|
|
group(
|
|
'Initalization',
|
|
() {
|
|
test('caffeine - true', () async {
|
|
when(() => mockUserPreferencesService.caffeine).thenReturn(true);
|
|
when(() => mockCaffeineService.keepScreenOn(true)).thenAnswer((_) async => true);
|
|
when(() => mockUserPreferencesService.volumeAction).thenReturn(VolumeAction.shutter);
|
|
when(() => mockVolumeEventsService.setVolumeHandling(true)).thenAnswer((_) async => true);
|
|
interactor.initialize();
|
|
verify(() => mockUserPreferencesService.caffeine).called(1);
|
|
verify(() => mockCaffeineService.keepScreenOn(true)).called(1);
|
|
verify(() => mockVolumeEventsService.setVolumeHandling(true)).called(1);
|
|
});
|
|
|
|
test('caffeine - false', () async {
|
|
when(() => mockUserPreferencesService.caffeine).thenReturn(false);
|
|
when(() => mockCaffeineService.keepScreenOn(false)).thenAnswer((_) async => false);
|
|
when(() => mockUserPreferencesService.volumeAction).thenReturn(VolumeAction.shutter);
|
|
when(() => mockVolumeEventsService.setVolumeHandling(true)).thenAnswer((_) async => true);
|
|
interactor.initialize();
|
|
verify(() => mockUserPreferencesService.caffeine).called(1);
|
|
verifyNever(() => mockCaffeineService.keepScreenOn(false));
|
|
verify(() => mockVolumeEventsService.setVolumeHandling(true)).called(1);
|
|
});
|
|
},
|
|
);
|
|
|
|
group(
|
|
'Calibration',
|
|
() {
|
|
test('cameraEvCalibration', () async {
|
|
when(() => mockUserPreferencesService.cameraEvCalibration).thenReturn(0.0);
|
|
expect(interactor.cameraEvCalibration, 0.0);
|
|
verify(() => mockUserPreferencesService.cameraEvCalibration).called(1);
|
|
});
|
|
|
|
test('lightSensorEvCalibration', () async {
|
|
when(() => mockUserPreferencesService.lightSensorEvCalibration).thenReturn(0.0);
|
|
expect(interactor.lightSensorEvCalibration, 0.0);
|
|
verify(() => mockUserPreferencesService.lightSensorEvCalibration).called(1);
|
|
});
|
|
},
|
|
);
|
|
|
|
group(
|
|
'Equipment',
|
|
() {
|
|
test('iso - get', () async {
|
|
when(() => mockUserPreferencesService.iso).thenReturn(IsoValue.values.first);
|
|
expect(interactor.iso, IsoValue.values.first);
|
|
verify(() => mockUserPreferencesService.iso).called(1);
|
|
});
|
|
|
|
test('iso - set', () async {
|
|
when(() => mockUserPreferencesService.iso = IsoValue.values.first)
|
|
.thenReturn(IsoValue.values.first);
|
|
interactor.iso = IsoValue.values.first;
|
|
verify(() => mockUserPreferencesService.iso = IsoValue.values.first).called(1);
|
|
});
|
|
|
|
test('ndFilter - get', () async {
|
|
when(() => mockUserPreferencesService.ndFilter).thenReturn(NdValue.values.first);
|
|
expect(interactor.ndFilter, NdValue.values.first);
|
|
verify(() => mockUserPreferencesService.ndFilter).called(1);
|
|
});
|
|
|
|
test('ndFilter - set', () async {
|
|
when(() => mockUserPreferencesService.ndFilter = NdValue.values.first)
|
|
.thenReturn(NdValue.values.first);
|
|
interactor.ndFilter = NdValue.values.first;
|
|
verify(() => mockUserPreferencesService.ndFilter = NdValue.values.first).called(1);
|
|
});
|
|
},
|
|
);
|
|
|
|
group(
|
|
'Volume action',
|
|
() {
|
|
test('volumeAction - VolumeAction.shutter', () async {
|
|
when(() => mockUserPreferencesService.volumeAction).thenReturn(VolumeAction.shutter);
|
|
expect(interactor.volumeAction, VolumeAction.shutter);
|
|
verify(() => mockUserPreferencesService.volumeAction).called(1);
|
|
});
|
|
|
|
test('volumeAction - VolumeAction.none', () async {
|
|
when(() => mockUserPreferencesService.volumeAction).thenReturn(VolumeAction.none);
|
|
expect(interactor.volumeAction, VolumeAction.none);
|
|
verify(() => mockUserPreferencesService.volumeAction).called(1);
|
|
});
|
|
},
|
|
);
|
|
|
|
group(
|
|
'Haptics',
|
|
() {
|
|
test('isHapticsEnabled', () async {
|
|
when(() => mockUserPreferencesService.haptics).thenReturn(true);
|
|
expect(interactor.isHapticsEnabled, true);
|
|
verify(() => mockUserPreferencesService.haptics).called(1);
|
|
});
|
|
|
|
test('quickVibration() - true', () async {
|
|
when(() => mockUserPreferencesService.haptics).thenReturn(true);
|
|
when(() => mockHapticsService.quickVibration()).thenAnswer((_) async {});
|
|
interactor.quickVibration();
|
|
verify(() => mockUserPreferencesService.haptics).called(1);
|
|
verify(() => mockHapticsService.quickVibration()).called(1);
|
|
});
|
|
|
|
test('quickVibration() - false', () async {
|
|
when(() => mockUserPreferencesService.haptics).thenReturn(false);
|
|
when(() => mockHapticsService.quickVibration()).thenAnswer((_) async {});
|
|
interactor.quickVibration();
|
|
verify(() => mockUserPreferencesService.haptics).called(1);
|
|
verifyNever(() => mockHapticsService.quickVibration());
|
|
});
|
|
|
|
test('responseVibration() - true', () async {
|
|
when(() => mockUserPreferencesService.haptics).thenReturn(true);
|
|
when(() => mockHapticsService.responseVibration()).thenAnswer((_) async {});
|
|
interactor.responseVibration();
|
|
verify(() => mockUserPreferencesService.haptics).called(1);
|
|
verify(() => mockHapticsService.responseVibration()).called(1);
|
|
});
|
|
|
|
test('responseVibration() - false', () async {
|
|
when(() => mockUserPreferencesService.haptics).thenReturn(false);
|
|
when(() => mockHapticsService.responseVibration()).thenAnswer((_) async {});
|
|
interactor.responseVibration();
|
|
verify(() => mockUserPreferencesService.haptics).called(1);
|
|
verifyNever(() => mockHapticsService.responseVibration());
|
|
});
|
|
|
|
test('errorVibration() - true', () async {
|
|
when(() => mockUserPreferencesService.haptics).thenReturn(true);
|
|
when(() => mockHapticsService.errorVibration()).thenAnswer((_) async {});
|
|
interactor.errorVibration();
|
|
verify(() => mockUserPreferencesService.haptics).called(1);
|
|
verify(() => mockHapticsService.errorVibration()).called(1);
|
|
});
|
|
|
|
test('errorVibration() - false', () async {
|
|
when(() => mockUserPreferencesService.haptics).thenReturn(false);
|
|
when(() => mockHapticsService.errorVibration()).thenAnswer((_) async {});
|
|
interactor.errorVibration();
|
|
verify(() => mockUserPreferencesService.haptics).called(1);
|
|
verifyNever(() => mockHapticsService.errorVibration());
|
|
});
|
|
},
|
|
);
|
|
|
|
group(
|
|
'Permissions',
|
|
() {
|
|
test('checkCameraPermission() - granted', () async {
|
|
when(() => mockPermissionsService.checkCameraPermission())
|
|
.thenAnswer((_) async => PermissionStatus.granted);
|
|
expectLater(interactor.checkCameraPermission(), completion(true));
|
|
verify(() => mockPermissionsService.checkCameraPermission()).called(1);
|
|
});
|
|
|
|
test('checkCameraPermission() - denied', () async {
|
|
when(() => mockPermissionsService.checkCameraPermission())
|
|
.thenAnswer((_) async => PermissionStatus.denied);
|
|
expectLater(interactor.checkCameraPermission(), completion(false));
|
|
verify(() => mockPermissionsService.checkCameraPermission()).called(1);
|
|
});
|
|
|
|
test('requestCameraPermission() - granted', () async {
|
|
when(() => mockPermissionsService.requestCameraPermission())
|
|
.thenAnswer((_) async => PermissionStatus.granted);
|
|
expectLater(interactor.requestCameraPermission(), completion(true));
|
|
verify(() => mockPermissionsService.requestCameraPermission()).called(1);
|
|
});
|
|
|
|
test('requestCameraPermission() - denied', () async {
|
|
when(() => mockPermissionsService.requestCameraPermission())
|
|
.thenAnswer((_) async => PermissionStatus.denied);
|
|
expectLater(interactor.requestCameraPermission(), completion(false));
|
|
verify(() => mockPermissionsService.requestCameraPermission()).called(1);
|
|
});
|
|
},
|
|
);
|
|
|
|
group(
|
|
'Light sensor',
|
|
() {
|
|
test('hasAmbientLightSensor() - true', () async {
|
|
when(() => mockLightSensorService.hasSensor()).thenAnswer((_) async => true);
|
|
expectLater(interactor.hasAmbientLightSensor(), completion(true));
|
|
verify(() => mockLightSensorService.hasSensor()).called(1);
|
|
});
|
|
|
|
test('hasAmbientLightSensor() - false', () async {
|
|
when(() => mockLightSensorService.hasSensor()).thenAnswer((_) async => false);
|
|
expectLater(interactor.hasAmbientLightSensor(), completion(false));
|
|
verify(() => mockLightSensorService.hasSensor()).called(1);
|
|
});
|
|
|
|
test('luxStream()', () async {
|
|
when(() => mockLightSensorService.luxStream()).thenAnswer((_) => const Stream<int>.empty());
|
|
expect(interactor.luxStream(), const Stream<int>.empty());
|
|
verify(() => mockLightSensorService.luxStream()).called(1);
|
|
});
|
|
},
|
|
);
|
|
}
|