cpd_David_und_Yusuf/test/playerregistry_test.dart

48 lines
1.7 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/screens/playerregistry.dart';
import 'package:werwolf/screens/settings.dart';
void main() {
group('PlayerRegistry Tests', () {
testWidgets('Adds a player to the list', (WidgetTester tester) async {
2024-06-13 12:34:45 +02:00
await tester.pumpWidget(const MaterialApp(home: PlayerRegistry()));
2024-06-13 01:30:02 +02:00
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 {
2024-06-13 12:34:45 +02:00
await tester.pumpWidget(const MaterialApp(home: PlayerRegistry()));
2024-06-13 01:30:02 +02:00
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 {
2024-06-13 12:34:45 +02:00
await tester.pumpWidget(const MaterialApp(home: PlayerRegistry()));
2024-06-13 01:30:02 +02:00
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);
});
});
}