m3_lightmeter/test/interactors/timer_interactor_test.dart

75 lines
2.7 KiB
Dart
Raw Permalink Normal View History

2024-05-03 10:43:45 +00:00
import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/interactors/timer_interactor.dart';
import 'package:mocktail/mocktail.dart';
class _MockUserPreferencesService extends Mock implements UserPreferencesService {}
class _MockHapticsService extends Mock implements HapticsService {}
void main() {
late _MockUserPreferencesService mockUserPreferencesService;
late _MockHapticsService mockHapticsService;
late TimerInteractor interactor;
setUp(() {
mockUserPreferencesService = _MockUserPreferencesService();
mockHapticsService = _MockHapticsService();
interactor = TimerInteractor(
mockUserPreferencesService,
mockHapticsService,
);
});
group(
'Haptics',
() {
2024-05-06 12:14:50 +00:00
test('startVibration() - true', () async {
2024-05-03 10:43:45 +00:00
when(() => mockUserPreferencesService.haptics).thenReturn(true);
when(() => mockHapticsService.quickVibration()).thenAnswer((_) async {});
2024-05-06 12:14:50 +00:00
interactor.startVibration();
2024-05-03 10:43:45 +00:00
verify(() => mockUserPreferencesService.haptics).called(1);
verify(() => mockHapticsService.quickVibration()).called(1);
});
2024-05-06 12:14:50 +00:00
test('startVibration() - false', () async {
2024-05-03 10:43:45 +00:00
when(() => mockUserPreferencesService.haptics).thenReturn(false);
when(() => mockHapticsService.quickVibration()).thenAnswer((_) async {});
2024-05-06 12:14:50 +00:00
interactor.startVibration();
2024-05-03 10:43:45 +00:00
verify(() => mockUserPreferencesService.haptics).called(1);
verifyNever(() => mockHapticsService.quickVibration());
});
2024-05-06 12:14:50 +00:00
test('endVibration() - true', () async {
2024-05-03 10:43:45 +00:00
when(() => mockUserPreferencesService.haptics).thenReturn(true);
2024-05-06 12:14:50 +00:00
when(() => mockHapticsService.errorVibration()).thenAnswer((_) async {});
interactor.endVibration();
2024-05-03 10:43:45 +00:00
verify(() => mockUserPreferencesService.haptics).called(1);
2024-05-06 12:14:50 +00:00
verify(() => mockHapticsService.errorVibration()).called(1);
2024-05-03 10:43:45 +00:00
});
2024-05-06 12:14:50 +00:00
test('endVibration() - false', () async {
2024-05-03 10:43:45 +00:00
when(() => mockUserPreferencesService.haptics).thenReturn(false);
2024-05-06 12:14:50 +00:00
when(() => mockHapticsService.errorVibration()).thenAnswer((_) async {});
interactor.endVibration();
2024-05-03 10:43:45 +00:00
verify(() => mockUserPreferencesService.haptics).called(1);
2024-05-06 12:14:50 +00:00
verifyNever(() => mockHapticsService.errorVibration());
2024-05-03 10:43:45 +00:00
});
},
);
2024-05-04 17:58:19 +00:00
group(
'AutostartTimer',
() {
test('isAutostartTimerEnabled', () {
when(() => mockUserPreferencesService.autostartTimer).thenReturn(true);
expect(interactor.isAutostartTimerEnabled, true);
verify(() => mockUserPreferencesService.autostartTimer).called(1);
});
},
);
2024-05-03 10:43:45 +00:00
}