cpd/test/widget_testing/homepage_test.dart

39 lines
1.2 KiB
Dart
Raw Normal View History

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 {
// Mock HabitDatabase
final mockHabitDatabase = HabitDatabase();
await tester.pumpWidget(MaterialApp(
home: MyHomePage(database: mockHabitDatabase, title: 'homepage'),
));
// Verify initial state
expect(find.text('step by step, day by day'), findsOneWidget);
expect(find.text('Keep Going!'), findsOneWidget);
expect(find.byType(FloatingActionButton), findsOneWidget);
// Tap the FloatingActionButton to add a new habit
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();
});
}