import 'package:cpd/database/todo_db.dart'; import 'package:cpd/pages/iconpage.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:cpd/database/habit.dart'; import 'package:cpd/widgets/edithabit_dialog.dart'; import 'package:sqflite_common_ffi/sqflite_ffi.dart'; void main() { final TodoDB todoDb = TodoDB(); setUpAll(() { sqfliteFfiInit(); databaseFactory = databaseFactoryFfi; }); testWidgets('EditHabitDialog contains all of the ui-elements', (WidgetTester tester) async { final habit = Habit( id: 1, title: 'Existing Habit', subtitle: 'Existing Description', iconCodePoint: Icons.star.codePoint, iconFontFamily: Icons.star.fontFamily ?? 'MaterialIcons', isComplete: false, ); await tester.pumpWidget(MaterialApp( home: Scaffold( body: EditHabitDialog( todo: habit, todoDB: todoDb, fetchTodos: (){}, ), ), )); expect(find.text('Edit Habit'), findsOneWidget); expect(find.text('Existing Habit'), findsOneWidget); expect(find.text('Existing Description'), 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.tap(find.byIcon(Icons.star)); await tester.pumpAndSettle(); IconData newIcon = Icons.code; (tester.firstWidget(find.byType(IconPage)) as IconPage).onIconSelected(newIcon); await tester.tap(find.byIcon(newIcon)); await tester.pumpAndSettle(); final saveButtonFinder = find.widgetWithText(TextButton, 'Save'); expect(saveButtonFinder, findsOneWidget); await tester.tap(saveButtonFinder); await tester.pumpAndSettle(); }); }