cpd_David_und_Yusuf/test/settings_test.dart

51 lines
1.9 KiB
Dart
Raw Normal View History

2024-06-18 01:46:57 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:werwolf/screens/settings.dart';
import 'package:werwolf/screens/flippingcards.dart';
void main() {
group('GameSettings Tests', () {
List<String> playerNames = ['Alice', 'Bob', 'Charlie', 'Dave', 'Eve', 'Frank'];
testWidgets('Displays number of players', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: GameSettings(playernames: playerNames)));
expect(find.text('Anzahl der Spieler 6'), findsOneWidget);
});
testWidgets('Displays number of wolves and increments/decrements correctly', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: GameSettings(playernames: playerNames)));
expect(find.text('Anzahl der Werwölfe 1'), findsOneWidget);
await tester.tap(find.byIcon(Icons.add));
await tester.pumpAndSettle();
expect(find.text('Anzahl der Werwölfe 2'), findsOneWidget);
await tester.tap(find.byIcon(Icons.remove));
await tester.pumpAndSettle();
expect(find.text('Anzahl der Werwölfe 1'), findsOneWidget);
});
testWidgets('Displays special roles and toggles switches', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: GameSettings(playernames: playerNames)));
expect(find.text('Spezielle Rollen'), findsOneWidget);
await tester.tap(find.byType(Switch).first);
await tester.pumpAndSettle();
expect((tester.widget(find.byType(Switch).first) as Switch).value, true);
});
testWidgets('Navigates to FlipingCard screen on start', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: GameSettings(playernames: playerNames)));
await tester.tap(find.text('Spiel starten!'));
await tester.pumpAndSettle();
expect(find.byType(FlipingCard), findsOneWidget);
});
});
}