mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Refactor add_exercise_screen.dart
Use the is_trustworthy flag from the server, which also takes the account's age into account. The widgets in the screen are split so it's easier to test and read
This commit is contained in:
@@ -28,13 +28,12 @@ const languages = [
|
||||
// Note: it seems if too many languages are processed at once, some processes
|
||||
// disappear and no images are written. Doing this in smaller steps works fine
|
||||
|
||||
/*
|
||||
'ca',
|
||||
'de-DE',
|
||||
'en-US',
|
||||
'es-ES',
|
||||
'fr-FR',
|
||||
*/
|
||||
|
||||
/*
|
||||
'hi-IN',
|
||||
'hr',
|
||||
|
||||
@@ -28,12 +28,16 @@ class Profile {
|
||||
@JsonKey(required: true, name: 'email_verified')
|
||||
bool emailVerified;
|
||||
|
||||
@JsonKey(required: true, name: 'is_trustworthy')
|
||||
bool isTrustworthy;
|
||||
|
||||
@JsonKey(required: true)
|
||||
String email;
|
||||
|
||||
Profile({
|
||||
required this.username,
|
||||
required this.emailVerified,
|
||||
required this.isTrustworthy,
|
||||
required this.email,
|
||||
});
|
||||
|
||||
|
||||
@@ -9,11 +9,12 @@ part of 'profile.dart';
|
||||
Profile _$ProfileFromJson(Map<String, dynamic> json) {
|
||||
$checkKeys(
|
||||
json,
|
||||
requiredKeys: const ['username', 'email_verified', 'email'],
|
||||
requiredKeys: const ['username', 'email_verified', 'is_trustworthy', 'email'],
|
||||
);
|
||||
return Profile(
|
||||
username: json['username'] as String,
|
||||
emailVerified: json['email_verified'] as bool,
|
||||
isTrustworthy: json['is_trustworthy'] as bool,
|
||||
email: json['email'] as String,
|
||||
);
|
||||
}
|
||||
@@ -21,5 +22,6 @@ Profile _$ProfileFromJson(Map<String, dynamic> json) {
|
||||
Map<String, dynamic> _$ProfileToJson(Profile instance) => <String, dynamic>{
|
||||
'username': instance.username,
|
||||
'email_verified': instance.emailVerified,
|
||||
'is_trustworthy': instance.isTrustworthy,
|
||||
'email': instance.email,
|
||||
};
|
||||
|
||||
@@ -16,19 +16,31 @@ import 'package:wger/widgets/user/forms.dart';
|
||||
|
||||
import 'form_screen.dart';
|
||||
|
||||
class AddExerciseScreen extends StatefulWidget {
|
||||
class AddExerciseScreen extends StatelessWidget {
|
||||
const AddExerciseScreen({Key? key}) : super(key: key);
|
||||
|
||||
static const routeName = '/exercises/add';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final profile = context.read<UserProvider>().profile;
|
||||
|
||||
return profile!.isTrustworthy ? const AddExerciseStepper() : const EmailNotVerified();
|
||||
}
|
||||
}
|
||||
|
||||
class AddExerciseStepper extends StatefulWidget {
|
||||
const AddExerciseStepper({Key? key}) : super(key: key);
|
||||
|
||||
static const STEPS_IN_FORM = 5;
|
||||
|
||||
@override
|
||||
_AddExerciseScreenState createState() => _AddExerciseScreenState();
|
||||
_AddExerciseStepperState createState() => _AddExerciseStepperState();
|
||||
}
|
||||
|
||||
class _AddExerciseScreenState extends State<AddExerciseScreen> {
|
||||
class _AddExerciseStepperState extends State<AddExerciseStepper> {
|
||||
int _currentStep = 0;
|
||||
int lastStepIndex = AddExerciseScreen.STEPS_IN_FORM - 1;
|
||||
int lastStepIndex = AddExerciseStepper.STEPS_IN_FORM - 1;
|
||||
final List<GlobalKey<FormState>> _keys = [
|
||||
GlobalKey<FormState>(),
|
||||
GlobalKey<FormState>(),
|
||||
@@ -70,11 +82,7 @@ class _AddExerciseScreenState extends State<AddExerciseScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final user = context.read<UserProvider>().profile;
|
||||
|
||||
return !user!.emailVerified
|
||||
? const EmailNotVerified()
|
||||
: Scaffold(
|
||||
return Scaffold(
|
||||
appBar: EmptyAppBar(AppLocalizations.of(context).contributeExercise),
|
||||
body: Stepper(
|
||||
controlsBuilder: _controlsBuilder,
|
||||
|
||||
94
test/exercises/contribute_exercise_test.dart
Normal file
94
test/exercises/contribute_exercise_test.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/providers/add_exercise.dart';
|
||||
import 'package:wger/providers/exercises.dart';
|
||||
import 'package:wger/providers/user.dart';
|
||||
import 'package:wger/screens/add_exercise_screen.dart';
|
||||
|
||||
import '../../test_data/exercises.dart';
|
||||
import '../../test_data/profile.dart';
|
||||
import '../workout/gym_mode_screen_test.mocks.dart';
|
||||
import 'contribute_exercise_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([AddExerciseProvider, UserProvider])
|
||||
void main() {
|
||||
final mockAddExerciseProvider = MockAddExerciseProvider();
|
||||
final mockExerciseProvider = MockExercisesProvider();
|
||||
final mockUserProvider = MockUserProvider();
|
||||
|
||||
Widget createExerciseScreen({locale = 'en'}) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<ExercisesProvider>(create: (context) => mockExerciseProvider),
|
||||
ChangeNotifierProvider<AddExerciseProvider>(create: (context) => mockAddExerciseProvider),
|
||||
ChangeNotifierProvider<UserProvider>(create: (context) => mockUserProvider),
|
||||
],
|
||||
child: MaterialApp(
|
||||
locale: Locale(locale),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const AddExerciseScreen(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('Unverified users see an info widget', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
tProfile1.isTrustworthy = false;
|
||||
when(mockUserProvider.profile).thenReturn(tProfile1);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createExerciseScreen());
|
||||
|
||||
// Assert
|
||||
expect(find.byType(EmailNotVerified), findsOneWidget);
|
||||
expect(find.byType(AddExerciseStepper), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Verified users see the stepper to add exercises', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
tProfile1.isTrustworthy = true;
|
||||
when(mockUserProvider.profile).thenReturn(tProfile1);
|
||||
|
||||
when(mockExerciseProvider.categories).thenReturn(testCategories);
|
||||
when(mockExerciseProvider.muscles).thenReturn(testMuscles);
|
||||
when(mockExerciseProvider.equipment).thenReturn(testEquipment);
|
||||
when(mockExerciseProvider.exerciseBasesByVariation).thenReturn({});
|
||||
when(mockExerciseProvider.bases).thenReturn(getTestExerciseBases());
|
||||
when(mockExerciseProvider.languages).thenReturn(testLanguages);
|
||||
|
||||
when(mockAddExerciseProvider.equipment).thenReturn([]);
|
||||
when(mockAddExerciseProvider.primaryMuscles).thenReturn([]);
|
||||
when(mockAddExerciseProvider.secondaryMuscles).thenReturn([]);
|
||||
when(mockAddExerciseProvider.newVariationForExercise).thenReturn(null);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createExerciseScreen());
|
||||
|
||||
// Assert
|
||||
expect(find.byType(EmailNotVerified), findsNothing);
|
||||
expect(find.byType(AddExerciseStepper), findsOneWidget);
|
||||
});
|
||||
}
|
||||
513
test/exercises/contribute_exercise_test.mocks.dart
Normal file
513
test/exercises/contribute_exercise_test.mocks.dart
Normal file
@@ -0,0 +1,513 @@
|
||||
// Mocks generated by Mockito 5.3.2 from annotations
|
||||
// in wger/test/exercises/contribute_exercise_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i13;
|
||||
import 'dart:io' as _i10;
|
||||
import 'dart:ui' as _i14;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/models/exercises/alias.dart' as _i6;
|
||||
import 'package:wger/models/exercises/base.dart' as _i3;
|
||||
import 'package:wger/models/exercises/category.dart' as _i9;
|
||||
import 'package:wger/models/exercises/equipment.dart' as _i11;
|
||||
import 'package:wger/models/exercises/language.dart' as _i8;
|
||||
import 'package:wger/models/exercises/muscle.dart' as _i12;
|
||||
import 'package:wger/models/exercises/translation.dart' as _i4;
|
||||
import 'package:wger/models/exercises/variation.dart' as _i5;
|
||||
import 'package:wger/models/user/profile.dart' as _i16;
|
||||
import 'package:wger/providers/add_exercise.dart' as _i7;
|
||||
import 'package:wger/providers/base_provider.dart' as _i2;
|
||||
import 'package:wger/providers/user.dart' as _i15;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
// ignore_for_file: avoid_setters_without_getters
|
||||
// ignore_for_file: comment_references
|
||||
// ignore_for_file: implementation_imports
|
||||
// ignore_for_file: invalid_use_of_visible_for_testing_member
|
||||
// ignore_for_file: prefer_const_constructors
|
||||
// ignore_for_file: unnecessary_parenthesis
|
||||
// ignore_for_file: camel_case_types
|
||||
// ignore_for_file: subtype_of_sealed_class
|
||||
|
||||
class _FakeWgerBaseProvider_0 extends _i1.SmartFake implements _i2.WgerBaseProvider {
|
||||
_FakeWgerBaseProvider_0(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeExerciseBase_1 extends _i1.SmartFake implements _i3.ExerciseBase {
|
||||
_FakeExerciseBase_1(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeTranslation_2 extends _i1.SmartFake implements _i4.Translation {
|
||||
_FakeTranslation_2(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeVariation_3 extends _i1.SmartFake implements _i5.Variation {
|
||||
_FakeVariation_3(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeAlias_4 extends _i1.SmartFake implements _i6.Alias {
|
||||
_FakeAlias_4(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [AddExerciseProvider].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockAddExerciseProvider extends _i1.Mock implements _i7.AddExerciseProvider {
|
||||
MockAddExerciseProvider() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i2.WgerBaseProvider get baseProvider => (super.noSuchMethod(
|
||||
Invocation.getter(#baseProvider),
|
||||
returnValue: _FakeWgerBaseProvider_0(
|
||||
this,
|
||||
Invocation.getter(#baseProvider),
|
||||
),
|
||||
) as _i2.WgerBaseProvider);
|
||||
@override
|
||||
set language(_i8.Language? _language) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#language,
|
||||
_language,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
set category(_i9.ExerciseCategory? _category) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#category,
|
||||
_category,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
List<_i10.File> get exerciseImages => (super.noSuchMethod(
|
||||
Invocation.getter(#exerciseImages),
|
||||
returnValue: <_i10.File>[],
|
||||
) as List<_i10.File>);
|
||||
@override
|
||||
set exerciseNameEn(String? name) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#exerciseNameEn,
|
||||
name,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
set exerciseNameTrans(String? name) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#exerciseNameTrans,
|
||||
name,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
set descriptionEn(String? description) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#descriptionEn,
|
||||
description,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
set descriptionTrans(String? description) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#descriptionTrans,
|
||||
description,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
set alternateNamesEn(List<String>? names) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#alternateNamesEn,
|
||||
names,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
set alternateNamesTrans(List<String>? names) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#alternateNamesTrans,
|
||||
names,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
set equipment(List<_i11.Equipment>? equipment) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#equipment,
|
||||
equipment,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
List<_i11.Equipment> get equipment => (super.noSuchMethod(
|
||||
Invocation.getter(#equipment),
|
||||
returnValue: <_i11.Equipment>[],
|
||||
) as List<_i11.Equipment>);
|
||||
@override
|
||||
bool get newVariation => (super.noSuchMethod(
|
||||
Invocation.getter(#newVariation),
|
||||
returnValue: false,
|
||||
) as bool);
|
||||
@override
|
||||
set newVariationForExercise(int? value) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#newVariationForExercise,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
set variationId(int? variation) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#variationId,
|
||||
variation,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
_i3.ExerciseBase get base => (super.noSuchMethod(
|
||||
Invocation.getter(#base),
|
||||
returnValue: _FakeExerciseBase_1(
|
||||
this,
|
||||
Invocation.getter(#base),
|
||||
),
|
||||
) as _i3.ExerciseBase);
|
||||
@override
|
||||
_i4.Translation get exerciseEn => (super.noSuchMethod(
|
||||
Invocation.getter(#exerciseEn),
|
||||
returnValue: _FakeTranslation_2(
|
||||
this,
|
||||
Invocation.getter(#exerciseEn),
|
||||
),
|
||||
) as _i4.Translation);
|
||||
@override
|
||||
_i4.Translation get exerciseTranslation => (super.noSuchMethod(
|
||||
Invocation.getter(#exerciseTranslation),
|
||||
returnValue: _FakeTranslation_2(
|
||||
this,
|
||||
Invocation.getter(#exerciseTranslation),
|
||||
),
|
||||
) as _i4.Translation);
|
||||
@override
|
||||
_i5.Variation get variation => (super.noSuchMethod(
|
||||
Invocation.getter(#variation),
|
||||
returnValue: _FakeVariation_3(
|
||||
this,
|
||||
Invocation.getter(#variation),
|
||||
),
|
||||
) as _i5.Variation);
|
||||
@override
|
||||
List<_i12.Muscle> get primaryMuscles => (super.noSuchMethod(
|
||||
Invocation.getter(#primaryMuscles),
|
||||
returnValue: <_i12.Muscle>[],
|
||||
) as List<_i12.Muscle>);
|
||||
@override
|
||||
set primaryMuscles(List<_i12.Muscle>? muscles) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#primaryMuscles,
|
||||
muscles,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
List<_i12.Muscle> get secondaryMuscles => (super.noSuchMethod(
|
||||
Invocation.getter(#secondaryMuscles),
|
||||
returnValue: <_i12.Muscle>[],
|
||||
) as List<_i12.Muscle>);
|
||||
@override
|
||||
set secondaryMuscles(List<_i12.Muscle>? muscles) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#secondaryMuscles,
|
||||
muscles,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
bool get hasListeners => (super.noSuchMethod(
|
||||
Invocation.getter(#hasListeners),
|
||||
returnValue: false,
|
||||
) as bool);
|
||||
@override
|
||||
void clear() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#clear,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
void addExerciseImages(List<_i10.File>? exercises) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addExerciseImages,
|
||||
[exercises],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
void removeExercise(String? path) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#removeExercise,
|
||||
[path],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
void printValues() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#printValues,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
_i13.Future<int> addExercise() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addExercise,
|
||||
[],
|
||||
),
|
||||
returnValue: _i13.Future<int>.value(0),
|
||||
) as _i13.Future<int>);
|
||||
@override
|
||||
_i13.Future<_i3.ExerciseBase> addExerciseBase() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addExerciseBase,
|
||||
[],
|
||||
),
|
||||
returnValue: _i13.Future<_i3.ExerciseBase>.value(_FakeExerciseBase_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addExerciseBase,
|
||||
[],
|
||||
),
|
||||
)),
|
||||
) as _i13.Future<_i3.ExerciseBase>);
|
||||
@override
|
||||
_i13.Future<_i5.Variation> addVariation() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addVariation,
|
||||
[],
|
||||
),
|
||||
returnValue: _i13.Future<_i5.Variation>.value(_FakeVariation_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addVariation,
|
||||
[],
|
||||
),
|
||||
)),
|
||||
) as _i13.Future<_i5.Variation>);
|
||||
@override
|
||||
_i13.Future<void> addImages(_i3.ExerciseBase? base) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addImages,
|
||||
[base],
|
||||
),
|
||||
returnValue: _i13.Future<void>.value(),
|
||||
returnValueForMissingStub: _i13.Future<void>.value(),
|
||||
) as _i13.Future<void>);
|
||||
@override
|
||||
_i13.Future<_i4.Translation> addExerciseTranslation(_i4.Translation? exercise) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addExerciseTranslation,
|
||||
[exercise],
|
||||
),
|
||||
returnValue: _i13.Future<_i4.Translation>.value(_FakeTranslation_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addExerciseTranslation,
|
||||
[exercise],
|
||||
),
|
||||
)),
|
||||
) as _i13.Future<_i4.Translation>);
|
||||
@override
|
||||
_i13.Future<_i6.Alias> addExerciseAlias(
|
||||
String? name,
|
||||
int? exerciseId,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addExerciseAlias,
|
||||
[
|
||||
name,
|
||||
exerciseId,
|
||||
],
|
||||
),
|
||||
returnValue: _i13.Future<_i6.Alias>.value(_FakeAlias_4(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addExerciseAlias,
|
||||
[
|
||||
name,
|
||||
exerciseId,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i13.Future<_i6.Alias>);
|
||||
@override
|
||||
void addListener(_i14.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
void removeListener(_i14.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#removeListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
void dispose() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#dispose,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
void notifyListeners() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#notifyListeners,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [UserProvider].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockUserProvider extends _i1.Mock implements _i15.UserProvider {
|
||||
MockUserProvider() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i2.WgerBaseProvider get baseProvider => (super.noSuchMethod(
|
||||
Invocation.getter(#baseProvider),
|
||||
returnValue: _FakeWgerBaseProvider_0(
|
||||
this,
|
||||
Invocation.getter(#baseProvider),
|
||||
),
|
||||
) as _i2.WgerBaseProvider);
|
||||
@override
|
||||
set profile(_i16.Profile? _profile) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#profile,
|
||||
_profile,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
bool get hasListeners => (super.noSuchMethod(
|
||||
Invocation.getter(#hasListeners),
|
||||
returnValue: false,
|
||||
) as bool);
|
||||
@override
|
||||
void clear() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#clear,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetProfile() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetProfile,
|
||||
[],
|
||||
),
|
||||
returnValue: _i13.Future<void>.value(),
|
||||
returnValueForMissingStub: _i13.Future<void>.value(),
|
||||
) as _i13.Future<void>);
|
||||
@override
|
||||
_i13.Future<void> saveProfile() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#saveProfile,
|
||||
[],
|
||||
),
|
||||
returnValue: _i13.Future<void>.value(),
|
||||
returnValueForMissingStub: _i13.Future<void>.value(),
|
||||
) as _i13.Future<void>);
|
||||
@override
|
||||
_i13.Future<void> verifyEmail() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#verifyEmail,
|
||||
[],
|
||||
),
|
||||
returnValue: _i13.Future<void>.value(),
|
||||
returnValueForMissingStub: _i13.Future<void>.value(),
|
||||
) as _i13.Future<void>);
|
||||
@override
|
||||
void addListener(_i14.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
void removeListener(_i14.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#removeListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
void dispose() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#dispose,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
void notifyListeners() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#notifyListeners,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
}
|
||||
4
test/fixtures/user/userprofile_response.json
vendored
4
test/fixtures/user/userprofile_response.json
vendored
@@ -1,7 +1,9 @@
|
||||
{
|
||||
"username": "admin",
|
||||
"email": "me@example.com",
|
||||
"email_verified": false,
|
||||
"email_verified": true,
|
||||
"is_trustworthy": true,
|
||||
"date_joined": "2021-04-24 09:07:09.364859+00:00",
|
||||
"gym": 1,
|
||||
"is_temporary": false,
|
||||
"show_comments": false,
|
||||
|
||||
@@ -78,8 +78,9 @@ void main() {
|
||||
|
||||
// assert
|
||||
expect(userProvider.profile!.username, 'admin');
|
||||
expect(userProvider.profile!.emailVerified, false);
|
||||
expect(userProvider.profile!.emailVerified, true);
|
||||
expect(userProvider.profile!.email, 'me@example.com');
|
||||
expect(userProvider.profile!.isTrustworthy, true);
|
||||
});
|
||||
|
||||
test('Sending the verify email works', () async {
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i6;
|
||||
import 'dart:ui' as _i7;
|
||||
import 'dart:async' as _i5;
|
||||
import 'dart:ui' as _i6;
|
||||
|
||||
import 'package:http/http.dart' as _i3;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/models/body_weight/weight_entry.dart' as _i4;
|
||||
import 'package:wger/providers/auth.dart' as _i2;
|
||||
import 'package:wger/providers/body_weight.dart' as _i5;
|
||||
import 'package:wger/models/body_weight/weight_entry.dart' as _i3;
|
||||
import 'package:wger/providers/base_provider.dart' as _i2;
|
||||
import 'package:wger/providers/body_weight.dart' as _i4;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
@@ -23,8 +22,8 @@ import 'package:wger/providers/body_weight.dart' as _i5;
|
||||
// ignore_for_file: camel_case_types
|
||||
// ignore_for_file: subtype_of_sealed_class
|
||||
|
||||
class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
|
||||
_FakeAuthProvider_0(
|
||||
class _FakeWgerBaseProvider_0 extends _i1.SmartFake implements _i2.WgerBaseProvider {
|
||||
_FakeWgerBaseProvider_0(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
@@ -33,38 +32,8 @@ class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
|
||||
_FakeClient_1(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeWeightEntry_2 extends _i1.SmartFake implements _i4.WeightEntry {
|
||||
_FakeWeightEntry_2(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeUri_3 extends _i1.SmartFake implements Uri {
|
||||
_FakeUri_3(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeResponse_4 extends _i1.SmartFake implements _i3.Response {
|
||||
_FakeResponse_4(
|
||||
class _FakeWeightEntry_1 extends _i1.SmartFake implements _i3.WeightEntry {
|
||||
_FakeWeightEntry_1(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
@@ -76,45 +45,29 @@ class _FakeResponse_4 extends _i1.SmartFake implements _i3.Response {
|
||||
/// A class which mocks [BodyWeightProvider].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockBodyWeightProvider extends _i1.Mock implements _i5.BodyWeightProvider {
|
||||
class MockBodyWeightProvider extends _i1.Mock implements _i4.BodyWeightProvider {
|
||||
MockBodyWeightProvider() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
List<_i4.WeightEntry> get items => (super.noSuchMethod(
|
||||
_i2.WgerBaseProvider get baseProvider => (super.noSuchMethod(
|
||||
Invocation.getter(#baseProvider),
|
||||
returnValue: _FakeWgerBaseProvider_0(
|
||||
this,
|
||||
Invocation.getter(#baseProvider),
|
||||
),
|
||||
) as _i2.WgerBaseProvider);
|
||||
@override
|
||||
List<_i3.WeightEntry> get items => (super.noSuchMethod(
|
||||
Invocation.getter(#items),
|
||||
returnValue: <_i4.WeightEntry>[],
|
||||
) as List<_i4.WeightEntry>);
|
||||
returnValue: <_i3.WeightEntry>[],
|
||||
) as List<_i3.WeightEntry>);
|
||||
@override
|
||||
_i2.AuthProvider get auth => (super.noSuchMethod(
|
||||
Invocation.getter(#auth),
|
||||
returnValue: _FakeAuthProvider_0(
|
||||
this,
|
||||
Invocation.getter(#auth),
|
||||
),
|
||||
) as _i2.AuthProvider);
|
||||
@override
|
||||
set auth(_i2.AuthProvider? _auth) => super.noSuchMethod(
|
||||
set items(List<_i3.WeightEntry>? entries) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#auth,
|
||||
_auth,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
_i3.Client get client => (super.noSuchMethod(
|
||||
Invocation.getter(#client),
|
||||
returnValue: _FakeClient_1(
|
||||
this,
|
||||
Invocation.getter(#client),
|
||||
),
|
||||
) as _i3.Client);
|
||||
@override
|
||||
set client(_i3.Client? _client) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#client,
|
||||
_client,
|
||||
#items,
|
||||
entries,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@@ -132,175 +85,66 @@ class MockBodyWeightProvider extends _i1.Mock implements _i5.BodyWeightProvider
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
_i4.WeightEntry findById(int? id) => (super.noSuchMethod(
|
||||
_i3.WeightEntry findById(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#findById,
|
||||
[id],
|
||||
),
|
||||
returnValue: _FakeWeightEntry_2(
|
||||
returnValue: _FakeWeightEntry_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#findById,
|
||||
[id],
|
||||
),
|
||||
),
|
||||
) as _i4.WeightEntry);
|
||||
) as _i3.WeightEntry);
|
||||
@override
|
||||
_i4.WeightEntry? findByDate(DateTime? date) => (super.noSuchMethod(Invocation.method(
|
||||
_i3.WeightEntry? findByDate(DateTime? date) => (super.noSuchMethod(Invocation.method(
|
||||
#findByDate,
|
||||
[date],
|
||||
)) as _i4.WeightEntry?);
|
||||
)) as _i3.WeightEntry?);
|
||||
@override
|
||||
_i6.Future<List<_i4.WeightEntry>> fetchAndSetEntries() => (super.noSuchMethod(
|
||||
_i5.Future<List<_i3.WeightEntry>> fetchAndSetEntries() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetEntries,
|
||||
[],
|
||||
),
|
||||
returnValue: _i6.Future<List<_i4.WeightEntry>>.value(<_i4.WeightEntry>[]),
|
||||
) as _i6.Future<List<_i4.WeightEntry>>);
|
||||
returnValue: _i5.Future<List<_i3.WeightEntry>>.value(<_i3.WeightEntry>[]),
|
||||
) as _i5.Future<List<_i3.WeightEntry>>);
|
||||
@override
|
||||
_i6.Future<_i4.WeightEntry> addEntry(_i4.WeightEntry? entry) => (super.noSuchMethod(
|
||||
_i5.Future<_i3.WeightEntry> addEntry(_i3.WeightEntry? entry) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addEntry,
|
||||
[entry],
|
||||
),
|
||||
returnValue: _i6.Future<_i4.WeightEntry>.value(_FakeWeightEntry_2(
|
||||
returnValue: _i5.Future<_i3.WeightEntry>.value(_FakeWeightEntry_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addEntry,
|
||||
[entry],
|
||||
),
|
||||
)),
|
||||
) as _i6.Future<_i4.WeightEntry>);
|
||||
) as _i5.Future<_i3.WeightEntry>);
|
||||
@override
|
||||
_i6.Future<void> editEntry(_i4.WeightEntry? entry) => (super.noSuchMethod(
|
||||
_i5.Future<void> editEntry(_i3.WeightEntry? entry) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editEntry,
|
||||
[entry],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
) as _i6.Future<void>);
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
) as _i5.Future<void>);
|
||||
@override
|
||||
_i6.Future<void> deleteEntry(int? id) => (super.noSuchMethod(
|
||||
_i5.Future<void> deleteEntry(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteEntry,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
) as _i6.Future<void>);
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
) as _i5.Future<void>);
|
||||
@override
|
||||
Map<String, String> getDefaultHeaders({dynamic includeAuth = false}) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDefaultHeaders,
|
||||
[],
|
||||
{#includeAuth: includeAuth},
|
||||
),
|
||||
returnValue: <String, String>{},
|
||||
) as Map<String, String>);
|
||||
@override
|
||||
Uri makeUrl(
|
||||
String? path, {
|
||||
int? id,
|
||||
String? objectMethod,
|
||||
Map<String, dynamic>? query,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#makeUrl,
|
||||
[path],
|
||||
{
|
||||
#id: id,
|
||||
#objectMethod: objectMethod,
|
||||
#query: query,
|
||||
},
|
||||
),
|
||||
returnValue: _FakeUri_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#makeUrl,
|
||||
[path],
|
||||
{
|
||||
#id: id,
|
||||
#objectMethod: objectMethod,
|
||||
#query: query,
|
||||
},
|
||||
),
|
||||
),
|
||||
) as Uri);
|
||||
@override
|
||||
_i6.Future<Map<String, dynamic>> fetch(Uri? uri) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetch,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i6.Future<Map<String, dynamic>>);
|
||||
@override
|
||||
_i6.Future<List<dynamic>> fetchPaginated(Uri? uri) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchPaginated,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i6.Future<List<dynamic>>.value(<dynamic>[]),
|
||||
) as _i6.Future<List<dynamic>>);
|
||||
@override
|
||||
_i6.Future<Map<String, dynamic>> post(
|
||||
Map<String, dynamic>? data,
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#post,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i6.Future<Map<String, dynamic>>);
|
||||
@override
|
||||
_i6.Future<Map<String, dynamic>> patch(
|
||||
Map<String, dynamic>? data,
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i6.Future<Map<String, dynamic>>);
|
||||
@override
|
||||
_i6.Future<_i3.Response> deleteRequest(
|
||||
String? url,
|
||||
int? id,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<_i3.Response>.value(_FakeResponse_4(
|
||||
this,
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i6.Future<_i3.Response>);
|
||||
@override
|
||||
void addListener(_i7.VoidCallback? listener) => super.noSuchMethod(
|
||||
void addListener(_i6.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addListener,
|
||||
[listener],
|
||||
@@ -308,7 +152,7 @@ class MockBodyWeightProvider extends _i1.Mock implements _i5.BodyWeightProvider
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
void removeListener(_i7.VoidCallback? listener) => super.noSuchMethod(
|
||||
void removeListener(_i6.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#removeListener,
|
||||
[listener],
|
||||
|
||||
@@ -26,20 +26,24 @@ import 'package:wger/models/exercises/translation.dart';
|
||||
const tLanguage1 = Language(id: 1, shortName: 'de', fullName: 'Deutsch');
|
||||
const tLanguage2 = Language(id: 2, shortName: 'en', fullName: 'English');
|
||||
const tLanguage3 = Language(id: 3, shortName: 'fr', fullName: 'Français');
|
||||
const testLanguages = [tLanguage1, tLanguage2, tLanguage3];
|
||||
|
||||
const tMuscle1 = Muscle(id: 1, name: 'Flutterus maximus', nameEn: 'Glutes', isFront: true);
|
||||
const tMuscle2 = Muscle(id: 2, name: 'Biceps brachii', nameEn: 'Biceps', isFront: true);
|
||||
const tMuscle3 = Muscle(id: 3, name: 'Gluteus maximus', nameEn: 'Booty', isFront: false);
|
||||
const tMuscle3 = Muscle(id: 3, name: 'Gluteus maximus', nameEn: 'Glutes', isFront: false);
|
||||
const testMuscles = [tMuscle1, tMuscle2, tMuscle3];
|
||||
|
||||
const tCategory1 = ExerciseCategory(id: 1, name: 'Arms');
|
||||
const tCategory2 = ExerciseCategory(id: 2, name: 'Legs');
|
||||
const tCategory3 = ExerciseCategory(id: 3, name: 'Abs');
|
||||
const tCategory4 = ExerciseCategory(id: 4, name: 'Shoulders');
|
||||
const tCategory5 = ExerciseCategory(id: 5, name: 'Calves');
|
||||
const testCategories = [tCategory1, tCategory2, tCategory3, tCategory4, tCategory5];
|
||||
|
||||
const tEquipment1 = Equipment(id: 1, name: 'Bench');
|
||||
const tEquipment2 = Equipment(id: 1, name: 'Dumbbell');
|
||||
const tEquipment3 = Equipment(id: 2, name: 'Matress');
|
||||
const tEquipment3 = Equipment(id: 2, name: 'Bench');
|
||||
const testEquipment = [tEquipment1, tEquipment2, tEquipment3];
|
||||
|
||||
final benchPress = ExerciseBase(
|
||||
id: 1,
|
||||
@@ -194,10 +198,6 @@ final sideRaisesEn = Translation(
|
||||
language: tLanguage2,
|
||||
);
|
||||
|
||||
List<Translation> getTestExercises() {
|
||||
return [benchPressDe, deadLiftEn, crunchesFr];
|
||||
}
|
||||
|
||||
List<ExerciseBase> getTestExerciseBases() {
|
||||
benchPress.translations = [benchPressEn, benchPressDe];
|
||||
crunches.translations = [crunchesEn, crunchesDe, crunchesFr];
|
||||
|
||||
8
test_data/profile.dart
Normal file
8
test_data/profile.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
import 'package:wger/models/user/profile.dart';
|
||||
|
||||
final tProfile1 = Profile(
|
||||
username: 'super root',
|
||||
emailVerified: true,
|
||||
isTrustworthy: true,
|
||||
email: 'admin@google.com',
|
||||
);
|
||||
Reference in New Issue
Block a user