2023-03-06 20:38:53 +01:00
|
|
|
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;
|
2023-03-06 23:06:33 +01:00
|
|
|
import '../mock/audio_provider_mock.dart';
|
2023-03-06 22:15:29 +01:00
|
|
|
import '../mock/db_mock.dart';
|
2023-03-06 20:38:53 +01:00
|
|
|
|
|
|
|
void main() {
|
2023-03-06 21:54:32 +01:00
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
2023-03-06 22:15:29 +01:00
|
|
|
globals.databaseService = DatabaseMock();
|
2023-03-06 20:38:53 +01:00
|
|
|
group('WorkoutProvider', () {
|
|
|
|
late WorkoutProvider workoutProvider;
|
|
|
|
late TimerProvider timerProvider;
|
|
|
|
late AudioProvider audioProvider;
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
timerProvider = TimerProvider();
|
2023-03-06 23:06:33 +01:00
|
|
|
audioProvider = AudioProviderMock();
|
2023-03-06 20:38:53 +01:00
|
|
|
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));
|
2023-03-06 20:38:53 +01:00
|
|
|
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));
|
2023-03-06 20:38:53 +01:00
|
|
|
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));
|
2023-03-06 20:38:53 +01:00
|
|
|
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 20:38:53 +01:00
|
|
|
|
2023-03-06 22:15:29 +01:00
|
|
|
final result = await globals.databaseService.getWorkoutRecords();
|
|
|
|
|
|
|
|
expect(result.length, 1);
|
|
|
|
});
|
2023-03-06 20:38:53 +01:00
|
|
|
});
|
|
|
|
}
|