mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-23 07:50:42 +00:00
ML-62 Interactors tests (#87)
* 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
This commit is contained in:
parent
47f7b61230
commit
b13acedebd
8 changed files with 492 additions and 12 deletions
|
@ -1,6 +1,5 @@
|
||||||
include: package:lint/strict.yaml
|
include: package:lint/strict.yaml
|
||||||
|
|
||||||
|
|
||||||
linter:
|
linter:
|
||||||
rules:
|
rules:
|
||||||
use_setters_to_change_properties: false
|
use_setters_to_change_properties: false
|
||||||
|
|
|
@ -25,7 +25,9 @@ class MeteringInteractor {
|
||||||
this._permissionsService,
|
this._permissionsService,
|
||||||
this._lightSensorService,
|
this._lightSensorService,
|
||||||
this._volumeEventsService,
|
this._volumeEventsService,
|
||||||
) {
|
);
|
||||||
|
|
||||||
|
void initialize() {
|
||||||
if (_userPreferencesService.caffeine) {
|
if (_userPreferencesService.caffeine) {
|
||||||
_caffeineService.keepScreenOn(true);
|
_caffeineService.keepScreenOn(true);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +71,7 @@ class MeteringInteractor {
|
||||||
.then((value) => value == PermissionStatus.granted);
|
.then((value) => value == PermissionStatus.granted);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> requestPermission() async {
|
Future<bool> requestCameraPermission() async {
|
||||||
return _permissionsService
|
return _permissionsService
|
||||||
.requestCameraPermission()
|
.requestCameraPermission()
|
||||||
.then((value) => value == PermissionStatus.granted);
|
.then((value) => value == PermissionStatus.granted);
|
||||||
|
|
|
@ -41,8 +41,8 @@ class SettingsInteractor {
|
||||||
|
|
||||||
VolumeAction get volumeAction => _userPreferencesService.volumeAction;
|
VolumeAction get volumeAction => _userPreferencesService.volumeAction;
|
||||||
Future<void> setVolumeAction(VolumeAction value) async {
|
Future<void> setVolumeAction(VolumeAction value) async {
|
||||||
await _volumeEventsService.setVolumeHandling(value != VolumeAction.none);
|
|
||||||
_userPreferencesService.volumeAction = value;
|
_userPreferencesService.volumeAction = value;
|
||||||
|
await _volumeEventsService.setVolumeHandling(value != VolumeAction.none);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get isHapticsEnabled => _userPreferencesService.haptics;
|
bool get isHapticsEnabled => _userPreferencesService.haptics;
|
||||||
|
|
|
@ -92,7 +92,7 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onRequestPermission(_, Emitter emit) async {
|
Future<void> _onRequestPermission(_, Emitter emit) async {
|
||||||
final hasPermission = await _meteringInteractor.requestPermission();
|
final hasPermission = await _meteringInteractor.requestCameraPermission();
|
||||||
if (!hasPermission) {
|
if (!hasPermission) {
|
||||||
emit(const CameraErrorState(CameraErrorType.permissionNotGranted));
|
emit(const CameraErrorState(CameraErrorType.permissionNotGranted));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -31,7 +31,7 @@ class _MeteringFlowState extends State<MeteringFlow> {
|
||||||
context.get<PermissionsService>(),
|
context.get<PermissionsService>(),
|
||||||
context.get<LightSensorService>(),
|
context.get<LightSensorService>(),
|
||||||
context.get<VolumeEventsService>(),
|
context.get<VolumeEventsService>(),
|
||||||
),
|
)..initialize(),
|
||||||
child: InheritedWidgetBase<VolumeKeysNotifier>(
|
child: InheritedWidgetBase<VolumeKeysNotifier>(
|
||||||
data: VolumeKeysNotifier(context.get<VolumeEventsService>()),
|
data: VolumeKeysNotifier(context.get<VolumeEventsService>()),
|
||||||
child: MultiBlocProvider(
|
child: MultiBlocProvider(
|
||||||
|
|
274
test/interactors/metering_interactor_test.dart
Normal file
274
test/interactors/metering_interactor_test.dart
Normal file
|
@ -0,0 +1,274 @@
|
||||||
|
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/film.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);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('film - get', () async {
|
||||||
|
when(() => mockUserPreferencesService.film).thenReturn(Film.values.first);
|
||||||
|
expect(interactor.film, Film.values.first);
|
||||||
|
verify(() => mockUserPreferencesService.film).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('film - set', () async {
|
||||||
|
when(() => mockUserPreferencesService.film = Film.values.first)
|
||||||
|
.thenReturn(Film.values.first);
|
||||||
|
interactor.film = Film.values.first;
|
||||||
|
verify(() => mockUserPreferencesService.film = Film.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(
|
||||||
|
'Haptics',
|
||||||
|
() {
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
205
test/interactors/settings_interactor_test.dart
Normal file
205
test/interactors/settings_interactor_test.dart
Normal file
|
@ -0,0 +1,205 @@
|
||||||
|
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/models/volume_action.dart';
|
||||||
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||||
|
import 'package:lightmeter/data/volume_events_service.dart';
|
||||||
|
import 'package:lightmeter/interactors/settings_interactor.dart';
|
||||||
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
|
||||||
|
class _MockUserPreferencesService extends Mock implements UserPreferencesService {}
|
||||||
|
|
||||||
|
class _MockCaffeineService extends Mock implements CaffeineService {}
|
||||||
|
|
||||||
|
class _MockHapticsService extends Mock implements HapticsService {}
|
||||||
|
|
||||||
|
class _MockVolumeEventsService extends Mock implements VolumeEventsService {}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
late _MockUserPreferencesService mockUserPreferencesService;
|
||||||
|
late _MockCaffeineService mockCaffeineService;
|
||||||
|
late _MockHapticsService mockHapticsService;
|
||||||
|
late _MockVolumeEventsService mockVolumeEventsService;
|
||||||
|
|
||||||
|
late SettingsInteractor interactor;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
mockUserPreferencesService = _MockUserPreferencesService();
|
||||||
|
mockCaffeineService = _MockCaffeineService();
|
||||||
|
mockHapticsService = _MockHapticsService();
|
||||||
|
mockVolumeEventsService = _MockVolumeEventsService();
|
||||||
|
|
||||||
|
interactor = SettingsInteractor(
|
||||||
|
mockUserPreferencesService,
|
||||||
|
mockCaffeineService,
|
||||||
|
mockHapticsService,
|
||||||
|
mockVolumeEventsService,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
group(
|
||||||
|
'Calibration',
|
||||||
|
() {
|
||||||
|
test('cameraEvCalibration - get', () async {
|
||||||
|
when(() => mockUserPreferencesService.cameraEvCalibration).thenReturn(0.0);
|
||||||
|
expect(interactor.cameraEvCalibration, 0.0);
|
||||||
|
verify(() => mockUserPreferencesService.cameraEvCalibration).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('cameraEvCalibration - set', () async {
|
||||||
|
when(() => mockUserPreferencesService.cameraEvCalibration = 0.0).thenReturn(0.0);
|
||||||
|
interactor.setCameraEvCalibration(0.0);
|
||||||
|
verify(() => mockUserPreferencesService.cameraEvCalibration = 0.0).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('lightSensorEvCalibration - get', () async {
|
||||||
|
when(() => mockUserPreferencesService.lightSensorEvCalibration).thenReturn(0.0);
|
||||||
|
expect(interactor.lightSensorEvCalibration, 0.0);
|
||||||
|
verify(() => mockUserPreferencesService.lightSensorEvCalibration).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('lightSensorEvCalibration - set', () async {
|
||||||
|
when(() => mockUserPreferencesService.lightSensorEvCalibration = 0.0).thenReturn(0.0);
|
||||||
|
interactor.setLightSensorEvCalibration(0.0);
|
||||||
|
verify(() => mockUserPreferencesService.lightSensorEvCalibration = 0.0).called(1);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
group(
|
||||||
|
'Caffeine',
|
||||||
|
() {
|
||||||
|
test('isCaffeineEnabled', () async {
|
||||||
|
when(() => mockUserPreferencesService.caffeine).thenReturn(true);
|
||||||
|
expect(interactor.isCaffeineEnabled, true);
|
||||||
|
verify(() => mockUserPreferencesService.caffeine).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('enableCaffeine(true)', () async {
|
||||||
|
when(() => mockCaffeineService.keepScreenOn(true)).thenAnswer((_) async => true);
|
||||||
|
when(() => mockUserPreferencesService.caffeine = true).thenReturn(true);
|
||||||
|
await interactor.enableCaffeine(true);
|
||||||
|
verify(() => mockCaffeineService.keepScreenOn(true)).called(1);
|
||||||
|
verify(() => mockUserPreferencesService.caffeine = true).called(1);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
group(
|
||||||
|
'Volume action',
|
||||||
|
() {
|
||||||
|
test('disableVolumeHandling()', () async {
|
||||||
|
when(() => mockVolumeEventsService.setVolumeHandling(false)).thenAnswer((_) async => false);
|
||||||
|
expectLater(interactor.disableVolumeHandling(), isA<Future<void>>());
|
||||||
|
verify(() => mockVolumeEventsService.setVolumeHandling(false)).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('restoreVolumeHandling() - VolumeAction.shutter', () async {
|
||||||
|
when(() => mockUserPreferencesService.volumeAction).thenReturn(VolumeAction.shutter);
|
||||||
|
when(() => mockVolumeEventsService.setVolumeHandling(true)).thenAnswer((_) async => true);
|
||||||
|
expectLater(interactor.restoreVolumeHandling(), isA<Future<void>>());
|
||||||
|
verify(() => mockUserPreferencesService.volumeAction).called(1);
|
||||||
|
verify(() => mockVolumeEventsService.setVolumeHandling(true)).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('restoreVolumeHandling() - VolumeAction.none', () async {
|
||||||
|
when(() => mockUserPreferencesService.volumeAction).thenReturn(VolumeAction.none);
|
||||||
|
when(() => mockVolumeEventsService.setVolumeHandling(false)).thenAnswer((_) async => false);
|
||||||
|
expectLater(interactor.restoreVolumeHandling(), isA<Future<void>>());
|
||||||
|
verify(() => mockUserPreferencesService.volumeAction).called(1);
|
||||||
|
verify(() => mockVolumeEventsService.setVolumeHandling(false)).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('setVolumeAction(VolumeAction.shutter)', () async {
|
||||||
|
when(() => mockUserPreferencesService.volumeAction = VolumeAction.shutter)
|
||||||
|
.thenReturn(VolumeAction.shutter);
|
||||||
|
when(() => mockVolumeEventsService.setVolumeHandling(true)).thenAnswer((_) async => true);
|
||||||
|
expectLater(interactor.setVolumeAction(VolumeAction.shutter), isA<Future<void>>());
|
||||||
|
verify(() => mockVolumeEventsService.setVolumeHandling(true)).called(1);
|
||||||
|
verify(() => mockUserPreferencesService.volumeAction = VolumeAction.shutter).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('setVolumeAction(VolumeAction.none)', () async {
|
||||||
|
when(() => mockUserPreferencesService.volumeAction = VolumeAction.none)
|
||||||
|
.thenReturn(VolumeAction.none);
|
||||||
|
when(() => mockVolumeEventsService.setVolumeHandling(false)).thenAnswer((_) async => false);
|
||||||
|
expectLater(interactor.setVolumeAction(VolumeAction.none), isA<Future<void>>());
|
||||||
|
verify(() => mockVolumeEventsService.setVolumeHandling(false)).called(1);
|
||||||
|
verify(() => mockUserPreferencesService.volumeAction = VolumeAction.none).called(1);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
group(
|
||||||
|
'Haptics',
|
||||||
|
() {
|
||||||
|
test('isHapticsEnabled', () async {
|
||||||
|
when(() => mockUserPreferencesService.haptics).thenReturn(true);
|
||||||
|
expect(interactor.isHapticsEnabled, true);
|
||||||
|
verify(() => mockUserPreferencesService.haptics).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('enableHaptics() - true', () async {
|
||||||
|
when(() => mockUserPreferencesService.haptics = true).thenReturn(true);
|
||||||
|
when(() => mockUserPreferencesService.haptics).thenReturn(true);
|
||||||
|
when(() => mockHapticsService.quickVibration()).thenAnswer((_) async {});
|
||||||
|
interactor.enableHaptics(true);
|
||||||
|
verify(() => mockUserPreferencesService.haptics).called(1);
|
||||||
|
verify(() => mockHapticsService.quickVibration()).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('enableHaptics() - false', () async {
|
||||||
|
when(() => mockUserPreferencesService.haptics = false).thenReturn(false);
|
||||||
|
when(() => mockUserPreferencesService.haptics).thenReturn(false);
|
||||||
|
when(() => mockHapticsService.quickVibration()).thenAnswer((_) async {});
|
||||||
|
interactor.enableHaptics(false);
|
||||||
|
verify(() => mockUserPreferencesService.haptics).called(1);
|
||||||
|
verifyNever(() => mockHapticsService.quickVibration());
|
||||||
|
});
|
||||||
|
|
||||||
|
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());
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
|
@ -140,11 +140,11 @@ void main() {
|
||||||
'Request denied',
|
'Request denied',
|
||||||
build: () => bloc,
|
build: () => bloc,
|
||||||
setUp: () {
|
setUp: () {
|
||||||
when(() => meteringInteractor.requestPermission()).thenAnswer((_) async => false);
|
when(() => meteringInteractor.requestCameraPermission()).thenAnswer((_) async => false);
|
||||||
},
|
},
|
||||||
act: (bloc) => bloc.add(const RequestPermissionEvent()),
|
act: (bloc) => bloc.add(const RequestPermissionEvent()),
|
||||||
verify: (_) {
|
verify: (_) {
|
||||||
verify(() => meteringInteractor.requestPermission()).called(1);
|
verify(() => meteringInteractor.requestCameraPermission()).called(1);
|
||||||
},
|
},
|
||||||
expect: () => [
|
expect: () => [
|
||||||
isA<CameraErrorState>()
|
isA<CameraErrorState>()
|
||||||
|
@ -156,12 +156,12 @@ void main() {
|
||||||
'Request granted -> check denied',
|
'Request granted -> check denied',
|
||||||
build: () => bloc,
|
build: () => bloc,
|
||||||
setUp: () {
|
setUp: () {
|
||||||
when(() => meteringInteractor.requestPermission()).thenAnswer((_) async => true);
|
when(() => meteringInteractor.requestCameraPermission()).thenAnswer((_) async => true);
|
||||||
when(() => meteringInteractor.checkCameraPermission()).thenAnswer((_) async => false);
|
when(() => meteringInteractor.checkCameraPermission()).thenAnswer((_) async => false);
|
||||||
},
|
},
|
||||||
act: (bloc) => bloc.add(const RequestPermissionEvent()),
|
act: (bloc) => bloc.add(const RequestPermissionEvent()),
|
||||||
verify: (_) {
|
verify: (_) {
|
||||||
verify(() => meteringInteractor.requestPermission()).called(1);
|
verify(() => meteringInteractor.requestCameraPermission()).called(1);
|
||||||
verify(() => meteringInteractor.checkCameraPermission()).called(1);
|
verify(() => meteringInteractor.checkCameraPermission()).called(1);
|
||||||
},
|
},
|
||||||
expect: () => [
|
expect: () => [
|
||||||
|
@ -175,12 +175,12 @@ void main() {
|
||||||
'Request granted -> check granted',
|
'Request granted -> check granted',
|
||||||
build: () => bloc,
|
build: () => bloc,
|
||||||
setUp: () {
|
setUp: () {
|
||||||
when(() => meteringInteractor.requestPermission()).thenAnswer((_) async => true);
|
when(() => meteringInteractor.requestCameraPermission()).thenAnswer((_) async => true);
|
||||||
when(() => meteringInteractor.checkCameraPermission()).thenAnswer((_) async => true);
|
when(() => meteringInteractor.checkCameraPermission()).thenAnswer((_) async => true);
|
||||||
},
|
},
|
||||||
act: (bloc) => bloc.add(const RequestPermissionEvent()),
|
act: (bloc) => bloc.add(const RequestPermissionEvent()),
|
||||||
verify: (_) {
|
verify: (_) {
|
||||||
verify(() => meteringInteractor.requestPermission()).called(1);
|
verify(() => meteringInteractor.requestCameraPermission()).called(1);
|
||||||
verify(() => meteringInteractor.checkCameraPermission()).called(1);
|
verify(() => meteringInteractor.checkCameraPermission()).called(1);
|
||||||
},
|
},
|
||||||
expect: () => initializedStateSequence,
|
expect: () => initializedStateSequence,
|
||||||
|
|
Loading…
Reference in a new issue