mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-06 07:54:02 +01:00
Merge branch 'refs/heads/master' into nutrition-plan-stats
This commit is contained in:
commit
0fd2af030d
51 files changed
+1388
-409
No files matched your search
@@ -39,7 +39,7 @@ import 'settings_test.mocks.dart';
|
||||
WgerBaseProvider,
|
||||
SharedPreferencesAsync,
|
||||
])
|
||||
void main() async {
|
||||
void main() {
|
||||
final mockExerciseProvider = MockExercisesProvider();
|
||||
final mockNutritionProvider = MockNutritionPlansProvider();
|
||||
final mockSharedPreferences = MockSharedPreferencesAsync();
|
||||
@@ -68,12 +68,22 @@ void main() async {
|
||||
group('Cache', () {
|
||||
testWidgets('Test resetting the exercise cache', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createSettingsScreen());
|
||||
await tester.tap(find.byKey(const ValueKey('cacheIconExercises')));
|
||||
await tester.tap(find.byKey(const ValueKey('cacheIconExercisesDelete')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
verify(mockExerciseProvider.clearAllCachesAndPrefs());
|
||||
});
|
||||
|
||||
testWidgets('Test refreshing the exercise cache', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createSettingsScreen());
|
||||
await tester.tap(find.byKey(const ValueKey('cacheIconExercisesRefresh')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
verify(mockExerciseProvider.clearAllCachesAndPrefs());
|
||||
verify(mockExerciseProvider.fetchAndSetInitialData());
|
||||
verify(mockExerciseProvider.fetchAndSetAllExercises());
|
||||
});
|
||||
|
||||
testWidgets('Test resetting the ingredient cache', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createSettingsScreen());
|
||||
await tester.tap(find.byKey(const ValueKey('cacheIconIngredients')));
|
||||
|
||||
@@ -490,6 +490,16 @@ class MockExercisesProvider extends _i1.Mock implements _i17.ExercisesProvider {
|
||||
returnValueForMissingStub: _i18.Future<void>.value(),
|
||||
) as _i18.Future<void>);
|
||||
|
||||
@override
|
||||
_i18.Future<void> fetchAndSetAllExercises() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllExercises,
|
||||
[],
|
||||
),
|
||||
returnValue: _i18.Future<void>.value(),
|
||||
returnValueForMissingStub: _i18.Future<void>.value(),
|
||||
) as _i18.Future<void>);
|
||||
|
||||
@override
|
||||
_i18.Future<_i4.Exercise?> fetchAndSetExercise(int? exerciseId) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -945,6 +945,16 @@ class MockExercisesProvider extends _i1.Mock implements _i20.ExercisesProvider {
|
||||
returnValueForMissingStub: _i15.Future<void>.value(),
|
||||
) as _i15.Future<void>);
|
||||
|
||||
@override
|
||||
_i15.Future<void> fetchAndSetAllExercises() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllExercises,
|
||||
[],
|
||||
),
|
||||
returnValue: _i15.Future<void>.value(),
|
||||
returnValueForMissingStub: _i15.Future<void>.value(),
|
||||
) as _i15.Future<void>);
|
||||
|
||||
@override
|
||||
_i15.Future<_i3.Exercise?> fetchAndSetExercise(int? exerciseId) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -377,6 +377,16 @@ class MockExercisesProvider extends _i1.Mock implements _i9.ExercisesProvider {
|
||||
returnValueForMissingStub: _i10.Future<void>.value(),
|
||||
) as _i10.Future<void>);
|
||||
|
||||
@override
|
||||
_i10.Future<void> fetchAndSetAllExercises() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllExercises,
|
||||
[],
|
||||
),
|
||||
returnValue: _i10.Future<void>.value(),
|
||||
returnValueForMissingStub: _i10.Future<void>.value(),
|
||||
) as _i10.Future<void>);
|
||||
|
||||
@override
|
||||
_i10.Future<_i4.Exercise?> fetchAndSetExercise(int? exerciseId) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
import 'package:wger/exceptions/no_such_entry_exception.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/models/measurements/measurement_category.dart';
|
||||
import 'package:wger/models/measurements/measurement_entry.dart';
|
||||
import 'package:wger/providers/base_provider.dart';
|
||||
@@ -14,8 +15,6 @@ import 'package:wger/providers/measurement.dart';
|
||||
import '../fixtures/fixture_reader.dart';
|
||||
import 'measurement_provider_test.mocks.dart';
|
||||
|
||||
// class MockWgerBaseProvider extends Mock implements WgerBaseProvider {}
|
||||
|
||||
@GenerateMocks([WgerBaseProvider])
|
||||
void main() {
|
||||
late MeasurementProvider measurementProvider;
|
||||
@@ -48,16 +47,17 @@ void main() {
|
||||
measurementProvider = MeasurementProvider(mockWgerBaseProvider);
|
||||
|
||||
when(mockWgerBaseProvider.makeUrl(any)).thenReturn(tCategoryUri);
|
||||
when(mockWgerBaseProvider.makeUrl(any, id: anyNamed('id'))).thenReturn(tCategoryUri);
|
||||
when(mockWgerBaseProvider.fetch(any))
|
||||
.thenAnswer((realInvocation) => Future.value(tMeasurementCategoriesMap));
|
||||
when(mockWgerBaseProvider.makeUrl(any, id: anyNamed('id'), query: anyNamed('query')))
|
||||
.thenReturn(tCategoryUri);
|
||||
when(mockWgerBaseProvider.fetchPaginated(any))
|
||||
.thenAnswer((realInvocation) => Future.value(tMeasurementCategoriesMap['results']));
|
||||
|
||||
when(mockWgerBaseProvider.makeUrl(entryUrl, query: anyNamed('query')))
|
||||
.thenReturn(tCategoryEntriesUri);
|
||||
when(mockWgerBaseProvider.makeUrl(entryUrl, id: anyNamed('id'), query: anyNamed('query')))
|
||||
.thenReturn(tCategoryEntriesUri);
|
||||
when(mockWgerBaseProvider.fetch(tCategoryEntriesUri))
|
||||
.thenAnswer((realInvocation) => Future.value(tMeasurementCategoryMap));
|
||||
when(mockWgerBaseProvider.fetchPaginated(tCategoryEntriesUri))
|
||||
.thenAnswer((realInvocation) => Future.value(tMeasurementCategoryMap['results']));
|
||||
});
|
||||
|
||||
group('clear()', () {
|
||||
@@ -100,7 +100,7 @@ void main() {
|
||||
await measurementProvider.fetchAndSetCategories();
|
||||
|
||||
// assert
|
||||
verify(mockWgerBaseProvider.makeUrl(categoryUrl));
|
||||
verify(mockWgerBaseProvider.makeUrl(categoryUrl, query: {'limit': API_MAX_PAGE_SIZE}));
|
||||
});
|
||||
|
||||
test('should fetch data from api', () async {
|
||||
@@ -108,7 +108,7 @@ void main() {
|
||||
await measurementProvider.fetchAndSetCategories();
|
||||
|
||||
// assert
|
||||
verify(mockWgerBaseProvider.fetch(tCategoryUri));
|
||||
verify(mockWgerBaseProvider.fetchPaginated(tCategoryUri));
|
||||
});
|
||||
|
||||
test('should set categories', () async {
|
||||
@@ -130,7 +130,10 @@ void main() {
|
||||
await measurementProvider.fetchAndSetCategoryEntries(tCategoryId);
|
||||
|
||||
// assert
|
||||
verify(mockWgerBaseProvider.makeUrl(entryUrl, query: {'category': tCategoryId.toString()}));
|
||||
verify(mockWgerBaseProvider.makeUrl(
|
||||
entryUrl,
|
||||
query: {'category': tCategoryId.toString(), 'limit': API_MAX_PAGE_SIZE},
|
||||
));
|
||||
});
|
||||
|
||||
test('should fetch categories entries for id', () async {
|
||||
@@ -138,7 +141,7 @@ void main() {
|
||||
await measurementProvider.fetchAndSetCategoryEntries(tCategoryId);
|
||||
|
||||
// assert
|
||||
verify(mockWgerBaseProvider.fetch(tCategoryEntriesUri));
|
||||
verify(mockWgerBaseProvider.fetchPaginated(tCategoryEntriesUri));
|
||||
});
|
||||
|
||||
test('should add entries to category in list', () async {
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -44,28 +44,31 @@ import '../../test_data/exercises.dart';
|
||||
import '../../test_data/routines.dart';
|
||||
import 'gym_mode_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([WgerBaseProvider, ExercisesProvider])
|
||||
@GenerateMocks([WgerBaseProvider, ExercisesProvider, RoutinesProvider])
|
||||
void main() {
|
||||
final mockBaseProvider = MockWgerBaseProvider();
|
||||
final key = GlobalKey<NavigatorState>();
|
||||
|
||||
final mockRoutinesProvider = MockRoutinesProvider();
|
||||
final mockExerciseProvider = MockExercisesProvider();
|
||||
final testRoutine = getTestRoutine();
|
||||
final testExercises = getTestExercises();
|
||||
|
||||
setUp(() {
|
||||
when(mockRoutinesProvider.findById(any)).thenReturn(testRoutine);
|
||||
when(mockRoutinesProvider.items).thenReturn([testRoutine]);
|
||||
when(mockRoutinesProvider.repetitionUnits).thenReturn(testRepetitionUnits);
|
||||
when(mockRoutinesProvider.findRepetitionUnitById(1)).thenReturn(testRepetitionUnit1);
|
||||
when(mockRoutinesProvider.weightUnits).thenReturn(testWeightUnits);
|
||||
when(mockRoutinesProvider.findWeightUnitById(1)).thenReturn(testWeightUnit1);
|
||||
when(mockRoutinesProvider.fetchAndSetRoutineFull(any))
|
||||
.thenAnswer((_) => Future.value(testRoutine));
|
||||
|
||||
SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty();
|
||||
});
|
||||
|
||||
Widget renderGymMode({locale = 'en'}) {
|
||||
return ChangeNotifierProvider<RoutinesProvider>(
|
||||
create: (context) => RoutinesProvider(
|
||||
mockBaseProvider,
|
||||
mockExerciseProvider,
|
||||
[testRoutine],
|
||||
repetitionUnits: testRepetitionUnits,
|
||||
weightUnits: testWeightUnits,
|
||||
),
|
||||
create: (context) => mockRoutinesProvider,
|
||||
child: ChangeNotifierProvider<ExercisesProvider>(
|
||||
create: (context) => mockExerciseProvider,
|
||||
child: riverpod.ProviderScope(
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -54,11 +54,12 @@ void main() {
|
||||
});
|
||||
|
||||
group('test the workout routine provider', () {
|
||||
test('Test fetching and setting a plan', () async {
|
||||
test('Test fetching and setting a routine', () async {
|
||||
final exercisesProvider = ExercisesProvider(mockBaseProvider);
|
||||
|
||||
final uri = Uri.https('localhost', 'api/v2/routine/325397/');
|
||||
when(mockBaseProvider.makeUrl('routine', id: 325397)).thenReturn(uri);
|
||||
when(mockBaseProvider.makeUrl('routine', id: 325397, query: {'limit': API_MAX_PAGE_SIZE}))
|
||||
.thenReturn(uri);
|
||||
when(mockBaseProvider.fetch(uri)).thenAnswer(
|
||||
(_) async => Future.value({
|
||||
'id': 325397,
|
||||
|
||||
@@ -580,6 +580,16 @@ class MockExercisesProvider extends _i1.Mock implements _i12.ExercisesProvider {
|
||||
returnValueForMissingStub: _i11.Future<void>.value(),
|
||||
) as _i11.Future<void>);
|
||||
|
||||
@override
|
||||
_i11.Future<void> fetchAndSetAllExercises() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllExercises,
|
||||
[],
|
||||
),
|
||||
returnValue: _i11.Future<void>.value(),
|
||||
returnValueForMissingStub: _i11.Future<void>.value(),
|
||||
) as _i11.Future<void>);
|
||||
|
||||
@override
|
||||
_i11.Future<_i6.Exercise?> fetchAndSetExercise(int? exerciseId) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
Reference in new issue
Block a user