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/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;
|
|
|
|
});
|
|
|
|
|
2024-05-24 10:48:58 +02:00
|
|
|
testWidgets('AddHabitPopup Dialog contains all of the UI-elements', (WidgetTester tester) async {
|
2024-05-24 00:01:08 +02:00
|
|
|
await tester.pumpWidget(MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
body: AddHabitPopup(
|
|
|
|
onSubmit: (title, subtitle, icon) {},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
|
|
|
|
expect(find.text('Add task'), 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.pumpAndSettle();
|
|
|
|
|
|
|
|
final saveButtonFinder = find.byKey(const Key('Save'));
|
|
|
|
expect(saveButtonFinder, findsOneWidget);
|
|
|
|
|
|
|
|
await tester.tap(saveButtonFinder);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
|
|
|
IconData newIcon = Icons.star;
|
|
|
|
|
|
|
|
await tester.tap(find.text('Select Icon'));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
|
|
|
(tester.firstWidget(find.byType(IconPage)) as IconPage).onIconSelected(newIcon);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
|
|
|
expect(find.byIcon(newIcon), findsOneWidget);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
});
|
|
|
|
}
|