From cbb4c66d04bd04bf2a05f111b624b19fcbffd67e Mon Sep 17 00:00:00 2001 From: alestiago Date: Fri, 18 Mar 2022 10:41:06 +0000 Subject: [PATCH] feat: included tests --- test/game/components/ball_test.dart | 57 ++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/test/game/components/ball_test.dart b/test/game/components/ball_test.dart index 64d41908..b9e3d4a2 100644 --- a/test/game/components/ball_test.dart +++ b/test/game/components/ball_test.dart @@ -72,7 +72,7 @@ void main() { ); }); - group('resetting a ball', () { + group('lost', () { late GameBloc gameBloc; setUp(() { @@ -128,7 +128,7 @@ void main() { ); await game.ready(); - game.children.whereType().first.removeFromParent(); + game.children.whereType().first.lost(); await tester.pump(); expect( @@ -138,5 +138,58 @@ void main() { }, ); }); + + group('stop', () { + Future newFrame() async { + // TODO(alestiago): Remove to wait for new frame. + await Future.delayed(const Duration(milliseconds: 100)); + } + + flameTester.test('can be moved', (game) async { + final ball = Ball(); + await game.ensureAdd(ball); + + await newFrame(); + expect(ball.body.position, isNot(equals(ball.initialPosition))); + + ball.body.linearVelocity.setValues(10, 10); + await newFrame(); + expect(ball.body.position, isNot(equals(ball.initialPosition))); + }); + + flameTester.test("can't be moved", (game) async { + final ball = Ball(); + await game.ensureAdd(ball); + ball.stop(); + + await newFrame(); + expect(ball.body.position, equals(ball.initialPosition)); + + ball.body.linearVelocity.setValues(10, 10); + await newFrame(); + expect(ball.body.position, equals(ball.initialPosition)); + }); + }); + + group('resume', () { + Future newFrame() async { + // TODO(alestiago): Remove to wait for new frame. + await Future.delayed(const Duration(milliseconds: 100)); + } + + flameTester.test('can move when previosusly stopped', (game) async { + final ball = Ball(); + await game.ensureAdd(ball); + ball.stop(); + ball.resume(); + + await newFrame(); + expect(ball.body.position, isNot(equals(ball.initialPosition))); + + ball.body.linearVelocity.setValues(10, 10); + await newFrame(); + expect(ball.body.position, isNot(equals(ball.initialPosition))); + }); + }); }); }