cpd_2022_zi/test/unit_tests/workout_provider_test.dart

83 lines
2.9 KiB
Dart
Raw Normal View History

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';
2023-03-06 22:15:29 +01:00
import 'package:smoke_cess_app/globals.dart' as globals;
import '../mock/audio_provider_mock.dart';
2023-03-06 22:15:29 +01:00
import '../mock/db_mock.dart';
void main() {
2023-03-06 21:54:32 +01:00
WidgetsFlutterBinding.ensureInitialized();
2023-03-06 22:15:29 +01:00
globals.databaseService = DatabaseMock();
group('WorkoutProvider', () {
late WorkoutProvider workoutProvider;
late TimerProvider timerProvider;
late AudioProvider audioProvider;
setUp(() {
timerProvider = TimerProvider();
audioProvider = AudioProviderMock();
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);
2023-03-07 00:06:07 +01:00
expect(workoutProvider.currentPhaseDuration, const Duration(minutes: 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);
2023-03-07 00:06:07 +01:00
expect(workoutProvider.currentPhaseDuration, const Duration(minutes: 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);
2023-03-07 00:06:07 +01:00
expect(workoutProvider.currentPhaseDuration, const Duration(minutes: 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);
});
2023-03-06 22:15:29 +01:00
test('save workout', () async {
workoutProvider.motivationBefore = 70;
workoutProvider.motivationAfter = 80;
workoutProvider.saveWorkout();
2023-03-06 22:15:29 +01:00
final result = await globals.databaseService.getWorkoutRecords();
expect(result.length, 1);
});
});
}