refactor: switched method

pull/337/head
Allison Ryan 3 years ago
parent 7e9d7ee4ab
commit b9050d4c08

@ -33,11 +33,7 @@ class SkillShotBlinkingBehavior extends TimerComponent
void onTick() { void onTick() {
super.onTick(); super.onTick();
if (_blinks != _maxBlinks * 2) { if (_blinks != _maxBlinks * 2) {
if (parent.bloc.state.spriteState == SkillShotSpriteState.lit) { parent.bloc.switched();
parent.bloc.onBlinkedOn();
} else {
parent.bloc.onBlinkedOff();
}
_blinks++; _blinks++;
} else { } else {
_blinks = 0; _blinks = 0;

@ -17,12 +17,15 @@ class SkillShotCubit extends Cubit<SkillShotState> {
); );
} }
void onBlinkedOff() { void switched() {
switch (state.spriteState) {
case SkillShotSpriteState.lit:
emit(state.copyWith(spriteState: SkillShotSpriteState.dimmed));
break;
case SkillShotSpriteState.dimmed:
emit(state.copyWith(spriteState: SkillShotSpriteState.lit)); emit(state.copyWith(spriteState: SkillShotSpriteState.lit));
break;
} }
void onBlinkedOn() {
emit(state.copyWith(spriteState: SkillShotSpriteState.dimmed));
} }
void onBlinkingFinished() { void onBlinkingFinished() {

@ -21,7 +21,7 @@ void main() {
'SkillShotBlinkingBehavior', 'SkillShotBlinkingBehavior',
() { () {
flameTester.testGameWidget( flameTester.testGameWidget(
'calls onBlinkedOn after 0.15 seconds when isBlinking and lit', 'calls switched after 0.15 seconds when isBlinking and lit',
setUp: (game, tester) async { setUp: (game, tester) async {
final behavior = SkillShotBlinkingBehavior(); final behavior = SkillShotBlinkingBehavior();
final bloc = _MockSkillShotCubit(); final bloc = _MockSkillShotCubit();
@ -46,12 +46,12 @@ void main() {
game.update(0.15); game.update(0.15);
await streamController.close(); await streamController.close();
verify(bloc.onBlinkedOn).called(1); verify(bloc.switched).called(1);
}, },
); );
flameTester.testGameWidget( flameTester.testGameWidget(
'calls onBlinkedOff after 0.15 seconds when isBlinking and dimmed', 'calls switched after 0.15 seconds when isBlinking and dimmed',
setUp: (game, tester) async { setUp: (game, tester) async {
final behavior = SkillShotBlinkingBehavior(); final behavior = SkillShotBlinkingBehavior();
final bloc = _MockSkillShotCubit(); final bloc = _MockSkillShotCubit();
@ -76,7 +76,7 @@ void main() {
game.update(0.15); game.update(0.15);
await streamController.close(); await streamController.close();
verify(bloc.onBlinkedOff).called(1); verify(bloc.switched).called(1);
}, },
); );

@ -21,9 +21,9 @@ void main() {
); );
blocTest<SkillShotCubit, SkillShotState>( blocTest<SkillShotCubit, SkillShotState>(
'onBlinkedOff emits lit', 'switched emits lit when dimmed',
build: SkillShotCubit.new, build: SkillShotCubit.new,
act: (bloc) => bloc.onBlinkedOff(), act: (bloc) => bloc.switched(),
expect: () => [ expect: () => [
isA<SkillShotState>().having( isA<SkillShotState>().having(
(state) => state.spriteState, (state) => state.spriteState,
@ -34,9 +34,13 @@ void main() {
); );
blocTest<SkillShotCubit, SkillShotState>( blocTest<SkillShotCubit, SkillShotState>(
'onBlinkedOn emits dimmed', 'switched emits dimmed when lit',
build: SkillShotCubit.new, build: SkillShotCubit.new,
act: (bloc) => bloc.onBlinkedOn(), seed: () => SkillShotState(
spriteState: SkillShotSpriteState.lit,
isBlinking: false,
),
act: (bloc) => bloc.switched(),
expect: () => [ expect: () => [
isA<SkillShotState>().having( isA<SkillShotState>().having(
(state) => state.spriteState, (state) => state.spriteState,

Loading…
Cancel
Save