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/widgets/addhabit_popup.dart'; import 'package:mockito/mockito.dart'; import 'package:sqflite_common_ffi/sqflite_ffi.dart'; class MockTodoDB extends Mock implements TodoDB {} void main() { setUpAll(() { sqfliteFfiInit(); databaseFactory = databaseFactoryFfi; }); testWidgets('AddHabitPopup Dialog contains all of the UI-elements', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( home: Scaffold( body: AddHabitPopup( onSubmit: (title, subtitle, icon) {}, ), ), )); // Verifying that the AddHabitPopup is displayed expect(find.text('Add task'), findsOneWidget); // Enter title and subtitle print('Entering 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'); // Ensure widgets are rendered await tester.pumpAndSettle(); // Verifying that the Save button is present final saveButtonFinder = find.byKey(const Key('Save')); expect(saveButtonFinder, findsOneWidget); //finds and taps save button await tester.tap(saveButtonFinder); await tester.pumpAndSettle(); // Simulate selecting a new icon from the IconPage IconData newIcon = Icons.star; // Tap the 'Select Icon' button await tester.tap(find.text('Select Icon')); await tester.pumpAndSettle(); // Simulate the icon selection callback (tester.firstWidget(find.byType(IconPage)) as IconPage).onIconSelected(newIcon); await tester.pumpAndSettle(); // Verify the new icon is displayed expect(find.byIcon(newIcon), findsOneWidget); await tester.pumpAndSettle(); }); }