create_input_provider_test

main
Hinrik Ehrenfried 2023-03-02 18:49:14 +01:00
parent 86d42b40ad
commit 76e7309467
1 changed files with 87 additions and 0 deletions

View File

@ -0,0 +1,87 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:smoke_cess_app/providers/input_provider.dart';
void main() {
group('InputProvider', () {
test('Initial values are correct', () {
late final inputProvider = InputProvider();
expect(inputProvider.sliderValue, equals(50));
expect(inputProvider.textController.text, equals(''));
expect(inputProvider.relapseCategory, equals(''));
expect(inputProvider.getTimeEntry('wokeUpAt'),equals(const TimeOfDay(hour: 8, minute: 0)));
expect(inputProvider.getTimeEntry('sleptAt'),equals(const TimeOfDay(hour: 22, minute: 0)));
});
test('Setters work right way', () {
late final inputProvider = InputProvider();
inputProvider.sliderValue = 75;
expect(inputProvider.sliderValue, equals(75));
inputProvider.textController.text = 'Test';
expect(inputProvider.textController.text, equals('Test'));
inputProvider.relapseCategory = 'Test';
expect(inputProvider.relapseCategory, equals('Test'));
inputProvider.setTime('wokeUpAt', const TimeOfDay(hour: 7, minute: 0));
expect(inputProvider.getTimeEntry('wokeUpAt'),equals(const TimeOfDay(hour: 7, minute: 0)));
inputProvider.setTime('sleptAt', const TimeOfDay(hour: 23, minute: 0));
expect(inputProvider.getTimeEntry('sleptAt'), equals(const TimeOfDay(hour: 23, minute: 0)));
});
test('Reset Fields should reset all fields correctly', () async{
final inputProvider = InputProvider();
inputProvider.sliderValue = 44;
inputProvider.textController.text = 'Test';
inputProvider.setTime('wokeUpAt', const TimeOfDay(hour: 7, minute: 0));
inputProvider.setTime('sleptAt', const TimeOfDay(hour: 23, minute: 0));
final result = await inputProvider.saveMood(); // calls private function ResetFields
expect(result, equals(1));
expect(inputProvider.sliderValue, equals(50));
expect(inputProvider.textController.text, equals(''));
expect(inputProvider.getTimeEntry('wokeUpAt'),equals(const TimeOfDay(hour: 8, minute: 0)));
expect(inputProvider.getTimeEntry('sleptAt'), equals(const TimeOfDay(hour: 22, minute: 0)));
});
test('Save Mood ', () async {
late final inputProvider = InputProvider();
final result = await inputProvider.saveMood();
expect(result, equals(1));
expect(inputProvider.sliderValue, equals(50));
expect(inputProvider.textController.text, equals(''));
});
test('Save Relapse', () async {
late final inputProvider = InputProvider();
final result = await inputProvider.saveRelapse();
expect(result, equals(1));
expect(inputProvider.relapseCategory, equals(''));
expect(inputProvider.textController.text, equals(''));
});
test('Save Sleep', () async {
late final inputProvider = InputProvider();
final result = await inputProvider.saveSleep('wokeUpAt', 'sleptAt');
expect(result, equals(1));
expect(inputProvider.sliderValue, equals(50));
expect(inputProvider.textController.text, equals(''));
expect(inputProvider.getTimeEntry('wokeUpAt'),equals(const TimeOfDay(hour: 8, minute: 0)));
expect(inputProvider.getTimeEntry('sleptAt'),equals(const TimeOfDay(hour: 22, minute: 0)));
});
});
}