From a3b03976e3884bc2346273cee9386ff4f43ddf50 Mon Sep 17 00:00:00 2001 From: RuiAlonso Date: Mon, 9 May 2022 09:08:57 +0200 Subject: [PATCH] test: coverage --- .../cubit/spaceship_ramp_cubit_test.dart | 46 +++++++++++++++++++ .../cubit/spaceship_ramp_state_test.dart | 30 +++++++++--- 2 files changed, 69 insertions(+), 7 deletions(-) diff --git a/packages/pinball_components/test/src/components/spaceship_ramp/cubit/spaceship_ramp_cubit_test.dart b/packages/pinball_components/test/src/components/spaceship_ramp/cubit/spaceship_ramp_cubit_test.dart index 89d03af0..c9af44cf 100644 --- a/packages/pinball_components/test/src/components/spaceship_ramp/cubit/spaceship_ramp_cubit_test.dart +++ b/packages/pinball_components/test/src/components/spaceship_ramp/cubit/spaceship_ramp_cubit_test.dart @@ -22,6 +22,52 @@ void main() { ); }); + group('onProgressed', () { + blocTest( + 'emits next arrow lightState', + build: SpaceshipRampCubit.new, + act: (bloc) => bloc + ..onProgressed() + ..onProgressed() + ..onProgressed() + ..onProgressed() + ..onProgressed() + ..onProgressed(), + expect: () => [ + isA().having( + (state) => state.lightState, + 'lightState', + ArrowLightState.active1, + ), + isA().having( + (state) => state.lightState, + 'lightState', + ArrowLightState.active2, + ), + isA().having( + (state) => state.lightState, + 'lightState', + ArrowLightState.active3, + ), + isA().having( + (state) => state.lightState, + 'lightState', + ArrowLightState.active4, + ), + isA().having( + (state) => state.lightState, + 'lightState', + ArrowLightState.active5, + ), + isA().having( + (state) => state.lightState, + 'lightState', + ArrowLightState.inactive, + ), + ], + ); + }); + group('onReset', () { blocTest( 'emits state reset to initial values', diff --git a/packages/pinball_components/test/src/components/spaceship_ramp/cubit/spaceship_ramp_state_test.dart b/packages/pinball_components/test/src/components/spaceship_ramp/cubit/spaceship_ramp_state_test.dart index 3cc982c3..77cf20c3 100644 --- a/packages/pinball_components/test/src/components/spaceship_ramp/cubit/spaceship_ramp_state_test.dart +++ b/packages/pinball_components/test/src/components/spaceship_ramp/cubit/spaceship_ramp_state_test.dart @@ -30,18 +30,34 @@ void main() { isNotNull, ); }); + + test( + 'throws AssertionError ' + 'when hits is negative', + () { + expect( + () => SpaceshipRampState( + hits: -1, + lightState: ArrowLightState.inactive, + ), + throwsAssertionError, + ); + }, + ); }); test( - 'throws AssertionError ' - 'when hits is negative', + 'fullArrowLit returns if lightState is last one', () { expect( - () => SpaceshipRampState( - hits: -1, - lightState: ArrowLightState.inactive, - ), - throwsAssertionError, + SpaceshipRampState.initial().fullArrowLit, + isFalse, + ); + expect( + SpaceshipRampState.initial() + .copyWith(lightState: ArrowLightState.active5) + .fullArrowLit, + isTrue, ); }, );