fix: spitting test

pull/277/head
Allison Ryan 3 years ago
parent 3af0c51b05
commit a896da3d97

@ -30,7 +30,7 @@ class _BarrierBehindDino extends BodyComponent {
Body createBody() {
final shape = EdgeShape()
..set(
Vector2(27, -14.2),
Vector2(25, -14.2),
Vector2(25, -7.7),
);

@ -34,7 +34,7 @@ class ChromeDinoSpittingBehavior extends Component
void _spit() {
parent.bloc.state.ball!
..firstChild<SpriteComponent>()!.setOpacity(1)
..body.linearVelocity = Vector2(-50, 3);
..body.linearVelocity = Vector2(-50, 0);
parent.bloc.onSpit();
}

@ -28,31 +28,47 @@ void main() {
);
});
group('on the next time the mouth opens and status is chomping', () {
flameTester.test(
'creates a RevoluteJoint',
'sets ball sprite to visible and sets a linear velocity',
(game) async {
final ball = Ball(baseColor: Colors.red);
final behavior = ChromeDinoSpittingBehavior();
final bloc = MockChromeDinoCubit();
final streamController = StreamController<ChromeDinoState>();
final chompingState = ChromeDinoState(
status: ChromeDinoStatus.chomping,
isMouthOpen: true,
ball: ball,
);
whenListen(
bloc,
const Stream<ChromeDinoState>.empty(),
initialState: const ChromeDinoState.inital(),
streamController.stream,
initialState: chompingState,
);
final chromeDino = ChromeDino.test(bloc: bloc);
await chromeDino.add(behavior);
await game.ensureAdd(chromeDino);
await game.ensureAddAll([chromeDino, ball]);
expect(
game.world.joints.whereType<RevoluteJoint>().single,
isNotNull,
);
streamController.add(chompingState.copyWith(isMouthOpen: false));
streamController.add(chompingState.copyWith(isMouthOpen: true));
await game.ready();
game
.descendants()
.whereType<TimerComponent>()
.single
.timer
.onTick!();
expect(ball.firstChild<SpriteComponent>()!.getOpacity(), equals(1));
expect(ball.body.linearVelocity, equals(Vector2(-50, 0)));
},
);
group('calls', () {
flameTester.test(
'onSpit the next time the mouth opens and status is chomping',
'calls onSpit',
(game) async {
final ball = Ball(baseColor: Colors.red);
final behavior = ChromeDinoSpittingBehavior();

Loading…
Cancel
Save