mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Add simple widget test for gym mode screen
This commit is contained in:
@@ -28,7 +28,7 @@ class RepetitionUnit {
|
||||
@JsonKey(required: true)
|
||||
final String name;
|
||||
|
||||
RepetitionUnit({
|
||||
const RepetitionUnit({
|
||||
required this.id,
|
||||
required this.name,
|
||||
});
|
||||
|
||||
@@ -28,7 +28,7 @@ class WeightUnit {
|
||||
@JsonKey(required: true)
|
||||
final String name;
|
||||
|
||||
WeightUnit({
|
||||
const WeightUnit({
|
||||
required this.id,
|
||||
required this.name,
|
||||
});
|
||||
|
||||
140
test/gym_mode_screen_test.dart
Normal file
140
test/gym_mode_screen_test.dart
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* Copyright (C) 2020, 2021 wger Team
|
||||
*
|
||||
* wger Workout Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wger Workout Manager is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/models/workouts/workout_plan.dart';
|
||||
import 'package:wger/providers/workout_plans.dart';
|
||||
import 'package:wger/screens/gym_mode.dart';
|
||||
import 'package:wger/screens/workout_plan_screen.dart';
|
||||
import 'package:wger/widgets/workouts/gym_mode.dart';
|
||||
|
||||
import '../test_data/workouts.dart';
|
||||
import 'base_provider_test.mocks.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
void main() {
|
||||
Widget createHomeScreen({locale = 'en'}) {
|
||||
final key = GlobalKey<NavigatorState>();
|
||||
final client = MockClient();
|
||||
|
||||
WorkoutPlan workoutPlan = getWorkout();
|
||||
|
||||
return ChangeNotifierProvider<WorkoutPlans>(
|
||||
create: (context) => WorkoutPlans(
|
||||
testAuthProvider,
|
||||
testExercisesProvider,
|
||||
[workoutPlan],
|
||||
client,
|
||||
),
|
||||
child: ChangeNotifierProvider(
|
||||
create: (context) => testExercisesProvider,
|
||||
child: MaterialApp(
|
||||
locale: Locale(locale),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
navigatorKey: key,
|
||||
home: TextButton(
|
||||
onPressed: () => key.currentState!.push(
|
||||
MaterialPageRoute<void>(
|
||||
settings: RouteSettings(arguments: workoutPlan.days.first),
|
||||
builder: (_) => GymModeScreen(),
|
||||
),
|
||||
),
|
||||
child: const SizedBox(),
|
||||
),
|
||||
routes: {
|
||||
WorkoutPlanScreen.routeName: (ctx) => WorkoutPlanScreen(),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('Test the widgets on the gym mode screen', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createHomeScreen());
|
||||
await tester.tap(find.byType(TextButton));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Start page
|
||||
expect(find.byType(StartPage), findsOneWidget);
|
||||
expect(find.text('Your workout today'), findsOneWidget);
|
||||
expect(find.text('test exercise 1'), findsOneWidget);
|
||||
expect(find.byIcon(Icons.chevron_left), findsNothing);
|
||||
expect(find.byIcon(Icons.exit_to_app), findsOneWidget);
|
||||
expect(find.byIcon(Icons.chevron_right), findsOneWidget);
|
||||
await tester.tap(find.byIcon(Icons.chevron_right));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Exercise overview page
|
||||
expect(find.text('test exercise 1'), findsOneWidget);
|
||||
expect(find.byType(ExerciseOverview), findsOneWidget);
|
||||
expect(find.byIcon(Icons.chevron_left), findsOneWidget);
|
||||
expect(find.byIcon(Icons.exit_to_app), findsOneWidget);
|
||||
expect(find.byIcon(Icons.chevron_right), findsOneWidget);
|
||||
await tester.drag(find.byType(ExerciseOverview), Offset(-500.0, 0.0));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Log
|
||||
expect(find.text('test exercise 1'), findsOneWidget);
|
||||
expect(find.byType(LogPage), findsOneWidget);
|
||||
expect(find.byType(Form), findsOneWidget);
|
||||
expect(find.byIcon(Icons.chevron_left), findsOneWidget);
|
||||
expect(find.byIcon(Icons.exit_to_app), findsOneWidget);
|
||||
expect(find.byIcon(Icons.chevron_right), findsOneWidget);
|
||||
await tester.drag(find.byType(LogPage), Offset(-500.0, 0.0));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Pause
|
||||
expect(find.text('0:00'), findsOneWidget);
|
||||
expect(find.byType(TimerWidget), findsOneWidget);
|
||||
expect(find.byIcon(Icons.chevron_left), findsOneWidget);
|
||||
expect(find.byIcon(Icons.exit_to_app), findsOneWidget);
|
||||
expect(find.byIcon(Icons.chevron_right), findsOneWidget);
|
||||
await tester.tap(find.byIcon(Icons.chevron_right));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Log
|
||||
expect(find.text('test exercise 1'), findsOneWidget);
|
||||
expect(find.byType(LogPage), findsOneWidget);
|
||||
expect(find.byType(Form), findsOneWidget);
|
||||
await tester.drag(find.byType(LogPage), Offset(-500.0, 0.0));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Pause
|
||||
expect(find.text('0:00'), findsOneWidget);
|
||||
expect(find.byType(TimerWidget), findsOneWidget);
|
||||
expect(find.byIcon(Icons.chevron_left), findsOneWidget);
|
||||
expect(find.byIcon(Icons.exit_to_app), findsOneWidget);
|
||||
expect(find.byIcon(Icons.chevron_right), findsOneWidget);
|
||||
await tester.tap(find.byIcon(Icons.chevron_right));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Session
|
||||
expect(find.text('Workout session'), findsOneWidget);
|
||||
expect(find.byType(SessionPage), findsOneWidget);
|
||||
expect(find.byType(Form), findsOneWidget);
|
||||
expect(find.byIcon(Icons.chevron_left), findsOneWidget);
|
||||
expect(find.byIcon(Icons.exit_to_app), findsOneWidget);
|
||||
expect(find.byIcon(Icons.chevron_right), findsNothing);
|
||||
|
||||
//
|
||||
});
|
||||
}
|
||||
@@ -19,10 +19,12 @@
|
||||
import 'package:wger/providers/auth.dart';
|
||||
import 'package:wger/providers/exercises.dart';
|
||||
|
||||
import '../test_data/exercises.dart';
|
||||
|
||||
// Test Auth provider
|
||||
final Auth testAuthProvider = Auth()
|
||||
..token = 'FooBar'
|
||||
..serverUrl = 'https://localhost';
|
||||
|
||||
// Test Exercises provider
|
||||
final Exercises testExercisesProvider = Exercises(testAuthProvider, []);
|
||||
final Exercises testExercisesProvider = Exercises(testAuthProvider, [exercise1, exercise2]);
|
||||
|
||||
57
test_data/exercises.dart
Normal file
57
test_data/exercises.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* Copyright (C) 2020, 2021 wger Team
|
||||
*
|
||||
* wger Workout Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wger Workout Manager is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:wger/models/exercises/category.dart';
|
||||
import 'package:wger/models/exercises/equipment.dart';
|
||||
import 'package:wger/models/exercises/exercise.dart';
|
||||
import 'package:wger/models/exercises/muscle.dart';
|
||||
|
||||
const muscle1 = Muscle(id: 1, name: 'Flutterus maximus', isFront: true);
|
||||
const muscle2 = Muscle(id: 2, name: 'Biceps', isFront: true);
|
||||
|
||||
const category1 = ExerciseCategory(id: 1, name: 'Arms');
|
||||
const category2 = ExerciseCategory(id: 2, name: 'Legs');
|
||||
const category3 = ExerciseCategory(id: 3, name: 'Abs');
|
||||
|
||||
const equipment1 = Equipment(id: 1, name: 'Bench');
|
||||
const equipment2 = Equipment(id: 1, name: 'Dumbbell');
|
||||
|
||||
final exercise1 = Exercise(
|
||||
id: 1,
|
||||
uuid: 'uuid',
|
||||
creationDate: DateTime(2021, 1, 15),
|
||||
name: 'test exercise 1',
|
||||
description: 'add clever text',
|
||||
categoryId: 1,
|
||||
muscles: [muscle1, muscle2],
|
||||
equipment: [equipment1, equipment2],
|
||||
category: category1,
|
||||
);
|
||||
|
||||
final exercise2 = Exercise(
|
||||
id: 2,
|
||||
uuid: '111-2222-44444',
|
||||
creationDate: DateTime(2021, 1, 15),
|
||||
name: 'test exercise 2',
|
||||
description: 'Lorem ipsum etc',
|
||||
categoryId: 2,
|
||||
muscles: [muscle1],
|
||||
musclesSecondary: [muscle2],
|
||||
equipment: [equipment2],
|
||||
category: category2,
|
||||
);
|
||||
79
test_data/workouts.dart
Normal file
79
test_data/workouts.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* Copyright (C) 2020, 2021 wger Team
|
||||
*
|
||||
* wger Workout Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wger Workout Manager is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:wger/models/workouts/day.dart';
|
||||
import 'package:wger/models/workouts/repetition_unit.dart';
|
||||
import 'package:wger/models/workouts/set.dart';
|
||||
import 'package:wger/models/workouts/setting.dart';
|
||||
import 'package:wger/models/workouts/weight_unit.dart';
|
||||
import 'package:wger/models/workouts/workout_plan.dart';
|
||||
|
||||
import './exercises.dart';
|
||||
|
||||
const weightUnit1 = WeightUnit(id: 1, name: 'kg');
|
||||
const weightUnit2 = WeightUnit(id: 2, name: 'metric tonnes');
|
||||
|
||||
const RepetitionUnit repetitionUnit1 = RepetitionUnit(id: 1, name: 'Repetitions');
|
||||
const RepetitionUnit repetitionUnit2 = RepetitionUnit(id: 2, name: 'Hours');
|
||||
|
||||
WorkoutPlan getWorkout() {
|
||||
var setting1 = Setting(
|
||||
setId: 1,
|
||||
order: 1,
|
||||
exerciseId: 1,
|
||||
repetitionUnitId: 1,
|
||||
reps: 2,
|
||||
weightUnitId: 1,
|
||||
comment: 'ddd',
|
||||
rir: '2',
|
||||
);
|
||||
setting1.repetitionUnit = repetitionUnit1;
|
||||
setting1.weightUnit = weightUnit1;
|
||||
setting1.exercise = exercise1;
|
||||
|
||||
var set1 = Set.withData(
|
||||
id: 1,
|
||||
day: 1,
|
||||
sets: 3,
|
||||
order: 1,
|
||||
);
|
||||
set1.settings.add(setting1);
|
||||
set1.settingsComputed = [setting1, setting1];
|
||||
|
||||
var day1 = Day()
|
||||
..id = 1
|
||||
..workoutId = 1
|
||||
..description = 'test day 1'
|
||||
..daysOfWeek = [1, 2];
|
||||
day1.sets.add(set1);
|
||||
|
||||
var day2 = Day()
|
||||
..id = 2
|
||||
..workoutId = 1
|
||||
..description = 'test day 2'
|
||||
..daysOfWeek = [4];
|
||||
|
||||
var workout = WorkoutPlan(
|
||||
id: 1,
|
||||
creationDate: DateTime(2021, 01, 01),
|
||||
description: 'test workout 1',
|
||||
days: [day1, day2],
|
||||
);
|
||||
|
||||
return workout;
|
||||
}
|
||||
Reference in New Issue
Block a user