new tests
parent
419ae9ea58
commit
298390170c
|
@ -20,3 +20,5 @@ dev_dependencies:
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
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/flippingcards.dart';
|
||||||
|
import 'package:werwolf/screens/gameboard.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('FlippingCard Screen Tests', () {
|
||||||
|
List<Player> players = [
|
||||||
|
Player(name: 'Alice', role: Role.dorfbewohner, isDead: false),
|
||||||
|
Player(name: 'Bob', role: Role.werwolf, isDead: false),
|
||||||
|
// Add more players as needed
|
||||||
|
];
|
||||||
|
|
||||||
|
testWidgets('Displays player name on front of card', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(MaterialApp(home: FlipingCard(players: players)));
|
||||||
|
|
||||||
|
expect(find.text('Alice'), findsOneWidget);
|
||||||
|
expect(find.text('Klick um deine Rolle zu sehen!'), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Flips card to show role', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(MaterialApp(home: FlipingCard(players: players)));
|
||||||
|
|
||||||
|
await tester.tap(find.text('Klick um deine Rolle zu sehen!'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text('Dorfbewohner'), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Navigates to PlayerGridView on last player', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(MaterialApp(home: FlipingCard(players: players)));
|
||||||
|
|
||||||
|
await tester.tap(find.text('Nächster Spieler'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await tester.tap(find.text('Spiel anfangen!'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byType(PlayerGridView), findsOneWidget);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:werwolf/models/game.dart';
|
||||||
|
import 'package:werwolf/models/player.dart';
|
||||||
|
import 'package:werwolf/models/role.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('Game Tests', () {
|
||||||
|
List<String> playerNames = ['Alice', 'Bob', 'Charlie', 'Dave', 'Eve', 'Frank'];
|
||||||
|
|
||||||
|
test('Initial number of wolves is 1', () {
|
||||||
|
Game game = Game(playernames: playerNames);
|
||||||
|
expect(game.getWolves(), 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Increment wolves within valid range', () {
|
||||||
|
Game game = Game(playernames: playerNames);
|
||||||
|
game.incrementWolves();
|
||||||
|
expect(game.getWolves(), 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Decrement wolves within valid range', () {
|
||||||
|
Game game = Game(playernames: playerNames);
|
||||||
|
game.incrementWolves();
|
||||||
|
game.decrementWolves();
|
||||||
|
expect(game.getWolves(), 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Cannot increment wolves beyond valid range', () {
|
||||||
|
Game game = Game(playernames: playerNames);
|
||||||
|
game.incrementWolves();
|
||||||
|
game.incrementWolves();
|
||||||
|
expect(game.getWolves(), 2); // Should not increment beyond 2 for 6 players
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Cannot decrement wolves below 1', () {
|
||||||
|
Game game = Game(playernames: playerNames);
|
||||||
|
game.decrementWolves();
|
||||||
|
expect(game.getWolves(), 1); // Should not decrement below 1
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Assign roles to players correctly', () {
|
||||||
|
Game game = Game(playernames: playerNames);
|
||||||
|
List<Player> players = game.getAllPlayers();
|
||||||
|
expect(players.length, playerNames.length);
|
||||||
|
int wolfCount = players.where((p) => p.role == Role.werwolf).length;
|
||||||
|
int dorfbewohnerCount = players.where((p) => p.role == Role.dorfbewohner).length;
|
||||||
|
expect(wolfCount, game.getWolves());
|
||||||
|
expect(dorfbewohnerCount, playerNames.length - game.getWolves() - game.specialRoles.values.where((v) => v).length);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Special roles are assigned correctly', () {
|
||||||
|
Game game = Game(playernames: playerNames);
|
||||||
|
game.specialRoles[Role.seher] = true;
|
||||||
|
List<Player> players = game.getAllPlayers();
|
||||||
|
int seherCount = players.where((p) => p.role == Role.seher).length;
|
||||||
|
expect(seherCount, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Multiple special roles assignment', () {
|
||||||
|
Game game = Game(playernames: playerNames);
|
||||||
|
game.specialRoles[Role.seher] = true;
|
||||||
|
game.specialRoles[Role.joker] = true;
|
||||||
|
List<Player> players = game.getAllPlayers();
|
||||||
|
int seherCount = players.where((p) => p.role == Role.seher).length;
|
||||||
|
int jokerCount = players.where((p) => p.role == Role.joker).length;
|
||||||
|
expect(seherCount, 1);
|
||||||
|
expect(jokerCount, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Minimum number of players', () {
|
||||||
|
List<String> minPlayerNames = ['Alice', 'Bob', 'Charlie'];
|
||||||
|
Game game = Game(playernames: minPlayerNames);
|
||||||
|
List<Player> players = game.getAllPlayers();
|
||||||
|
expect(players.length, minPlayerNames.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Maximum number of players (arbitrary large number)', () {
|
||||||
|
List<String> maxPlayerNames = List<String>.generate(100, (index) => 'Player$index');
|
||||||
|
Game game = Game(playernames: maxPlayerNames);
|
||||||
|
List<Player> players = game.getAllPlayers();
|
||||||
|
expect(players.length, maxPlayerNames.length);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -1 +1,20 @@
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:werwolf/models/player.dart';
|
||||||
|
import 'package:werwolf/models/role.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('Player Tests', () {
|
||||||
|
test('Player creation', () {
|
||||||
|
Player player = Player(name: 'Alice', role: Role.dorfbewohner, isDead: false);
|
||||||
|
expect(player.name, 'Alice');
|
||||||
|
expect(player.role, Role.dorfbewohner);
|
||||||
|
expect(player.isDead, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Player status change', () {
|
||||||
|
Player player = Player(name: 'Bob', role: Role.werwolf, isDead: false);
|
||||||
|
player.isDead = true;
|
||||||
|
expect(player.isDead, true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:werwolf/screens/playerregistry.dart';
|
||||||
|
import 'package:werwolf/screens/settings.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('PlayerRegistry Tests', () {
|
||||||
|
testWidgets('Adds a player to the list', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(MaterialApp(home: PlayerRegistry()));
|
||||||
|
|
||||||
|
await tester.enterText(find.byType(TextField), 'Alice');
|
||||||
|
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text('Alice'), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Shows error for duplicate player', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(MaterialApp(home: PlayerRegistry()));
|
||||||
|
|
||||||
|
await tester.enterText(find.byType(TextField), 'Alice');
|
||||||
|
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await tester.enterText(find.byType(TextField), 'Alice');
|
||||||
|
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text('Dieser Spieler existiert bereits'), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Navigates to GameSettings when enough players are added', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(MaterialApp(home: PlayerRegistry()));
|
||||||
|
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
await tester.enterText(find.byType(TextField), 'Player $i');
|
||||||
|
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
|
await tester.tap(find.text('Spiel einstellen'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byType(GameSettings), findsOneWidget);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -1,30 +0,0 @@
|
||||||
// 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.
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
|
|
||||||
import 'package:werwolf/main.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
|
||||||
// Build our app and trigger a frame.
|
|
||||||
await tester.pumpWidget(const MyApp());
|
|
||||||
|
|
||||||
// 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));
|
|
||||||
await tester.pump();
|
|
||||||
|
|
||||||
// Verify that our counter has incremented.
|
|
||||||
expect(find.text('0'), findsNothing);
|
|
||||||
expect(find.text('1'), findsOneWidget);
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in New Issue