test: sparky mechanics

pull/155/head
Allison Ryan 4 years ago
parent 125e4e14e3
commit a3d0bf0152

@ -116,15 +116,18 @@ void main() {
}); });
}); });
flameTester.test('by applying velocity', (game) async { // TODO(allisonryan0002): delete or retest this if/when solution is added
final ball = Ball(baseColor: Colors.blue); // to prevent forces on a ball while stopped.
await game.ensureAdd(ball);
ball.stop(); // flameTester.test('by applying velocity', (game) async {
// final ball = Ball(baseColor: Colors.blue);
ball.body.linearVelocity.setValues(10, 10); // await game.ensureAdd(ball);
game.update(1); // ball.stop();
expect(ball.body.position, equals(ball.initialPosition));
}); // ball.body.linearVelocity.setValues(10, 10);
// game.update(1);
// expect(ball.body.position, equals(ball.initialPosition));
// });
}); });
group('resume', () { group('resume', () {

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

@ -0,0 +1,30 @@
// ignore_for_file: cascade_invocations
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball_components/pinball_components.dart';
import '../../helpers/helpers.dart';
void main() {
group('SparkyComputer', () {
final tester = FlameTester(TestGame.new);
tester.testGameWidget(
'renders correctly',
setUp: (game, tester) async {
await game.addFromBlueprint(SparkyComputer());
await game.ready();
game.camera.followVector2(Vector2(-15, -50));
},
// TODO(allisonryan0002): enable test when workflows are fixed.
// verify: (game, tester) async {
// await expectLater(
// find.byGame<Forge2DGame>(),
// matchesGoldenFile('golden/sparky-computer.png'),
// );
// },
);
});
}

@ -221,5 +221,22 @@ void main() {
], ],
); );
}); });
group('SparkyTurboChargeActivated', () {
blocTest<GameBloc, GameState>(
'adds game bonus',
build: GameBloc.new,
act: (bloc) => bloc..add(const SparkyTurboChargeActivated()),
expect: () => const [
GameState(
score: 0,
balls: 3,
activatedBonusLetters: [],
activatedDashNests: {},
bonusHistory: [GameBonus.sparkyTurboCharge],
),
],
);
});
}); });
} }

@ -84,5 +84,18 @@ void main() {
); );
}); });
}); });
group('SparkyTurboChargeActivated', () {
test('can be instantiated', () {
expect(const SparkyTurboChargeActivated(), isNotNull);
});
test('supports value equality', () {
expect(
SparkyTurboChargeActivated(),
equals(SparkyTurboChargeActivated()),
);
});
});
}); });
} }

@ -1,8 +1,8 @@
// ignore_for_file: cascade_invocations // ignore_for_file: cascade_invocations
import 'package:bloc_test/bloc_test.dart'; import 'package:bloc_test/bloc_test.dart';
import 'package:flame/extensions.dart';
import 'package:flame_test/flame_test.dart'; import 'package:flame_test/flame_test.dart';
import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart'; import 'package:mocktail/mocktail.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
@ -15,14 +15,6 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
group('BallController', () { group('BallController', () {
test('can be instantiated', () {
expect(
BallController(MockBall()),
isA<BallController>(),
);
});
group('description', () {
late Ball ball; late Ball ball;
late GameBloc gameBloc; late GameBloc gameBloc;
@ -41,6 +33,13 @@ void main() {
blocBuilder: () => gameBloc, blocBuilder: () => gameBloc,
); );
test('can be instantiated', () {
expect(
BallController(MockBall()),
isA<BallController>(),
);
});
flameBlocTester.testGameWidget( flameBlocTester.testGameWidget(
'lost adds BallLost to GameBloc', 'lost adds BallLost to GameBloc',
setUp: (game, tester) async { setUp: (game, tester) async {
@ -54,6 +53,67 @@ void main() {
verify(() => gameBloc.add(const BallLost())).called(1); verify(() => gameBloc.add(const BallLost())).called(1);
}, },
); );
group('turboCharge', () {
flameBlocTester.testGameWidget(
'adds TurboChargeActivated',
setUp: (game, tester) async {
final controller = BallController(ball);
await ball.add(controller);
await game.ensureAdd(ball);
await controller.turboCharge();
},
verify: (game, tester) async {
verify(() => gameBloc.add(const SparkyTurboChargeActivated()))
.called(1);
},
);
flameBlocTester.testGameWidget(
"initially stops the ball's motion",
setUp: (game, tester) async {
final controller = BallController(ball);
await ball.add(controller);
await game.ensureAdd(ball);
ball.body.linearVelocity = Vector2.all(10);
// ignore: unawaited_futures
controller.turboCharge();
expect(ball.body.gravityScale, equals(0));
expect(ball.body.linearVelocity, equals(Vector2.zero()));
expect(ball.body.angularVelocity, equals(0));
},
);
flameBlocTester.testGameWidget(
'resumes the ball',
setUp: (game, tester) async {
final controller = BallController(ball);
await ball.add(controller);
await game.ensureAdd(ball);
await controller.turboCharge();
expect(ball.body.gravityScale, equals(1));
expect(ball.body.linearVelocity, isNot(equals(Vector2.zero())));
},
);
flameBlocTester.testGameWidget(
'boosts the ball',
setUp: (game, tester) async {
final controller = BallController(ball);
await ball.add(controller);
await game.ensureAdd(ball);
await controller.turboCharge();
expect(ball.body.linearVelocity, equals(Vector2(200, -500)));
},
);
}); });
}); });
} }

@ -0,0 +1,21 @@
// ignore_for_file: cascade_invocations
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball/game/game.dart';
void main() {
group('SparkyComputerController', () {
late ControlledSparkyComputer controlledSparkyComputer;
setUp(() {
controlledSparkyComputer = ControlledSparkyComputer();
});
test('can be instantiated', () {
expect(
SparkyComputerController(controlledSparkyComputer),
isA<SparkyComputerController>(),
);
});
});
}
Loading…
Cancel
Save