2024-05-24 10:48:58 +02:00
|
|
|
import 'package:cpd/database/todo_db.dart';
|
2024-06-08 14:22:18 +02:00
|
|
|
import 'package:cpd/widgets/edithabit_dialog.dart';
|
2024-05-24 10:48:58 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:cpd/database/habit.dart';
|
|
|
|
import 'package:cpd/widgets/listview.dart';
|
|
|
|
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
final todoDb = TodoDB();
|
|
|
|
|
|
|
|
setUpAll(() {
|
|
|
|
sqfliteFfiInit();
|
|
|
|
databaseFactory = databaseFactoryFfi;
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('MyListView displays and interacts correctly', (WidgetTester tester) async {
|
|
|
|
final habits = [
|
2024-06-09 17:45:17 +02:00
|
|
|
Habit(id: 1, title: 'Habit 1', subtitle: 'Description 1', iconCodePoint: Icons.star.codePoint,
|
|
|
|
iconFontFamily: Icons.star.fontFamily ?? 'MaterialIcons', isComplete: false),
|
|
|
|
Habit(id: 2, title: 'Habit 2', subtitle: 'Description 2', iconCodePoint: Icons.star_border.codePoint,
|
|
|
|
iconFontFamily: Icons.star_border.fontFamily ?? 'MaterialIcons', isComplete: true),
|
2024-05-24 10:48:58 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
await tester.pumpWidget(MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
body: MyListView(
|
|
|
|
habits: habits,
|
|
|
|
todoDB: todoDb,
|
|
|
|
fetchTodos: () {},
|
2024-06-08 14:22:18 +02:00
|
|
|
updateCounter: (int count) {},
|
2024-05-24 10:48:58 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
|
|
|
|
expect(find.byType(ListView), findsOneWidget);
|
|
|
|
expect(find.byType(ListTile), findsNWidgets(habits.length));
|
|
|
|
|
|
|
|
for (final habit in habits) {
|
|
|
|
expect(find.text(habit.title), findsOneWidget);
|
|
|
|
expect(find.text(habit.subtitle), findsOneWidget);
|
|
|
|
expect(find.byIcon(habit.icon), findsOneWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
final firstHabitCheckbox = find.byType(Checkbox).at(0);
|
|
|
|
expect(firstHabitCheckbox, findsOneWidget);
|
|
|
|
expect((tester.widget(firstHabitCheckbox) as Checkbox).value, habits[0].isComplete);
|
|
|
|
|
|
|
|
await tester.tap(firstHabitCheckbox);
|
2024-06-09 12:25:38 +02:00
|
|
|
await tester.pumpAndSettle();
|
2024-05-24 10:48:58 +02:00
|
|
|
expect((tester.widget(firstHabitCheckbox) as Checkbox).value, habits[0].isComplete);
|
|
|
|
|
|
|
|
final secondHabitCheckbox = find.byType(Checkbox).at(1);
|
|
|
|
expect(secondHabitCheckbox, findsOneWidget);
|
|
|
|
expect((tester.widget(secondHabitCheckbox) as Checkbox).value, habits[1].isComplete);
|
|
|
|
|
|
|
|
await tester.tap(secondHabitCheckbox);
|
2024-06-09 12:25:38 +02:00
|
|
|
await tester.pumpAndSettle();
|
2024-05-24 10:48:58 +02:00
|
|
|
expect((tester.widget(secondHabitCheckbox) as Checkbox).value, habits[1].isComplete);
|
|
|
|
|
|
|
|
final firstHabitListTile = find.byType(ListTile).at(0);
|
2024-06-16 17:12:28 +02:00
|
|
|
await tester.drag(firstHabitListTile, const Offset(-500.0, 0.0));
|
|
|
|
await tester.pumpAndSettle();
|
2024-05-24 10:48:58 +02:00
|
|
|
expect(find.text("${habits[0].title} was dismissed"), findsOneWidget);
|
|
|
|
|
2024-06-16 17:12:28 +02:00
|
|
|
await tester.drag(firstHabitListTile, const Offset(500.0, 0.0));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
2024-05-24 10:48:58 +02:00
|
|
|
expect(find.byType(EditHabitDialog), findsOneWidget);
|
|
|
|
|
2024-06-08 14:22:18 +02:00
|
|
|
//close the EditHabitDialog as it was already tested in edithabit_dialog_test.dart
|
2024-05-24 10:48:58 +02:00
|
|
|
final cancelButtonFinder = find.widgetWithText(TextButton, 'Cancel');
|
|
|
|
expect(cancelButtonFinder, findsOneWidget);
|
|
|
|
await tester.tap(cancelButtonFinder);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
});
|
2024-05-30 19:43:56 +02:00
|
|
|
}
|