import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:provider/provider.dart'; import 'package:smoke_cess_app/providers/input_provider.dart'; import 'package:smoke_cess_app/providers/page_provider.dart'; import 'package:smoke_cess_app/providers/tasks_provider.dart'; import 'package:smoke_cess_app/globals.dart' as globals; import 'package:smoke_cess_app/widgets/view_form/sleep_form.dart'; import '../mock/db_mock.dart'; void main() { globals.databaseService = DatabaseMock(); testWidgets('Sleep Form saves correctly', (WidgetTester tester) async { const String testText = 'Its a test'; // Create an instance of the Providers and add it to the widget tree final inputProvider = InputProvider(); final tasksProvider = TasksProvider(null); final pageProvider = PageProvider(); await tester.pumpWidget( MultiProvider( providers: [ ChangeNotifierProvider.value(value: inputProvider), ChangeNotifierProvider.value(value: tasksProvider), ChangeNotifierProvider.value(value: pageProvider), ], child: const MaterialApp( home: Scaffold( body: SleepForm(), ), ), ), ); await tester.enterText(find.byType(TextField), testText); await tester.tap(find.byType(ElevatedButton).last); await tester.pump(); final result = await globals.databaseService.getSleepRecords(); expect(result.last.comment, testText); expect(result.last.sleepQualitiyValue, 50); expect(result.last.sleepDuration, const TimeOfDay(hour: 10, minute: 0)); }); }