cpd/test/widget_testing/homepage_test.dart

36 lines
1.1 KiB
Dart

import 'package:cpd/pages/homepage.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:cpd/database/db.dart';
import 'package:cpd/database/todo_db.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
class MockTodoDB extends Mock implements TodoDB {}
void main() {
setUpAll(() {
sqfliteFfiInit();
databaseFactory = databaseFactoryFfi;
});
testWidgets('MyHomePage displays correctly', (WidgetTester tester) async {
final mockHabitDatabase = HabitDatabase();
await tester.pumpWidget(MaterialApp(
home: MyHomePage(database: mockHabitDatabase, title: 'homepage'),
));
expect(find.text('step by step, day by day'), findsOneWidget);
expect(find.text('Keep Going!'), findsOneWidget);
expect(find.byType(FloatingActionButton), findsOneWidget);
await tester.tap(find.byType(FloatingActionButton));
await tester.pumpAndSettle();
// close the addhabit-dialog, as it was already tested in addhabit_popup.dart
await tester.tap(find.byType(IconButton));
await tester.pumpAndSettle();
});
}