58 lines
2.2 KiB
Dart
58 lines
2.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:shared_preferences/shared_preferences.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/settings_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/drop_down.dart';
|
|
import 'package:smoke_cess_app/widgets/view_form/relapse_form.dart';
|
|
import '../mock/db_mock.dart';
|
|
import '../mock/settings_mock.dart';
|
|
|
|
void main() {
|
|
globals.databaseService = DatabaseMock();
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
SharedPreferences.setMockInitialValues(mockSettings);
|
|
testWidgets('Relapse 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();
|
|
final settingsProvider = SettingsProvider();
|
|
await tester.pumpWidget(
|
|
MultiProvider(
|
|
providers: [
|
|
ChangeNotifierProvider.value(value: inputProvider),
|
|
ChangeNotifierProvider.value(value: tasksProvider),
|
|
ChangeNotifierProvider.value(value: pageProvider),
|
|
ChangeNotifierProvider.value(value: settingsProvider),
|
|
],
|
|
child: const MaterialApp(
|
|
home: Scaffold(
|
|
body: RelapseForm(),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
await settingsProvider.initSettings();
|
|
|
|
await tester.enterText(find.byType(TextField), testText);
|
|
await tester.tap(find.byType(DropDown));
|
|
await tester.pump();
|
|
await tester
|
|
.tap(find.text(settingsProvider.settings!.relapseCategories![1]).last);
|
|
await tester.pump();
|
|
await tester.tap(find.byType(ElevatedButton).last);
|
|
await tester.pump();
|
|
final result = await globals.databaseService.getRelapseRecords();
|
|
expect(result.last.comment, testText);
|
|
expect(
|
|
result.last.category, settingsProvider.settings!.relapseCategories![1]);
|
|
});
|
|
}
|