diff --git a/pubspec.yaml b/pubspec.yaml index 9f287bc..4316417 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -20,3 +20,5 @@ dev_dependencies: flutter: uses-material-design: true + + diff --git a/test/flippingcards_test.dart b/test/flippingcards_test.dart new file mode 100644 index 0000000..dd697f5 --- /dev/null +++ b/test/flippingcards_test.dart @@ -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 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); + }); + }); +} diff --git a/test/game_test.dart b/test/game_test.dart new file mode 100644 index 0000000..ee4b135 --- /dev/null +++ b/test/game_test.dart @@ -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 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 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 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 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 minPlayerNames = ['Alice', 'Bob', 'Charlie']; + Game game = Game(playernames: minPlayerNames); + List players = game.getAllPlayers(); + expect(players.length, minPlayerNames.length); + }); + + test('Maximum number of players (arbitrary large number)', () { + List maxPlayerNames = List.generate(100, (index) => 'Player$index'); + Game game = Game(playernames: maxPlayerNames); + List players = game.getAllPlayers(); + expect(players.length, maxPlayerNames.length); + }); + }); +} diff --git a/test/gameboard_test..dart b/test/gameboard_test..dart new file mode 100644 index 0000000..a55d98f --- /dev/null +++ b/test/gameboard_test..dart @@ -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 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); + }); + }); +} diff --git a/test/player_test.dart b/test/player_test.dart index 8b13789..09cb2dc 100644 --- a/test/player_test.dart +++ b/test/player_test.dart @@ -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); + }); + }); +} diff --git a/test/playerregistry_test.dart b/test/playerregistry_test.dart new file mode 100644 index 0000000..3245fa9 --- /dev/null +++ b/test/playerregistry_test.dart @@ -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); + }); + }); +} diff --git a/test/widget_test.dart b/test/widget_test.dart deleted file mode 100644 index 1421343..0000000 --- a/test/widget_test.dart +++ /dev/null @@ -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); - }); -}