cpd_David_und_Yusuf/test/gameboard_test.dart

43 lines
1.5 KiB
Dart
Raw Normal View History

2024-06-13 01:30:02 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:werwolf/models/player.dart';
import 'package:werwolf/models/role.dart';
import 'package:werwolf/screens/gameboard.dart';
void main() {
group('PlayerGridView Tests', () {
List<Player> players = [
Player(name: 'Alice', role: Role.dorfbewohner, isDead: false),
Player(name: 'Bob', role: Role.werwolf, isDead: false),
Player(name: 'Charlie', role: Role.dorfbewohner, isDead: false),
];
testWidgets('Displays player names in grid', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: PlayerGridView(players: players)));
expect(find.text('Alice'), findsOneWidget);
expect(find.text('Bob'), findsOneWidget);
expect(find.text('Charlie'), findsOneWidget);
});
testWidgets('Kills a player on tap', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: PlayerGridView(players: players)));
await tester.tap(find.text('Alice'));
await tester.pumpAndSettle();
expect(players[0].isDead, true);
expect(find.byIcon(Icons.close), findsOneWidget); // Check if dead icon is shown
});
testWidgets('Changes phase on button press', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: PlayerGridView(players: players)));
await tester.tap(find.text('Tag skippen'));
await tester.pumpAndSettle();
expect(find.text('Nacht skippen'), findsOneWidget);
});
});
}