From 0c3318d45ee1dbb3564b0bb235f4d66868408f5b Mon Sep 17 00:00:00 2001 From: Bujdy Date: Sat, 12 Nov 2022 10:53:53 +0100 Subject: [PATCH 1/3] submit login after pressing enter --- lib/screens/auth_screen.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/screens/auth_screen.dart b/lib/screens/auth_screen.dart index 79b8e5619..8050d8506 100644 --- a/lib/screens/auth_screen.dart +++ b/lib/screens/auth_screen.dart @@ -259,6 +259,9 @@ class _AuthCardState extends State { } return null; }, + onFieldSubmitted: (value){ + _submit(context); + }, onSaved: (value) { _authData['password'] = value!; }, From d606f596c34646ed5e8fbd65de0b88becd99b0ab Mon Sep 17 00:00:00 2001 From: Bujdy Date: Sat, 12 Nov 2022 17:38:52 +0100 Subject: [PATCH 2/3] added workout and gallery provider tests --- lib/providers/gallery.dart | 2 +- lib/providers/workout_plans.dart | 6 + test/gallery/gallery_provider_test.dart | 82 +++++++++++ test/workout/workout_provider_test.dart | 185 ++++++++++++++++++++++++ 4 files changed, 274 insertions(+), 1 deletion(-) create mode 100644 test/gallery/gallery_provider_test.dart create mode 100644 test/workout/workout_provider_test.dart diff --git a/lib/providers/gallery.dart b/lib/providers/gallery.dart index d15bf32dc..15dc4090f 100644 --- a/lib/providers/gallery.dart +++ b/lib/providers/gallery.dart @@ -102,7 +102,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier { } Future deleteImage(gallery.Image image) async { - await deleteRequest(_galleryUrlPath, image.id!); + var response = await deleteRequest(_galleryUrlPath, image.id!); images.removeWhere((element) => element.id == image.id); notifyListeners(); diff --git a/lib/providers/workout_plans.dart b/lib/providers/workout_plans.dart index 1c7161678..fc08d6cf9 100644 --- a/lib/providers/workout_plans.dart +++ b/lib/providers/workout_plans.dart @@ -18,6 +18,7 @@ import 'dart:convert'; import 'dart:developer' as dev; +import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; @@ -89,6 +90,10 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier { return _repetitionUnit.firstWhere((element) => element.id == DEFAULT_REPETITION_UNIT); } + List getPlans() { + return _workoutPlans; + } + WorkoutPlan findById(int id) { return _workoutPlans.firstWhere((workoutPlan) => workoutPlan.id == id); } @@ -359,6 +364,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier { 'weightUnit': _weightUnits.map((e) => e.toJson()).toList(), }; prefs.setString('workoutUnits', json.encode(exerciseData)); + log(json.encode(exerciseData)); notifyListeners(); } diff --git a/test/gallery/gallery_provider_test.dart b/test/gallery/gallery_provider_test.dart new file mode 100644 index 000000000..c74b1b426 --- /dev/null +++ b/test/gallery/gallery_provider_test.dart @@ -0,0 +1,82 @@ +/* + * This file is part of wger Workout Manager . + * 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 . + */ + +import 'package:flutter_test/flutter_test.dart'; +import 'package:http/http.dart' as http; +import 'package:mockito/mockito.dart'; +import 'package:wger/providers/gallery.dart'; +import '../other/base_provider_test.mocks.dart'; +import 'package:wger/models/gallery/image.dart' as gallery; +import '../utils.dart'; + +void main() { + group('test gallery provider', () { + test('Test that fetch and set gallery', () async { + final client = MockClient(); + + when(client.get( + Uri.https('localhost', 'api/v2/gallery/'), + headers: anyNamed('headers'), + )).thenAnswer((_) async => http.Response( + '{"count":1,"next":null,"previous":null,"results":[' + '{"id":58,' + '"date":"2022-01-09",' + '"image":"https://wger.de/media/gallery/170335/d2b9c9e0-d541-41ae-8786-a2ab459e3538.jpg",' + '"description":"eggsaddjujuit\'ddayhadIforcanview",' + '"height":1280,"width":960}]}', + 200)); + + GalleryProvider galleryProvider = GalleryProvider(testAuthProvider, [], client); + + await galleryProvider.fetchAndSetGallery(); + + // Check that everything is ok + expect(galleryProvider.images.length, 1); + }); + + test('Test that delete gallery photo', () async { + final client = MockClient(); + + when(client.delete( + Uri.https('localhost', 'api/v2/gallery/58/'), + headers: anyNamed('headers'), + )).thenAnswer((_) async => http.Response( + '{"id":58,' + '"date":"2022-01-09",' + '"image":"https://wger.de/media/gallery/170335/d2b9c9e0-d541-41ae-8786-a2ab459e3538.jpg",' + '"description":"eggsaddjujuit\'ddayhadIforcanview",' + '"height":1280,"width":960}', + 200)); + + GalleryProvider galleryProvider = GalleryProvider(testAuthProvider, [], client); + + gallery.Image image = gallery.Image( + id: 58, + date: DateTime(2022, 01, 09), + url: "https://wger.de/media/gallery/170335/d2b9c9e0-d541-41ae-8786-a2ab459e3538.jpg", + description: "eggsaddjujuit\'ddayhadIforcanview"); + + galleryProvider.images.add(image); + + await galleryProvider.deleteImage(image); + + // Check that everything is ok + expect(galleryProvider.images.length, 0); + }); + }); +} diff --git a/test/workout/workout_provider_test.dart b/test/workout/workout_provider_test.dart new file mode 100644 index 000000000..3483472cc --- /dev/null +++ b/test/workout/workout_provider_test.dart @@ -0,0 +1,185 @@ +/* + * This file is part of wger Workout Manager . + * 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 . + */ + +import 'dart:convert'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:http/http.dart' as http; +import 'package:mockito/mockito.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:wger/models/workouts/repetition_unit.dart'; +import 'package:wger/models/workouts/weight_unit.dart'; +import 'package:wger/models/workouts/workout_plan.dart'; +import 'package:wger/providers/exercises.dart'; +import 'package:wger/providers/workout_plans.dart'; +import '../measurements/measurement_provider_test.mocks.dart'; +import '../other/base_provider_test.mocks.dart'; +import '../utils.dart'; + +void main() { + var repetitionUnitsResponse = '{"count":7,"next":null,"previous":null,' + '"results":[' + '{"id":6,"name":"Kilometers"},' + '{"id":7,"name":"MaxReps"},' + '{"id":5,"name":"Miles"},' + '{"id":4,"name":"Minutes"},' + '{"id":1,"name":"Repetitions"},' + '{"id":3,"name":"Seconds"},' + '{"id":2,"name":"UntilFailure"}]}'; + + var weightUnitsResponse = '{"count":6,"next":null,"previous":null,' + '"results":[' + '{"id":3,"name":"BodyWeight"},' + '{"id":1,"name":"kg"},' + '{"id":5,"name":"KilometersPerHour"},' + '{"id":2,"name":"lb"},' + '{"id":6,"name":"MilesPerHour"},' + '{"id":4,"name":"Plates"}]}'; + + group('test workout plans provider', () { + test('Test that fetch and set plans', () async { + final client = MockClient(); + + final mockBaseProvider = MockWgerBaseProvider(); + final ExercisesProvider testExercisesProvider = ExercisesProvider(mockBaseProvider); + + when(client.get( + Uri.https('localhost', 'api/v2/workout/325397/'), + headers: anyNamed('headers'), + )).thenAnswer((_) async => http.Response( + '{"id": 325397,"name": "Test workout","creation_date": "2022-10-10","description": "It is test workout to fix a bug."}', + 200)); + + // Load the entries + final WorkoutPlansProvider provider = + WorkoutPlansProvider(testAuthProvider, testExercisesProvider, [], client); + + final plan = await provider.fetchAndSetPlanSparse(325397); + final plans = provider.getPlans(); + + // Check that everything is ok + expect(plan, isA()); + expect(plan.id, 325397); + expect(plans.length, 1); + }); + + test('Test that deletes workout plan', () async { + final client = MockClient(); + + final mockBaseProvider = MockWgerBaseProvider(); + final ExercisesProvider testExercisesProvider = ExercisesProvider(mockBaseProvider); + + when(client.get( + Uri.https('localhost', 'api/v2/workout/325397/'), + headers: anyNamed('headers'), + )).thenAnswer((_) async => http.Response( + '{"id": 325397,"name": "Test workout","creation_date": "2022-10-10","description": "It is test workout to fix a bug."}', + 200)); + + when(client.delete( + Uri.https('localhost', 'api/v2/workout/325397/'), + headers: anyNamed('headers'), + )).thenAnswer((_) async => http.Response( + '{"id": 325397,"name": "Test workout","creation_date": "2022-10-10","description": "It is test workout to fix a bug."}', + 200)); + + // Load the entries + final WorkoutPlansProvider provider = + WorkoutPlansProvider(testAuthProvider, testExercisesProvider, [], client); + + await provider.fetchAndSetPlanSparse(325397); + await provider.deleteWorkout(325397); + final plans = provider.getPlans(); + expect(plans.length, 0); + }); + + test('Test that fetch and set repetition units for workout', () async { + final client = MockClient(); + + final mockBaseProvider = MockWgerBaseProvider(); + final ExercisesProvider testExercisesProvider = ExercisesProvider(mockBaseProvider); + + when(client.get( + Uri.https('localhost', 'api/v2/setting-repetitionunit/'), + headers: anyNamed('headers'), + )).thenAnswer((_) async => http.Response(repetitionUnitsResponse, 200)); + + // Load the entries + final WorkoutPlansProvider provider = + WorkoutPlansProvider(testAuthProvider, testExercisesProvider, [], client); + + await provider.fetchAndSetRepetitionUnits(); + + List repetitionUnits = provider.repetitionUnits; + + expect(repetitionUnits, isA>()); + expect(repetitionUnits.length, 7); + }); + test('Test that fetch and set weight units for workout', () async { + final client = MockClient(); + + final mockBaseProvider = MockWgerBaseProvider(); + final ExercisesProvider testExercisesProvider = ExercisesProvider(mockBaseProvider); + + when(client.get( + Uri.https('localhost', 'api/v2/setting-weightunit/'), + headers: anyNamed('headers'), + )).thenAnswer((_) async => http.Response(weightUnitsResponse, 200)); + + // Load the entries + final WorkoutPlansProvider provider = + WorkoutPlansProvider(testAuthProvider, testExercisesProvider, [], client); + + await provider.fetchAndSetWeightUnits(); + + List weightUnits = provider.weightUnits; + + expect(weightUnits, isA>()); + expect(weightUnits.length, 6); + }); + + test('Test that fetch and set both type of units', () async { + final client = MockClient(); + + final mockBaseProvider = MockWgerBaseProvider(); + final ExercisesProvider testExercisesProvider = ExercisesProvider(mockBaseProvider); + final prefs = await SharedPreferences.getInstance(); + + when(client.get( + Uri.https('localhost', 'api/v2/setting-repetitionunit/'), + headers: anyNamed('headers'), + )).thenAnswer((_) async => http.Response(repetitionUnitsResponse, 200)); + when(client.get( + Uri.https('localhost', 'api/v2/setting-weightunit/'), + headers: anyNamed('headers'), + )).thenAnswer((_) async => http.Response(weightUnitsResponse, 200)); + + // Load the entries + final WorkoutPlansProvider provider = + WorkoutPlansProvider(testAuthProvider, testExercisesProvider, [], client); + + await provider.fetchAndSetUnits(); + + dynamic prefsJson = jsonDecode(prefs.getString('workoutUnits')!); + + expect(prefsJson["repetitionUnits"].length, 7); + expect(prefsJson["weightUnit"].length, 6); + expect(true, DateTime.parse(prefsJson["date"]).isBefore(DateTime.now())); + expect(true, DateTime.parse(prefsJson["expiresIn"]).isAfter(DateTime.now())); + }); + }); +} From 81437d24455ab5a1e40f082cca182d4debcdfe32 Mon Sep 17 00:00:00 2001 From: Bujdy Date: Sat, 12 Nov 2022 17:45:29 +0100 Subject: [PATCH 3/3] changed AUTHORS.md --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 42d0555d4..57161720c 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -15,6 +15,7 @@ - Ogundoyin Toluwani - - Nenza Nurfirmansyah - - Florian Schmitz - +- Adam Bujdoš - ## Translators