98 lines
3.6 KiB
Dart
98 lines
3.6 KiB
Dart
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(SleepTimes.wokeUpAt),
|
|
equals(const TimeOfDay(hour: 8, minute: 0)));
|
|
expect(inputProvider.getTimeEntry(SleepTimes.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(
|
|
SleepTimes.wokeUpAt, const TimeOfDay(hour: 7, minute: 0));
|
|
expect(inputProvider.getTimeEntry(SleepTimes.wokeUpAt),
|
|
equals(const TimeOfDay(hour: 7, minute: 0)));
|
|
|
|
inputProvider.setTime(
|
|
SleepTimes.sleptAt, const TimeOfDay(hour: 23, minute: 0));
|
|
expect(inputProvider.getTimeEntry(SleepTimes.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(
|
|
SleepTimes.wokeUpAt, const TimeOfDay(hour: 7, minute: 0));
|
|
inputProvider.setTime(
|
|
SleepTimes.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(SleepTimes.wokeUpAt),
|
|
equals(const TimeOfDay(hour: 8, minute: 0)));
|
|
expect(inputProvider.getTimeEntry(SleepTimes.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(
|
|
SleepTimes.wokeUpAt, SleepTimes.sleptAt);
|
|
|
|
expect(result, equals(1));
|
|
expect(inputProvider.sliderValue, equals(50));
|
|
expect(inputProvider.textController.text, equals(''));
|
|
expect(inputProvider.getTimeEntry(SleepTimes.wokeUpAt),
|
|
equals(const TimeOfDay(hour: 8, minute: 0)));
|
|
expect(inputProvider.getTimeEntry(SleepTimes.sleptAt),
|
|
equals(const TimeOfDay(hour: 22, minute: 0)));
|
|
});
|
|
});
|
|
}
|