Wrote Widget test
parent
f0e08bba26
commit
ddb7b0002a
|
@ -39,17 +39,19 @@ class Game {
|
|||
}
|
||||
}
|
||||
|
||||
void endGame() {
|
||||
void endGame(bool gameIsCanceled) {
|
||||
running = false;
|
||||
counterTimer.cancel();
|
||||
if (!gameIsCanceled) {
|
||||
gameConsumer.gameStopped();
|
||||
}
|
||||
}
|
||||
|
||||
void countDown() {
|
||||
timeInSeconds--;
|
||||
gameConsumer.updateTime();
|
||||
if (timeInSeconds == 0 && running) {
|
||||
endGame();
|
||||
endGame(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +69,8 @@ class Game {
|
|||
points = 0;
|
||||
board = Board(this);
|
||||
gameConsumer.updateStones();
|
||||
counterTimer = Timer.periodic(const Duration(seconds: 1), (_) => countDown());
|
||||
counterTimer =
|
||||
Timer.periodic(const Duration(seconds: 1), (_) => countDown());
|
||||
gameConsumer.updatePoints();
|
||||
running = true;
|
||||
}
|
||||
|
|
|
@ -72,6 +72,14 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
|||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (game.isRunning()) {
|
||||
game.endGame(true);
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _saveScore(String name, int score) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_scoreboard.add({'name': name, 'score': score});
|
||||
|
|
|
@ -1,30 +1,24 @@
|
|||
// This is a basic Flutter widget test.
|
||||
//
|
||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
||||
// utility in the flutter_test package. For example, you can send tap and scroll
|
||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||
// tree, read text, and verify that the values of widget properties are correct.
|
||||
|
||||
// In the my_app_test.dart file
|
||||
import 'package:bubbletwist/main.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:bubbletwist/main.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
group('Bubble-Twist Widget Tests', () {
|
||||
testWidgets('Initial startup shows start button',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MyApp());
|
||||
expect(find.text('Start'), findsOneWidget);
|
||||
});
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
expect(find.text('1'), findsNothing);
|
||||
|
||||
// Tap the '+' icon and trigger a frame.
|
||||
await tester.tap(find.byIcon(Icons.add));
|
||||
testWidgets('Game starts and displays grid on start button tap',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MyApp());
|
||||
await tester.tap(find.text('Start'));
|
||||
await tester.pump();
|
||||
|
||||
// Verify that our counter has incremented.
|
||||
expect(find.text('0'), findsNothing);
|
||||
expect(find.text('1'), findsOneWidget);
|
||||
// Ensure the GridView is now visible
|
||||
expect(find.byType(GridView), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue