Wrote Widget test
parent
f0e08bba26
commit
ddb7b0002a
|
@ -39,17 +39,19 @@ class Game {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void endGame() {
|
void endGame(bool gameIsCanceled) {
|
||||||
running = false;
|
running = false;
|
||||||
counterTimer.cancel();
|
counterTimer.cancel();
|
||||||
gameConsumer.gameStopped();
|
if (!gameIsCanceled) {
|
||||||
|
gameConsumer.gameStopped();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void countDown() {
|
void countDown() {
|
||||||
timeInSeconds--;
|
timeInSeconds--;
|
||||||
gameConsumer.updateTime();
|
gameConsumer.updateTime();
|
||||||
if (timeInSeconds == 0 && running) {
|
if (timeInSeconds == 0 && running) {
|
||||||
endGame();
|
endGame(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +69,8 @@ class Game {
|
||||||
points = 0;
|
points = 0;
|
||||||
board = Board(this);
|
board = Board(this);
|
||||||
gameConsumer.updateStones();
|
gameConsumer.updateStones();
|
||||||
counterTimer = Timer.periodic(const Duration(seconds: 1), (_) => countDown());
|
counterTimer =
|
||||||
|
Timer.periodic(const Duration(seconds: 1), (_) => countDown());
|
||||||
gameConsumer.updatePoints();
|
gameConsumer.updatePoints();
|
||||||
running = true;
|
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 {
|
void _saveScore(String name, int score) async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
_scoreboard.add({'name': name, 'score': score});
|
_scoreboard.add({'name': name, 'score': score});
|
||||||
|
|
|
@ -1,30 +1,24 @@
|
||||||
// This is a basic Flutter widget test.
|
// In the my_app_test.dart file
|
||||||
//
|
import 'package:bubbletwist/main.dart';
|
||||||
// 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.
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
import 'package:bubbletwist/main.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
group('Bubble-Twist Widget Tests', () {
|
||||||
// Build our app and trigger a frame.
|
testWidgets('Initial startup shows start button',
|
||||||
await tester.pumpWidget(const MyApp());
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(const MyApp());
|
||||||
|
expect(find.text('Start'), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
// Verify that our counter starts at 0.
|
testWidgets('Game starts and displays grid on start button tap',
|
||||||
expect(find.text('0'), findsOneWidget);
|
(WidgetTester tester) async {
|
||||||
expect(find.text('1'), findsNothing);
|
await tester.pumpWidget(const MyApp());
|
||||||
|
await tester.tap(find.text('Start'));
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
// Tap the '+' icon and trigger a frame.
|
// Ensure the GridView is now visible
|
||||||
await tester.tap(find.byIcon(Icons.add));
|
expect(find.byType(GridView), findsOneWidget);
|
||||||
await tester.pump();
|
});
|
||||||
|
|
||||||
// Verify that our counter has incremented.
|
|
||||||
expect(find.text('0'), findsNothing);
|
|
||||||
expect(find.text('1'), findsOneWidget);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue