mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 15:30:59 +00:00
added TimerBloc
test
This commit is contained in:
parent
9929d2a5b8
commit
90a4b9a056
1 changed files with 66 additions and 0 deletions
66
test/screens/timer/bloc_timer_test.dart
Normal file
66
test/screens/timer/bloc_timer_test.dart
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
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 meteringInteractor;
|
||||||
|
late TimerBloc bloc;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
meteringInteractor = _MockTimerInteractor();
|
||||||
|
when(meteringInteractor.quickVibration).thenAnswer((_) async {});
|
||||||
|
when(meteringInteractor.responseVibration).thenAnswer((_) async {});
|
||||||
|
|
||||||
|
bloc = TimerBloc(meteringInteractor, const Duration(seconds: 1));
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() {
|
||||||
|
bloc.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
blocTest<TimerBloc, TimerState>(
|
||||||
|
'Start -> wait till the end -> reset',
|
||||||
|
build: () => bloc,
|
||||||
|
act: (bloc) async {
|
||||||
|
bloc.add(const StartTimerEvent());
|
||||||
|
bloc.add(const TimerEndedEvent());
|
||||||
|
bloc.add(const ResetTimerEvent());
|
||||||
|
},
|
||||||
|
verify: (_) {
|
||||||
|
verify(() => meteringInteractor.quickVibration()).called(1);
|
||||||
|
verify(() => meteringInteractor.responseVibration()).called(1);
|
||||||
|
},
|
||||||
|
expect: () => [
|
||||||
|
isA<TimerResumedState>(),
|
||||||
|
isA<TimerStoppedState>(),
|
||||||
|
isA<TimerResetState>(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
blocTest<TimerBloc, TimerState>(
|
||||||
|
'Start -> stop -> start -> wait till the end',
|
||||||
|
build: () => bloc,
|
||||||
|
act: (bloc) async {
|
||||||
|
bloc.add(const StartTimerEvent());
|
||||||
|
bloc.add(const StopTimerEvent());
|
||||||
|
bloc.add(const StartTimerEvent());
|
||||||
|
bloc.add(const TimerEndedEvent());
|
||||||
|
},
|
||||||
|
verify: (_) {
|
||||||
|
verify(() => meteringInteractor.quickVibration()).called(3);
|
||||||
|
verify(() => meteringInteractor.responseVibration()).called(1);
|
||||||
|
},
|
||||||
|
expect: () => [
|
||||||
|
isA<TimerResumedState>(),
|
||||||
|
isA<TimerStoppedState>(),
|
||||||
|
isA<TimerResumedState>(),
|
||||||
|
isA<TimerStoppedState>(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in a new issue