Added Integrationtests
parent
7b4d7abe4e
commit
52ec92b566
|
@ -31,7 +31,7 @@ class TasksProvider extends ChangeNotifier {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initHistories() async {
|
Future<void> initHistories() async {
|
||||||
moodHistory = await globals.databaseService.getMoodRecords();
|
moodHistory = await globals.databaseService.getMoodRecords();
|
||||||
sleepHistory = await globals.databaseService.getSleepRecords();
|
sleepHistory = await globals.databaseService.getSleepRecords();
|
||||||
workoutHistory = await globals.databaseService.getWorkoutRecords();
|
workoutHistory = await globals.databaseService.getWorkoutRecords();
|
||||||
|
|
|
@ -13,8 +13,8 @@ class MoodForm extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var inputModel = context.watch<InputProvider>();
|
InputProvider inputModel = context.watch<InputProvider>();
|
||||||
var tasksModel = context.watch<TasksProvider>();
|
TasksProvider tasksModel = context.watch<TasksProvider>();
|
||||||
return ListView(
|
return ListView(
|
||||||
padding: const EdgeInsets.fromLTRB(10, 10, 10, 10),
|
padding: const EdgeInsets.fromLTRB(10, 10, 10, 10),
|
||||||
children: [
|
children: [
|
||||||
|
|
|
@ -27,7 +27,7 @@ class SleepView extends StatelessWidget {
|
||||||
history: tasksModel.sleepHistory,
|
history: tasksModel.sleepHistory,
|
||||||
dateSelector: (Sleep sleep) => sleep.date,
|
dateSelector: (Sleep sleep) => sleep.date,
|
||||||
entryDataSelector: (Sleep sleep) =>
|
entryDataSelector: (Sleep sleep) =>
|
||||||
'${sleep.sleepDuration.hour}:${sleep.sleepDuration.minute}',
|
'${sleep.sleepDuration.hour}:${sleep.sleepDuration.minute.toString().padLeft(2, "0")}',
|
||||||
entryCommentSelector: (Sleep sleep) => 'Kommentar: ${sleep.comment}',
|
entryCommentSelector: (Sleep sleep) => 'Kommentar: ${sleep.comment}',
|
||||||
icon: Icons.bedtime_outlined,
|
icon: Icons.bedtime_outlined,
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:intl/date_symbol_data_local.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:smoke_cess_app/models/mood.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/view_form/mood_view.dart';
|
||||||
|
import '../mock/db_mock.dart';
|
||||||
|
import '../mock/settings_mock.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
globals.databaseService = DatabaseMock();
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
SharedPreferences.setMockInitialValues(mockSettings);
|
||||||
|
initializeDateFormatting('de');
|
||||||
|
testWidgets('Mood View displays correctly', (WidgetTester tester) async {
|
||||||
|
const String testText = 'Its a test';
|
||||||
|
const int testValue = 30;
|
||||||
|
// Create an instance of the Providers and add it to the widget tree
|
||||||
|
final tasksProvider = TasksProvider(null);
|
||||||
|
final settingsProvider = SettingsProvider();
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MultiProvider(
|
||||||
|
providers: [
|
||||||
|
ChangeNotifierProvider.value(value: tasksProvider),
|
||||||
|
ChangeNotifierProvider.value(value: settingsProvider),
|
||||||
|
],
|
||||||
|
child: const MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: MoodView(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await settingsProvider.initSettings();
|
||||||
|
await globals.databaseService
|
||||||
|
.addMood(Mood(testValue, testText, DateTime.now()));
|
||||||
|
await tasksProvider.initHistories();
|
||||||
|
await tester.pump();
|
||||||
|
expect(find.text('Stimmung: $testValue'), findsOneWidget);
|
||||||
|
await tester.tap(find.byIcon(Icons.expand_more));
|
||||||
|
await tester.pump();
|
||||||
|
expect(find.text('Kommentar: $testText'), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
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]);
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:intl/date_symbol_data_local.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:smoke_cess_app/models/relapse.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/view_form/relapse_view.dart';
|
||||||
|
import '../mock/db_mock.dart';
|
||||||
|
import '../mock/settings_mock.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
globals.databaseService = DatabaseMock();
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
SharedPreferences.setMockInitialValues(mockSettings);
|
||||||
|
initializeDateFormatting('de');
|
||||||
|
testWidgets('Relapse View displays correctly', (WidgetTester tester) async {
|
||||||
|
const String testText = 'Its a test';
|
||||||
|
// Create an instance of the Providers and add it to the widget tree
|
||||||
|
final tasksProvider = TasksProvider(null);
|
||||||
|
final settingsProvider = SettingsProvider();
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MultiProvider(
|
||||||
|
providers: [
|
||||||
|
ChangeNotifierProvider.value(value: tasksProvider),
|
||||||
|
ChangeNotifierProvider.value(value: settingsProvider),
|
||||||
|
],
|
||||||
|
child: const MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: RelapseView(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await settingsProvider.initSettings();
|
||||||
|
await globals.databaseService.addRelapse(Relapse(
|
||||||
|
settingsProvider.settings!.relapseCategories![0],
|
||||||
|
testText,
|
||||||
|
DateTime.now(),
|
||||||
|
));
|
||||||
|
await tasksProvider.initHistories();
|
||||||
|
await tester.pump();
|
||||||
|
expect(find.text(settingsProvider.settings!.relapseCategories![0]),
|
||||||
|
findsOneWidget);
|
||||||
|
await tester.tap(find.byIcon(Icons.expand_more));
|
||||||
|
await tester.pump();
|
||||||
|
expect(find.text('Kommentar: $testText'), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
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));
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:intl/date_symbol_data_local.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:smoke_cess_app/models/sleep.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/view_form/sleep_view.dart';
|
||||||
|
import '../mock/db_mock.dart';
|
||||||
|
import '../mock/settings_mock.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
globals.databaseService = DatabaseMock();
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
SharedPreferences.setMockInitialValues(mockSettings);
|
||||||
|
initializeDateFormatting('de');
|
||||||
|
testWidgets('Sleep View displays correctly', (WidgetTester tester) async {
|
||||||
|
const String testText = 'Its a test';
|
||||||
|
const int testValue = 30;
|
||||||
|
// Create an instance of the Providers and add it to the widget tree
|
||||||
|
final tasksProvider = TasksProvider(null);
|
||||||
|
final settingsProvider = SettingsProvider();
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MultiProvider(
|
||||||
|
providers: [
|
||||||
|
ChangeNotifierProvider.value(value: tasksProvider),
|
||||||
|
ChangeNotifierProvider.value(value: settingsProvider),
|
||||||
|
],
|
||||||
|
child: const MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: SleepView(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await settingsProvider.initSettings();
|
||||||
|
await globals.databaseService.addSleep(Sleep(
|
||||||
|
testValue,
|
||||||
|
testText,
|
||||||
|
DateTime.now(),
|
||||||
|
const TimeOfDay(hour: 22, minute: 0),
|
||||||
|
const TimeOfDay(hour: 8, minute: 0)));
|
||||||
|
await tasksProvider.initHistories();
|
||||||
|
await tester.pump();
|
||||||
|
expect(find.text('10:00'), findsOneWidget);
|
||||||
|
await tester.tap(find.byIcon(Icons.expand_more));
|
||||||
|
await tester.pump();
|
||||||
|
expect(find.text('Kommentar: $testText'), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue