create workout & settings Provider and date service tests
parent
a9480cc508
commit
d6a45e8974
|
@ -0,0 +1,118 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:smoke_cess_app/services/date_service.dart';
|
||||
import 'package:smoke_cess_app/services/pages_service.dart';
|
||||
import 'package:timezone/data/latest.dart' as tz;
|
||||
import 'package:timezone/timezone.dart';
|
||||
|
||||
void main() {
|
||||
group('Helpers', () {
|
||||
group('isSameDay', () {
|
||||
test('returns true when dates are the same day', () {
|
||||
DateTime dateA = DateTime.now();
|
||||
DateTime dateB = DateTime(dateA.year, dateA.month, dateA.day, 10, 0);
|
||||
expect(isSameDay(dateA, dateB), true);
|
||||
});
|
||||
|
||||
test('returns false when dates are different days', () {
|
||||
DateTime dateA = DateTime.now();
|
||||
DateTime dateB = DateTime(dateA.year, dateA.month, dateA.day + 1, 10, 0);
|
||||
expect(isSameDay(dateA, dateB), false);
|
||||
});
|
||||
|
||||
test('returns false when one date is null', () {
|
||||
DateTime? dateA = DateTime.now();
|
||||
DateTime? dateB;
|
||||
expect(isSameDay(dateA, dateB), false);
|
||||
});
|
||||
});
|
||||
|
||||
group('createTZDateTimes', () {
|
||||
test('returns empty list when selectedDays is null', () {
|
||||
List<TZDateTime> tzDateTimes =
|
||||
createTZDateTimes(null, 10, 0);
|
||||
expect(tzDateTimes, []);
|
||||
});
|
||||
|
||||
test('returns empty list when selectedHours is null', () {
|
||||
List<TZDateTime> tzDateTimes =
|
||||
createTZDateTimes(['Montag'], null, 0);
|
||||
expect(tzDateTimes, []);
|
||||
});
|
||||
|
||||
test('returns empty list when selectedMinutes is null', () {
|
||||
List<TZDateTime> tzDateTimes =
|
||||
createTZDateTimes(['Montag'], 10, null);
|
||||
expect(tzDateTimes, []);
|
||||
});
|
||||
|
||||
test('returns empty list when no valid dates are found', () {
|
||||
List<TZDateTime> tzDateTimes =
|
||||
createTZDateTimes(['Montag'], 10, 0);
|
||||
expect(tzDateTimes, []);
|
||||
});
|
||||
|
||||
test('returns list of valid dates', () {
|
||||
List<TZDateTime> tzDateTimes =
|
||||
createTZDateTimes(['Montag'], 10, 0);
|
||||
expect(tzDateTimes.length, greaterThan(0));
|
||||
});
|
||||
});
|
||||
|
||||
group('getTimeTill', () {
|
||||
test('returns time till next mood', () async {
|
||||
Duration duration = await getTimeTill(Pages.mood);
|
||||
expect(duration, isNotNull);
|
||||
});
|
||||
|
||||
test('returns time till next sleep', () async {
|
||||
Duration duration = await getTimeTill(Pages.sleep);
|
||||
expect(duration, isNotNull);
|
||||
});
|
||||
//?
|
||||
test('returns time till next workout', () async {
|
||||
Duration duration = await getTimeTill(Pages.relapse);
|
||||
expect(duration, isNotNull);
|
||||
});
|
||||
//?
|
||||
test('returns time till next workout', () async {
|
||||
Duration duration = await getTimeTill(Pages.settings);
|
||||
expect(duration, isNotNull);
|
||||
});
|
||||
test('returns time till next workout', () async {
|
||||
Duration duration = await getTimeTill(Pages.timer);
|
||||
expect(duration, isNotNull);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
group('Helper functions', () {
|
||||
setUp(() async {
|
||||
tz.initializeTimeZones();
|
||||
});
|
||||
|
||||
test('isSameDay returns true if two dates are the same day', () {
|
||||
final date1 = DateTime(2022, 3, 6);
|
||||
final date2 = DateTime(2022, 3, 6, 15, 30);
|
||||
final result = isSameDay(date1, date2);
|
||||
expect(result, true);
|
||||
});
|
||||
|
||||
test('isSameDay returns false if two dates are not the same day', () {
|
||||
final date1 = DateTime(2022, 3, 6);
|
||||
final date2 = DateTime(2022, 3, 7);
|
||||
final result = isSameDay(date1, date2);
|
||||
expect(result, false);
|
||||
});
|
||||
|
||||
test('createTZDateTimes returns a list of TZDateTime objects', () async {
|
||||
final selectedDays = ['Montag', 'Dienstag'];
|
||||
final selectedHours = 12;
|
||||
final selectedMinutes = 30;
|
||||
final result = await createTZDateTimes(
|
||||
selectedDays, selectedHours, selectedMinutes);
|
||||
expect(result, isA<List<TZDateTime>>());
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:smoke_cess_app/providers/settings_provider.dart';
|
||||
|
||||
void main() {
|
||||
group('SettingsProvider', () {
|
||||
test('initial state', () {
|
||||
final provider = SettingsProvider();
|
||||
expect(provider.settings, isNull);
|
||||
expect(provider.initialized, isFalse);
|
||||
expect(provider.scanning, isFalse);
|
||||
});
|
||||
|
||||
test('initialize settings', () async {
|
||||
final provider = SettingsProvider();
|
||||
provider.initSettings();
|
||||
expect(provider.settings, isNotNull);
|
||||
expect(provider.initialized, isTrue);
|
||||
});
|
||||
|
||||
test('set scanning', () {
|
||||
final provider = SettingsProvider();
|
||||
provider.scanning = true;
|
||||
expect(provider.scanning, isTrue);
|
||||
provider.scanning = false;
|
||||
expect(provider.scanning, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:smoke_cess_app/providers/audio_provider.dart';
|
||||
import 'package:smoke_cess_app/providers/timer_provider.dart';
|
||||
import 'package:smoke_cess_app/providers/workout_provider.dart';
|
||||
|
||||
void main() {
|
||||
group('WorkoutProvider', () {
|
||||
late WorkoutProvider workoutProvider;
|
||||
late TimerProvider timerProvider;
|
||||
late AudioProvider audioProvider;
|
||||
|
||||
setUp(() {
|
||||
timerProvider = TimerProvider();
|
||||
audioProvider = AudioProvider();
|
||||
workoutProvider = WorkoutProvider(timerProvider, audioProvider);
|
||||
});
|
||||
|
||||
test('initial values', () {
|
||||
expect(workoutProvider.isWorkoutStarted, false);
|
||||
expect(workoutProvider.isWorkoutComplete, false);
|
||||
expect(workoutProvider.motivationBefore, 50);
|
||||
expect(workoutProvider.motivationAfter, 50);
|
||||
expect(workoutProvider.currentPhase, WorkoutPhases.warmUp);
|
||||
expect(workoutProvider.currentPhaseDuration, const Duration(seconds: 5));
|
||||
expect(workoutProvider.isPhaseComplete, false);
|
||||
expect(workoutProvider.currentPhaseColor, Colors.green);
|
||||
expect(workoutProvider.currentPhaseTitle, 'Warm Up');
|
||||
});
|
||||
|
||||
test('next phase', () {
|
||||
workoutProvider.nextPhase();
|
||||
|
||||
expect(workoutProvider.currentPhase, WorkoutPhases.highIntensity);
|
||||
expect(workoutProvider.currentPhaseDuration, const Duration(seconds: 4));
|
||||
expect(workoutProvider.isPhaseComplete, false);
|
||||
expect(workoutProvider.currentPhaseColor, Colors.red);
|
||||
expect(workoutProvider.currentPhaseTitle, 'High Intensity');
|
||||
});
|
||||
|
||||
test('start workout', () {
|
||||
workoutProvider.startWorkout();
|
||||
|
||||
expect(workoutProvider.isWorkoutStarted, true);
|
||||
expect(workoutProvider.isWorkoutComplete, false);
|
||||
expect(workoutProvider.currentPhase, WorkoutPhases.warmUp);
|
||||
expect(workoutProvider.currentPhaseDuration, const Duration(seconds: 5));
|
||||
expect(workoutProvider.isPhaseComplete, false);
|
||||
});
|
||||
|
||||
test('stop workout', () {
|
||||
workoutProvider.startWorkout();
|
||||
workoutProvider.stopWorkout();
|
||||
|
||||
expect(workoutProvider.isWorkoutStarted, false);
|
||||
expect(workoutProvider.isWorkoutComplete, true);
|
||||
});
|
||||
|
||||
test('interrupt workout', () {
|
||||
workoutProvider.startWorkout();
|
||||
workoutProvider.interruptWorkout();
|
||||
|
||||
expect(workoutProvider.isWorkoutStarted, false);
|
||||
expect(workoutProvider.isWorkoutComplete, false);
|
||||
});
|
||||
|
||||
// test('save workout', () {
|
||||
// workoutProvider.motivationBefore = 70;
|
||||
// workoutProvider.motivationAfter = 80;
|
||||
// workoutProvider.saveWorkout();
|
||||
|
||||
// // -> hier in datenbank nachschauen obs geklappt hat
|
||||
// });
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue