2024-05-30 19:43:56 +02:00
|
|
|
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 {
|
2024-06-16 17:12:28 +02:00
|
|
|
|
2024-05-30 19:43:56 +02:00
|
|
|
String submittedTitle = '';
|
|
|
|
String submittedSubtitle = '';
|
|
|
|
IconData submittedIcon = Icons.favorite;
|
|
|
|
|
2024-06-16 17:12:28 +02:00
|
|
|
// erstellt eine echte onSubmit-Funktion,um die Daten zu erfassen
|
2024-05-30 19:43:56 +02:00
|
|
|
void handleSubmit(String title, String subtitle, IconData icon) {
|
|
|
|
submittedTitle = title;
|
|
|
|
submittedSubtitle = subtitle;
|
|
|
|
submittedIcon = icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
await tester.pumpWidget(MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
body: AddHabitPopup(
|
2024-06-16 17:12:28 +02:00
|
|
|
onSubmit: handleSubmit,
|
2024-05-30 19:43:56 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
|
|
|
|
await tester.enterText(find.byType(TextFormField).at(0), 'New Habit Title');
|
|
|
|
await tester.enterText(
|
|
|
|
find.byType(TextFormField).at(1), 'New Habit Description');
|
|
|
|
|
|
|
|
await tester.tap(find.text('Save'));
|
|
|
|
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
|
|
|
expect(submittedTitle, 'New Habit Title');
|
|
|
|
expect(submittedSubtitle, 'New Habit Description');
|
2024-06-16 17:12:28 +02:00
|
|
|
expect(submittedIcon, Icons.favorite);
|
2024-05-30 19:43:56 +02:00
|
|
|
});
|
|
|
|
}
|