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/widgets/view_form/mood_form.dart'; import 'package:smoke_cess_app/globals.dart' as globals; import '../mock/db_mock.dart'; void main() { globals.databaseService = DatabaseMock(); testWidgets('Mood 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: MoodForm(), ), ), ), ); await tester.enterText(find.byType(TextField), testText); await tester.tap(find.byType(ElevatedButton)); await tester.pump(); final result = await globals.databaseService.getMoodRecords(); expect(result.last.comment, testText); expect(result.last.moodValue, 50); }); }