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/edithabitDialog.dart'; import 'package:sqflite_common_ffi/sqflite_ffi.dart'; void main() { final TodoDB todoDb = TodoDB(); setUpAll(() { sqfliteFfiInit(); databaseFactory = databaseFactoryFfi; }); testWidgets('EditHabitDialog displays and updates habit correctly', (WidgetTester tester) async { final habit = Habit( id: 1, title: 'Existing Habit', subtitle: 'Existing Description', icon: Icons.star, 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); // Enter new title and subtitle await tester.enterText(find.byType(TextFormField).at(0), 'New Habit Title'); await tester.enterText(find.byType(TextFormField).at(1), 'New Habit Description'); // Check if the icon is visible await tester.tap(find.byIcon(Icons.star)); await tester.pumpAndSettle(); //Choose new icon IconData newIcon = Icons.code; (tester.firstWidget(find.byType(IconPage)) as IconPage).onIconSelected(newIcon); await tester.tap(find.byIcon(newIcon)); await tester.pumpAndSettle(); // Finds the save button and taps final saveButtonFinder = find.widgetWithText(TextButton, 'Save'); expect(saveButtonFinder, findsOneWidget); await tester.tap(saveButtonFinder); await tester.pumpAndSettle(); }); }