Skip to content

Commit

Permalink
Merge pull request #140 from a-mabe/full-workout-test
Browse files Browse the repository at this point in the history
Full workout test
  • Loading branch information
a-mabe authored Feb 21, 2024
2 parents ee12845 + a863ee6 commit 17b311c
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 66 deletions.
27 changes: 2 additions & 25 deletions lib/create_workout/create_timer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,6 @@ class CreateTimerState extends State<CreateTimer> {
/// from the previous view.
Workout workout = ModalRoute.of(context)!.settings.arguments as Workout;

Workout workoutCopy = Workout(
workout.id,
workout.title,
workout.numExercises,
workout.exercises,
workout.getReadyTime,
workout.workTime,
workout.restTime,
workout.halfTime,
workout.breakTime,
workout.warmupTime,
workout.cooldownTime,
workout.iterations,
workout.halfwayMark,
workout.workSound,
workout.restSound,
workout.halfwaySound,
workout.completeSound,
workout.countdownSound,
workout.colorInt,
workout.workoutIndex,
workout.showMinutes);

// Create a global key that uniquely identifies the Form widget
// and allows validation of the form.
//
Expand Down Expand Up @@ -85,9 +62,9 @@ class CreateTimerState extends State<CreateTimer> {
text: "Submit",
color: const Color.fromARGB(255, 58, 165, 255),
onTap: () {
submitForm(workoutCopy);
submitForm(workout);
},
),
body: CreateForm(workout: workoutCopy, formKey: formKey));
body: CreateForm(workout: workout, formKey: formKey));
}
}
36 changes: 11 additions & 25 deletions lib/create_workout/create_workout.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'package:openhiit/create_workout/main_widgets/create_form.dart';
import '../workout_data_type/workout_type.dart';
import 'main_widgets/submit_button.dart';
import 'set_exercises.dart';

var logger = Logger(
printer: PrettyPrinter(methodCount: 0),
);

class CreateWorkout extends StatefulWidget {
const CreateWorkout({super.key});

Expand All @@ -19,29 +24,6 @@ class CreateWorkoutState extends State<CreateWorkout> {
///
Workout workout = ModalRoute.of(context)!.settings.arguments as Workout;

Workout workoutCopy = Workout(
workout.id,
workout.title,
workout.numExercises,
workout.exercises,
workout.getReadyTime,
workout.workTime,
workout.restTime,
workout.halfTime,
workout.breakTime,
workout.warmupTime,
workout.cooldownTime,
workout.iterations,
workout.halfwayMark,
workout.workSound,
workout.restSound,
workout.halfwaySound,
workout.completeSound,
workout.countdownSound,
workout.colorInt,
workout.workoutIndex,
workout.showMinutes);

/// Create a global key that uniquely identifies the Form widget
/// and allows validation of the form.
///
Expand Down Expand Up @@ -72,6 +54,10 @@ class CreateWorkoutState extends State<CreateWorkout> {
final form = formKey.currentState!;
if (form.validate()) {
form.save();

logger.i(
"Title: ${workout.title}, Color: ${workout.colorInt}, Intervals: ${workout.numExercises}");

pushExercises(workout);
}
}
Expand All @@ -85,9 +71,9 @@ class CreateWorkoutState extends State<CreateWorkout> {
text: "Submit",
color: Colors.blue,
onTap: () {
submitForm(workoutCopy);
submitForm(workout);
},
),
body: CreateForm(workout: workoutCopy, formKey: formKey));
body: CreateForm(workout: workout, formKey: formKey));
}
}
9 changes: 8 additions & 1 deletion lib/create_workout/main_widgets/create_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class CreateFormState extends State<CreateForm> {
onSaved: (String? val) {
widget.workout.title = val!;
},
onChanged: (String? val) {
widget.workout.title = val!;
},
style: const TextStyle(fontSize: 18),
),

Expand Down Expand Up @@ -169,7 +172,11 @@ class CreateFormState extends State<CreateForm> {
onSaved: (String? val) {
widget.workout.numExercises = int.parse(val!);
},
onChanged: (text) {},
onChanged: (String? val) {
if (val!.isNotEmpty) {
widget.workout.numExercises = int.parse(val);
}
},
unit: "intervals",
min: 1,
max: 999),
Expand Down
2 changes: 1 addition & 1 deletion lib/create_workout/select_timer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SelectTimerState extends State<SelectTimer> {
///
TimerOptionCard(
onTap: () {
pushCreateWorkout(workout, context);
pushCreateWorkout(workout, context, (value) {});
},
optionIcon: Icons.fitness_center,
optionTitle: "Workout",
Expand Down
7 changes: 7 additions & 0 deletions lib/create_workout/set_exercises.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'dart:convert';
import '../workout_data_type/workout_type.dart';
import './set_timings.dart';
import 'main_widgets/submit_button.dart';

var logger = Logger(
printer: PrettyPrinter(methodCount: 0),
);

class SetExercises extends StatefulWidget {
const SetExercises({super.key});

Expand Down Expand Up @@ -64,6 +69,8 @@ class _SetExercisesState extends State<SetExercises> {
/// Generate the list of TextFormFields based off of the number of exercises.
///
List<Widget> generateTextFormFields(Workout workout) {
logger.i("Generating ${workout.numExercises} TextFormFields");

return List<Widget>.generate(workout.numExercises, (int index) {
return Padding(
padding: const EdgeInsets.fromLTRB(40.0, 15.0, 40.0, 15.0),
Expand Down
4 changes: 2 additions & 2 deletions lib/create_workout/set_sounds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class _SetSoundsState extends State<SetSounds> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SoundDropdown(
dropdownKey: Key("work-sound"),
dropdownKey: const Key("work-sound"),
title: "Work Sound",
initialSelection: workout.workSound,
pool: pool,
Expand All @@ -138,7 +138,7 @@ class _SetSoundsState extends State<SetSounds> {
});
}),
SoundDropdown(
dropdownKey: Key("rest-sound"),
dropdownKey: const Key("rest-sound"),
title: "Rest Sound",
initialSelection: workout.restSound,
pool: pool,
Expand Down
12 changes: 10 additions & 2 deletions lib/start_workout/view_workout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,18 @@ class ViewWorkoutState extends State<ViewWorkout> {
Navigator.of(context).pop();
},
onEdit: () {
Workout workoutCopy = workout.copy();

if (exercises.isEmpty) {
pushCreateTimer(workout, context);
pushCreateTimer(workoutCopy, context);
} else {
pushCreateWorkout(workout, context);
pushCreateWorkout(workoutCopy, context, (value) {
/// When we come back, reload the workout arg.
///
setState(() {
workout = ModalRoute.of(context)!.settings.arguments as Workout;
});
});
}
},
onCopy: () async {
Expand Down
8 changes: 6 additions & 2 deletions lib/utils/functions.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

Expand All @@ -13,7 +15,9 @@ import '../workout_data_type/workout_type.dart';
/// - [workout]: The 'Workout' object to be passed to the 'CreateWorkout' screen.
/// - [context]: The BuildContext required for navigation within the Flutter app.
///
void pushCreateWorkout(Workout workout, BuildContext context) {
void pushCreateWorkout(Workout workout, BuildContext context,
FutureOr<dynamic> Function(dynamic) then) {
Navigator.push(
context,
MaterialPageRoute(
Expand All @@ -22,7 +26,7 @@ void pushCreateWorkout(Workout workout, BuildContext context) {
arguments: workout,
),
),
);
).then(then);
}

/// Navigates to the 'CreateTimer' screen while passing the provided 'Workout' object
Expand Down
26 changes: 26 additions & 0 deletions lib/workout_data_type/workout_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,32 @@ class Workout {
};
}

Workout copy() {
return Workout(
id,
title,
numExercises,
exercises,
getReadyTime,
workTime,
restTime,
halfTime,
breakTime,
warmupTime,
cooldownTime,
iterations,
halfwayMark,
workSound,
restSound,
halfwaySound,
completeSound,
countdownSound,
colorInt,
workoutIndex,
showMinutes,
);
}

/// Implement toString to print information about
/// each Workout more easily.
///
Expand Down
12 changes: 8 additions & 4 deletions test/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import 'package:flutter_test/flutter_test.dart';
Future<void> selectSound(WidgetTester tester, Key key, String soundName) async {
await tester.tap(find.byKey(key));
await tester.pump(const Duration(seconds: 1));
await tester.tap(find.descendant(
of: find.byKey(key),
matching: find.text(soundName),
));
await tester.tap(find
.descendant(
of: find.byKey(key),
matching: find.text(soundName),
)
.last);
await tester.pumpAndSettle();
}

Expand Down Expand Up @@ -43,6 +45,7 @@ Future<void> createOrEditWorkout(
// Submit the form
await tester.tap(find.text(
'Submit')); // Replace 'Submit' with the actual text of your submit button
await tester.pump(const Duration(seconds: 1));
await tester.pumpAndSettle();

///
Expand All @@ -62,6 +65,7 @@ Future<void> createOrEditWorkout(
await tester.tap(find.text('Submit'));

// Wait for the navigation to complete
await tester.pump(const Duration(seconds: 1));
await tester.pumpAndSettle();
}

Expand Down
4 changes: 2 additions & 2 deletions test/interval_timer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void main() {
3,
false,
false,
"Long whistle",
"Harsh beep sequence",
"Ding",
"Quick beep sequence",
"Beep",
Expand All @@ -75,7 +75,7 @@ void main() {
await tester.pump(const Duration(seconds: 1)); // skip past the animation

await createOrEditWorkout(tester, timerName, 2, false, false, "Ding",
"Long whistle", "Horn", "None", "Quick beep sequence", "90", "20");
"Thunk", "Horn", "None", "Quick beep sequence", "90", "20");

// Tap the workout to view details
await tester.tap(find.text(timerName));
Expand Down
4 changes: 2 additions & 2 deletions test/workout_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void main() {
3,
true,
true,
"Long whistle",
"Harsh beep sequence",
"Ding",
"Quick beep sequence",
"Beep",
Expand All @@ -75,7 +75,7 @@ void main() {
await tester.pump(const Duration(seconds: 1)); // skip past the animation

await createOrEditWorkout(tester, workoutName, 2, false, true, "Ding",
"Long whistle", "Horn", "None", "Quick beep sequence", "90", "20");
"Thunk", "Horn", "None", "Quick beep sequence", "90", "20");

// Tap the workout to view details
await tester.tap(find.text(workoutName));
Expand Down

0 comments on commit 17b311c

Please sign in to comment.