CPD/Pong/test/widget_test.dart

48 lines
1.6 KiB
Dart
Raw Normal View History

2023-11-21 15:53:43 +01:00
import 'package:flutter/material.dart';
2024-01-10 22:59:41 +01:00
import 'package:flutter/scheduler.dart';
2023-11-21 15:53:43 +01:00
import 'package:flutter_test/flutter_test.dart';
import 'package:pong/main.dart';
void main() {
2024-01-11 02:38:41 +01:00
// Widget test for the "Berühren um zu beginnen!" message
2023-11-21 23:41:52 +01:00
testWidgets('Tests "Berühren um zu beginnen!"', (WidgetTester tester) async {
2024-01-10 22:59:41 +01:00
final tapToStart = find.text("Berühren um zu beginnen!");
2023-11-21 15:53:43 +01:00
2024-01-11 02:38:41 +01:00
// Build the widget tree with StartScreen and pump the widget tree
2023-11-21 23:41:52 +01:00
await tester.pumpWidget(const MaterialApp(home: StartScreen()));
2024-01-10 22:59:41 +01:00
2024-01-11 02:38:41 +01:00
// Verify that the "Berühren um zu beginnen!" text is displayed
2024-01-10 22:59:41 +01:00
expect(tapToStart, findsOneWidget);
});
2024-01-11 02:38:41 +01:00
// Widget test for the "Punkte:" message in GameScreen
2024-01-10 22:59:41 +01:00
testWidgets('Tests "Punkte:"', (WidgetTester tester) async {
final points = find.text("Punkte: 0");
2024-01-11 02:38:41 +01:00
// Build the widget tree with GameScreen and pump the widget tree
2024-01-10 22:59:41 +01:00
await tester.pumpWidget(const MaterialApp(home: GameScreen()));
2024-01-11 02:38:41 +01:00
// Verify that the "Punkte: 0" text is displayed
2024-01-10 22:59:41 +01:00
expect(points, findsOneWidget);
});
2024-01-11 02:38:41 +01:00
// Widget test for the UI of StartScreen
2024-01-10 22:59:41 +01:00
testWidgets('StartScreen UI Test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MaterialApp(
home: StartScreen(),
));
2024-01-11 02:38:41 +01:00
// Verify that the "Berühren um zu beginnen!" Text is displayed.
2024-01-10 22:59:41 +01:00
expect(find.text('Berühren um zu beginnen!'), findsOneWidget);
2024-01-11 02:38:41 +01:00
// Tap on the GestureDetector to navigate to GameScreen.
2024-01-10 22:59:41 +01:00
await tester.tap(find.byType(GestureDetector));
2023-11-21 15:53:43 +01:00
await tester.pump();
2024-01-11 02:38:41 +01:00
// Verify that the transition to GameScreen has occurred.
2024-01-10 22:59:41 +01:00
expect(find.byType(GameScreen), findsOneWidget);
2023-11-21 15:53:43 +01:00
});
}