mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-04 12:42:22 +01:00
Show the weight form bounds rounded inwards
This commit is contained in:
@@ -202,10 +202,11 @@ class _WeightFormState extends riverpod.ConsumerState<WeightForm> {
|
||||
return i18n.enterValidNumber;
|
||||
}
|
||||
if (!_isInRange(parsed)) {
|
||||
// The bounds are defined in kg, show them in the entered unit
|
||||
// The bounds are defined in kg; show them in the entered unit,
|
||||
// rounded inwards so every displayed bound is itself accepted
|
||||
return i18n.formMinMaxValues(
|
||||
convertWeight(_minWeightKg, from: 'kg', to: _unit).round(),
|
||||
convertWeight(_maxWeightKg, from: 'kg', to: _unit).round(),
|
||||
convertWeight(_minWeightKg, from: 'kg', to: _unit).ceil(),
|
||||
convertWeight(_maxWeightKg, from: 'kg', to: _unit).floor(),
|
||||
);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -203,6 +203,64 @@ void main() {
|
||||
expect(saved.extraData, {'unit': 'lb'});
|
||||
});
|
||||
|
||||
testWidgets('Accepts imperial weights over the 300 kg display bound', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
when(
|
||||
mockProfileRepo.watchDrift(),
|
||||
).thenAnswer((_) => Stream.value(UserProfile(id: 1, weightUnitStr: 'lb')));
|
||||
|
||||
final container = ProviderContainer.test(
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockRepo),
|
||||
userProfileRepositoryProvider.overrideWithValue(mockProfileRepo),
|
||||
],
|
||||
);
|
||||
container.listen(userProfileProvider, (_, _) {});
|
||||
await tester.runAsync(pumpEventQueue);
|
||||
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: WeightForm(getBodyWeightCategory(const [])),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 365 lb are over the numeric kg bound but a perfectly valid weight
|
||||
await tester.enterText(find.byKey(const Key('weightInput')), '365');
|
||||
await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final saved = verify(mockRepo.addLocalDrift(captureAny)).captured.single as MeasurementEntry;
|
||||
expect(saved.value, 365);
|
||||
expect(saved.extraData, {'unit': 'lb'});
|
||||
});
|
||||
|
||||
testWidgets('Rejects implausible weights with bounds in the entered unit', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
await tester.pumpWidget(createWeightForm(entry: testWeightEntryLb));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 35 lb are below the plausible minimum of 30 kg
|
||||
await tester.enterText(find.byKey(const Key('weightInput')), '35');
|
||||
await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
verifyNever(mockRepo.updateLocalDrift(any));
|
||||
// Bounds are rounded inwards, so the displayed minimum is acceptable
|
||||
expect(find.text('Please enter a value between 67 and 661'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Editing shows the stored value in its stored unit, unconverted', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
|
||||
Reference in New Issue
Block a user