cpd/test/widget_testing/edithabit_dialog_test.dart

62 lines
1.8 KiB
Dart
Raw Normal View History

2024-05-24 00:01:08 +02:00
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';
2024-05-24 00:01:08 +02:00
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 {
2024-05-24 00:01:08 +02:00
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();
});
}