cpd/test/integration_testing/addhabit_popup_submitform_t...

39 lines
1.1 KiB
Dart
Raw Permalink Normal View History

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-05-30 19:43:56 +02:00
String submittedTitle = '';
String submittedSubtitle = '';
IconData submittedIcon = Icons.favorite;
// 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(
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');
expect(submittedIcon, Icons.favorite);
2024-05-30 19:43:56 +02:00
});
}