cpd/test/widget_testing/addhabit_popup_test.dart

50 lines
1.5 KiB
Dart

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;
});
testWidgets('AddHabitPopup Dialog contains all of the UI-elements', (WidgetTester tester) async {
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();
});
}