39 lines
1.1 KiB
Dart
39 lines
1.1 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 {
|
|
|
|
String submittedTitle = '';
|
|
String submittedSubtitle = '';
|
|
IconData submittedIcon = Icons.favorite;
|
|
|
|
// erstellt eine echte onSubmit-Funktion,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,
|
|
),
|
|
),
|
|
));
|
|
|
|
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);
|
|
});
|
|
} |