2024-06-18 01:46:57 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:integration_test/integration_test.dart';
|
|
|
|
import 'package:werwolf/main.dart' as app;
|
|
|
|
import 'package:werwolf/screens/playerregistry.dart';
|
|
|
|
import 'package:werwolf/screens/settings.dart';
|
|
|
|
import 'package:werwolf/screens/flippingcards.dart';
|
|
|
|
import 'package:werwolf/screens/gameboard.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
group('Werwolf Game Integration Tests', () {
|
|
|
|
testWidgets('Complete game flow', (WidgetTester tester) async {
|
|
|
|
app.main();
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
|
|
|
// Ensure we are on the PlayerRegistry screen
|
|
|
|
expect(find.byType(PlayerRegistry), findsOneWidget);
|
|
|
|
|
|
|
|
// Add players
|
2024-06-19 11:58:49 +02:00
|
|
|
for (int i = 1; i <= 6; i++) {
|
|
|
|
// Find the TextField, enter text, and simulate the 'done' action on the keyboard
|
|
|
|
await tester.tap(find.byType(TextField).first);
|
|
|
|
await tester.enterText(find.byType(TextField).first, 'Player $i');
|
2024-06-18 01:46:57 +02:00
|
|
|
await tester.testTextInput.receiveAction(TextInputAction.done);
|
2024-06-19 11:58:49 +02:00
|
|
|
// Wait for the UI to settle before proceeding
|
2024-06-18 01:46:57 +02:00
|
|
|
await tester.pumpAndSettle();
|
2024-06-19 11:58:49 +02:00
|
|
|
// Debug print to check entered text
|
|
|
|
debugPrint('Entered Player $i');
|
2024-06-18 01:46:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure all players are added
|
2024-06-19 11:58:49 +02:00
|
|
|
for (int i = 1; i <= 6; i++) {
|
2024-06-18 01:46:57 +02:00
|
|
|
expect(find.text('Player $i'), findsOneWidget);
|
2024-06-19 11:58:49 +02:00
|
|
|
// Debug print to confirm text presence
|
|
|
|
debugPrint('Confirmed Player $i is present');
|
2024-06-18 01:46:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Navigate to GameSettings screen
|
|
|
|
await tester.tap(find.text('Spiel einstellen'));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byType(GameSettings), findsOneWidget);
|
|
|
|
|
|
|
|
// Ensure the number of players and wolves are displayed correctly
|
|
|
|
expect(find.text('Anzahl der Spieler 6'), findsOneWidget);
|
|
|
|
expect(find.text('Anzahl der Werwölfe 1'), findsOneWidget);
|
|
|
|
|
|
|
|
// Toggle a special role
|
|
|
|
await tester.tap(find.byType(Switch).first);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect((tester.widget(find.byType(Switch).first) as Switch).value, true);
|
|
|
|
|
|
|
|
// Navigate to FlipingCard screen
|
|
|
|
await tester.tap(find.text('Spiel starten!'));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byType(FlipingCard), findsOneWidget);
|
|
|
|
|
2024-06-19 11:58:49 +02:00
|
|
|
// Track player roles
|
|
|
|
Map<String, String> playerRoles = {};
|
|
|
|
|
2024-06-18 01:46:57 +02:00
|
|
|
// Flip through all players
|
2024-06-19 11:58:49 +02:00
|
|
|
for (int i = 1; i <= 5; i++) {
|
2024-06-18 01:46:57 +02:00
|
|
|
await tester.tap(find.text('Klick um deine Rolle zu sehen!'));
|
|
|
|
await tester.pumpAndSettle();
|
2024-06-19 11:58:49 +02:00
|
|
|
|
|
|
|
// Debug print to check the UI and role text
|
2024-06-19 12:08:45 +02:00
|
|
|
for (var widget in tester.allWidgets) {
|
2024-06-19 11:58:49 +02:00
|
|
|
if (widget is Text) {
|
|
|
|
debugPrint('Text widget: ${widget.data}');
|
|
|
|
}
|
2024-06-19 12:08:45 +02:00
|
|
|
}
|
2024-06-19 11:58:49 +02:00
|
|
|
|
|
|
|
// Assuming the role is displayed somewhere we can read
|
|
|
|
// Adjust the role extraction to how your app displays the role
|
|
|
|
String role = tester
|
|
|
|
.widgetList<Text>(find.byType(Text))
|
|
|
|
.map((e) => e.data!)
|
|
|
|
.firstWhere(
|
|
|
|
(text) =>
|
|
|
|
text.contains('Dorfbewohner') ||
|
|
|
|
text.contains('Werwolf') ||
|
|
|
|
text.contains('Joker'),
|
|
|
|
orElse: () => 'Unknown');
|
|
|
|
|
|
|
|
if (role == 'Unknown') {
|
|
|
|
throw StateError('No valid role found for Player $i');
|
|
|
|
}
|
|
|
|
|
|
|
|
playerRoles['Player $i'] = role;
|
|
|
|
|
2024-06-18 01:46:57 +02:00
|
|
|
await tester.tap(find.text('Nächster Spieler'));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure we navigate to the game board
|
|
|
|
await tester.tap(find.text('Spiel anfangen!'));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byType(PlayerGridView), findsOneWidget);
|
|
|
|
|
2024-06-19 11:58:49 +02:00
|
|
|
// Find a player who is not a Werewolf to kill
|
|
|
|
String playerToKill = playerRoles.entries
|
|
|
|
.firstWhere((entry) => entry.value != 'Werwolf')
|
|
|
|
.key;
|
|
|
|
|
|
|
|
// Tap to kill a non-Werewolf player
|
|
|
|
await tester.tap(find.text(playerToKill));
|
2024-06-18 01:46:57 +02:00
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byIcon(Icons.close), findsOneWidget);
|
2024-06-19 11:58:49 +02:00
|
|
|
expect(find.byIcon(Icons.wb_sunny), findsOneWidget);
|
2024-06-18 01:46:57 +02:00
|
|
|
|
|
|
|
// Skip phase
|
2024-06-19 11:58:49 +02:00
|
|
|
await tester.tap(find.byType(ElevatedButton).first);
|
2024-06-18 01:46:57 +02:00
|
|
|
await tester.pumpAndSettle();
|
2024-06-19 11:58:49 +02:00
|
|
|
expect(find.byIcon(Icons.nights_stay), findsOneWidget);
|
2024-06-18 01:46:57 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|