cpd/test/widget_testing/addhabit_popup_test.dart

46 lines
1.3 KiB
Dart
Raw Normal View History

2024-05-24 00:01:08 +02:00
import 'package:cpd/pages/iconpage.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:cpd/widgets/addhabit_popup.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
void main() {
setUpAll(() {
sqfliteFfiInit();
databaseFactory = databaseFactoryFfi;
});
testWidgets('AddHabitPopup Dialog contains all of the UI-elements', (WidgetTester tester) async {
2024-05-24 00:01:08 +02:00
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: AddHabitPopup(
onSubmit: (title, subtitle, icon) {},
),
),
));
expect(find.text('Add task'), findsOneWidget);
await tester.enterText(find.byType(TextFormField).at(0), 'New Habit Title');
await tester.enterText(find.byType(TextFormField).at(1), 'New Habit Description');
await tester.pumpAndSettle();
final saveButtonFinder = find.byKey(const Key('Save'));
expect(saveButtonFinder, findsOneWidget);
await tester.tap(saveButtonFinder);
await tester.pumpAndSettle();
IconData newIcon = Icons.star;
await tester.tap(find.text('Select Icon'));
await tester.pumpAndSettle();
(tester.firstWidget(find.byType(IconPage)) as IconPage).onIconSelected(newIcon);
await tester.pumpAndSettle();
expect(find.byIcon(newIcon), findsOneWidget);
await tester.pumpAndSettle();
});
}