mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-05 04:57:37 +01:00
Make the measurements a tab of their own, led by the weight
This commit is contained in:
@@ -646,6 +646,17 @@ class MockAppLocalizations extends _i1.Mock implements _i2.AppLocalizations {
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String get labelBottomNavBody =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#labelBottomNavBody),
|
||||
returnValue: _i3.dummyValue<String>(
|
||||
this,
|
||||
Invocation.getter(#labelBottomNavBody),
|
||||
),
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String get labelWorkoutLogs =>
|
||||
(super.noSuchMethod(
|
||||
@@ -2346,6 +2357,17 @@ class MockAppLocalizations extends _i1.Mock implements _i2.AppLocalizations {
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String get metricLeanBodyMass =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#metricLeanBodyMass),
|
||||
returnValue: _i3.dummyValue<String>(
|
||||
this,
|
||||
Invocation.getter(#metricLeanBodyMass),
|
||||
),
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String get metricBodyFat =>
|
||||
(super.noSuchMethod(
|
||||
@@ -2423,6 +2445,17 @@ class MockAppLocalizations extends _i1.Mock implements _i2.AppLocalizations {
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String get metricBloodOxygen =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#metricBloodOxygen),
|
||||
returnValue: _i3.dummyValue<String>(
|
||||
this,
|
||||
Invocation.getter(#metricBloodOxygen),
|
||||
),
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String get metricSteps =>
|
||||
(super.noSuchMethod(
|
||||
@@ -5347,50 +5380,6 @@ class MockAppLocalizations extends _i1.Mock implements _i2.AppLocalizations {
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String chartAllTimeTitle(String? name) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#chartAllTimeTitle, [name]),
|
||||
returnValue: _i3.dummyValue<String>(
|
||||
this,
|
||||
Invocation.method(#chartAllTimeTitle, [name]),
|
||||
),
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String chart30DaysTitle(String? name) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#chart30DaysTitle, [name]),
|
||||
returnValue: _i3.dummyValue<String>(
|
||||
this,
|
||||
Invocation.method(#chart30DaysTitle, [name]),
|
||||
),
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String chartLastYearTitle(String? name) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#chartLastYearTitle, [name]),
|
||||
returnValue: _i3.dummyValue<String>(
|
||||
this,
|
||||
Invocation.method(#chartLastYearTitle, [name]),
|
||||
),
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String chartLast3MonthsTitle(String? name) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#chartLast3MonthsTitle, [name]),
|
||||
returnValue: _i3.dummyValue<String>(
|
||||
this,
|
||||
Invocation.method(#chartLast3MonthsTitle, [name]),
|
||||
),
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String chartRangeMonths(int? count) =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -62,7 +62,7 @@ void main() {
|
||||
await tester.pumpWidget(createMeasurementScreen());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Measurements'), findsOneWidget);
|
||||
expect(find.text('Body'), findsOneWidget);
|
||||
expect(find.text('Body fat'), findsOneWidget);
|
||||
expect(find.text('Biceps'), findsOneWidget);
|
||||
expect(find.text('Blood pressure'), findsOneWidget);
|
||||
|
||||
@@ -20,6 +20,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_notifier.dart';
|
||||
@@ -28,7 +30,9 @@ import 'package:wger/features/measurements/widgets/categories.dart';
|
||||
import 'package:wger/features/measurements/widgets/categories_card.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
|
||||
import '../../../../test_data/body_weight.dart';
|
||||
import '../../../../test_data/measurements.dart';
|
||||
import '../../../../test_data/profile.dart';
|
||||
import '../../../helpers/measurement_chart_buckets.dart';
|
||||
import '../../../helpers/measurement_repository_stubs.dart';
|
||||
import 'categories_test.mocks.dart';
|
||||
@@ -38,9 +42,15 @@ Widget _wrap(
|
||||
List<MeasurementCategory> categories = const [],
|
||||
Map<String, List<MeasurementEntry>> entries = const {},
|
||||
}) {
|
||||
// The weight card needs the display unit, so it only appears once the
|
||||
// profile is there
|
||||
final mockProfileRepo = MockUserProfileRepository();
|
||||
when(mockProfileRepo.watchDrift()).thenAnswer((_) => Stream.value(tUserProfile1));
|
||||
|
||||
return ProviderScope(
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockRepo),
|
||||
userProfileRepositoryProvider.overrideWithValue(mockProfileRepo),
|
||||
// The cards read their chart points from the aggregated queries
|
||||
measurementChartBucketsProvider.overrideWith(chartBucketsFrom(entries)),
|
||||
measurementGroupBucketsProvider.overrideWith(groupBucketsFrom(categories, entries)),
|
||||
@@ -53,7 +63,7 @@ Widget _wrap(
|
||||
);
|
||||
}
|
||||
|
||||
@GenerateMocks([MeasurementRepository])
|
||||
@GenerateMocks([MeasurementRepository, UserProfileRepository])
|
||||
void main() {
|
||||
late MockMeasurementRepository mockRepo;
|
||||
|
||||
@@ -97,6 +107,29 @@ void main() {
|
||||
expect(find.text('Diastolic'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('body weight leads the list, wherever it is sorted', (tester) async {
|
||||
// The card is the way into the weight screen, so it stays on top rather
|
||||
// than taking the position the category order gives it
|
||||
final categories = [...getMeasurementCategories(), getBodyWeightCategory()];
|
||||
final entries = {...getMeasurementEntries(), ...bodyWeightEntries()};
|
||||
stubMeasurementReads(mockRepo, categories, entries);
|
||||
// Tall enough for all three cards; the list builds only what it shows
|
||||
tester.view.physicalSize = const Size(800, 2200);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
await tester.pumpWidget(_wrap(mockRepo, categories: categories, entries: entries));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Once, at the top: the official category is left out of the list below
|
||||
expect(find.byType(CategoriesCard), findsNWidgets(3));
|
||||
expect(find.text('Weight'), findsOneWidget);
|
||||
expect(
|
||||
tester.getTopLeft(find.text('Weight')).dy,
|
||||
lessThan(tester.getTopLeft(find.text('Body fat')).dy),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('empty list renders no CategoriesCard', (tester) async {
|
||||
stubMeasurementReads(mockRepo, []);
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i8;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i7;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i6;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i4;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i5;
|
||||
@@ -279,3 +281,29 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Future<void>);
|
||||
}
|
||||
|
||||
/// A class which mocks [UserProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i7.UserProfileRepository {
|
||||
MockUserProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.Stream<_i8.UserProfile?> watchDrift() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchDrift, []),
|
||||
returnValue: _i3.Stream<_i8.UserProfile?>.empty(),
|
||||
)
|
||||
as _i3.Stream<_i8.UserProfile?>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> editLocalDrift(_i8.UserProfile? profile) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editLocalDrift, [profile]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
returnValueForMissingStub: _i3.Future<void>.value(),
|
||||
)
|
||||
as _i3.Future<void>);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user