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';
|
2024-06-08 14:22:18 +02:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
2024-05-24 10:48:58 +02:00
|
|
|
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',
|
2024-06-09 17:45:17 +02:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
}
|