43 lines
1.4 KiB
Dart
43 lines
1.4 KiB
Dart
|
import 'package:cpd/widgets/addhabit_popup.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter_test/flutter_test.dart';
|
||
|
|
||
|
void main() {
|
||
|
testWidgets('AddHabitPopup form submission', (WidgetTester tester) async {
|
||
|
// Arrange
|
||
|
String submittedTitle = '';
|
||
|
String submittedSubtitle = '';
|
||
|
IconData submittedIcon = Icons.favorite;
|
||
|
|
||
|
// Eine echte onSubmit-Funktion erstellen, um die Daten zu erfassen
|
||
|
void handleSubmit(String title, String subtitle, IconData icon) {
|
||
|
submittedTitle = title;
|
||
|
submittedSubtitle = subtitle;
|
||
|
submittedIcon = icon;
|
||
|
}
|
||
|
|
||
|
await tester.pumpWidget(MaterialApp(
|
||
|
home: Scaffold(
|
||
|
body: AddHabitPopup(
|
||
|
onSubmit: handleSubmit, // Die echte onSubmit-Funktion übergeben
|
||
|
),
|
||
|
),
|
||
|
));
|
||
|
|
||
|
// Enter title and subtitle
|
||
|
await tester.enterText(find.byType(TextFormField).at(0), 'New Habit Title');
|
||
|
await tester.enterText(
|
||
|
find.byType(TextFormField).at(1), 'New Habit Description');
|
||
|
|
||
|
// Den "Save"-Button tippen
|
||
|
await tester.tap(find.text('Save'));
|
||
|
|
||
|
// Warten, bis alle Animationen abgeschlossen sind
|
||
|
await tester.pumpAndSettle();
|
||
|
|
||
|
// Assert: Überprüfen, ob handleSubmit mit den erwarteten Daten aufgerufen wurde
|
||
|
expect(submittedTitle, 'New Habit Title');
|
||
|
expect(submittedSubtitle, 'New Habit Description');
|
||
|
expect(submittedIcon, Icons.favorite); // Hier den erwarteten Icon-Wert einfügen
|
||
|
});
|
||
|
}
|