m3_lightmeter/test/screens/timer/bloc_timer_test.dart
Vadim 5c27f726c5
ML-173 Add a timer for long exposures (#174)
* wip

* added start/stop button

* animated timeline

* fixed timer stop state

* added reset button (wip)

* added `onExposurePairTap` callback

* integrated `TimerScreen` to navigation

* separated `TimerTimeline`

* fixed timeline flickering

* added milliseconds to timer

* synchronized timeline with actual timer

* reused `BottomControlsBar`

* fixed default scaffold background color

* moved center button size to the bar itself

* display selected exposure pair on timer screen

* separated reusable `AnimatedCircluarButton`

* release camera when timer is opened

* added `TimerInteractor`

* added `TimerBloc` test

* fixed hours parsing

* added scenarios for timer golden test

* adjusted timer timeline colors

* show iso & nd values on timer screen

* automatically close timer screen after timeout

* added timer autostart

* reverted theme changes

* updated goldens

* typo

* removed timer screen auto-dismiss

* increased timer vibration duration

* replaced outlined locks

* increased 1/3 values font size
2024-05-07 19:24:51 +02:00

77 lines
2.4 KiB
Dart

import 'package:bloc_test/bloc_test.dart';
import 'package:lightmeter/interactors/timer_interactor.dart';
import 'package:lightmeter/screens/timer/bloc_timer.dart';
import 'package:lightmeter/screens/timer/event_timer.dart';
import 'package:lightmeter/screens/timer/state_timer.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
class _MockTimerInteractor extends Mock implements TimerInteractor {}
void main() {
late _MockTimerInteractor timerInteractor;
setUpAll(() {
timerInteractor = _MockTimerInteractor();
when(() => timerInteractor.isAutostartTimerEnabled).thenReturn(true);
when(timerInteractor.startVibration).thenAnswer((_) async {});
when(timerInteractor.endVibration).thenAnswer((_) async {});
});
blocTest<TimerBloc, TimerState>(
'Autostart',
build: () => TimerBloc(timerInteractor, const Duration(seconds: 1)),
verify: (_) {
verify(() => timerInteractor.startVibration()).called(1);
},
expect: () => [
isA<TimerResumedState>(),
],
);
blocTest<TimerBloc, TimerState>(
'Start -> wait till the end -> reset',
build: () => TimerBloc(timerInteractor, const Duration(seconds: 1)),
setUp: () {
when(() => timerInteractor.isAutostartTimerEnabled).thenReturn(false);
},
act: (bloc) {
bloc.add(const StartTimerEvent());
bloc.add(const TimerEndedEvent());
bloc.add(const ResetTimerEvent());
},
verify: (_) {
verify(() => timerInteractor.startVibration()).called(1);
verify(() => timerInteractor.endVibration()).called(1);
},
expect: () => [
isA<TimerResumedState>(),
isA<TimerStoppedState>(),
isA<TimerResetState>(),
],
);
blocTest<TimerBloc, TimerState>(
'Start -> stop -> start -> wait till the end',
build: () => TimerBloc(timerInteractor, const Duration(seconds: 1)),
setUp: () {
when(() => timerInteractor.isAutostartTimerEnabled).thenReturn(false);
},
act: (bloc) async {
bloc.add(const StartTimerEvent());
bloc.add(const StopTimerEvent());
bloc.add(const StartTimerEvent());
bloc.add(const TimerEndedEvent());
},
verify: (_) {
verify(() => timerInteractor.startVibration()).called(3);
verify(() => timerInteractor.endVibration()).called(1);
},
expect: () => [
isA<TimerResumedState>(),
isA<TimerStoppedState>(),
isA<TimerResumedState>(),
isA<TimerStoppedState>(),
],
);
}