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() {
super.onTick();
if (_blinks != _maxBlinks * 2) {
if (parent.bloc.state.spriteState == SkillShotSpriteState.lit) {
parent.bloc.onBlinkedOn();
} else {
parent.bloc.onBlinkedOff();
}
parent.bloc.switched();
_blinks++;
} else {
_blinks = 0;

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

@ -21,7 +21,7 @@ void main() {
'SkillShotBlinkingBehavior',
() {
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 {
final behavior = SkillShotBlinkingBehavior();
final bloc = _MockSkillShotCubit();
@ -46,12 +46,12 @@ void main() {
game.update(0.15);
await streamController.close();
verify(bloc.onBlinkedOn).called(1);
verify(bloc.switched).called(1);
},
);
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 {
final behavior = SkillShotBlinkingBehavior();
final bloc = _MockSkillShotCubit();
@ -76,7 +76,7 @@ void main() {
game.update(0.15);
await streamController.close();
verify(bloc.onBlinkedOff).called(1);
verify(bloc.switched).called(1);
},
);

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

Loading…
Cancel
Save