cpd/test/widget_testing/edithabit_dialog_test.dart

59 lines
1.8 KiB
Dart
Raw Permalink 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',
iconCodePoint: Icons.star.codePoint,
iconFontFamily: Icons.star.fontFamily ?? 'MaterialIcons',
2024-05-24 00:01:08 +02:00
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();
});
}