Skip to content

Conversation

@Richard141201
Copy link

@Richard141201 Richard141201 commented Oct 16, 2025

feat: Add step-level language validation for exercise descriptions

Validate description language immediately when clicking "Next" instead
of at final form submit. Shows loading indicator and inline errors.

Changes:

  • Add _validateLanguageOnServer() method with API integration
  • Show loading spinner and error messages in UI
  • Prevent navigation on validation failure
  • Update Step3Description & Step4Translation onChange callbacks

Tests:

  • 6 unit tests (3 correct language, 3 wrong language)
  • Uses Mockito for mocking validateLanguage() API calls
  • Tests English, German, Slovak validation
Snímka obrazovky 2025-10-16 142345 Snímka obrazovky 2025-10-16 142502 Snímka obrazovky 2025-10-16 142512

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was really confused about this till I saw that it's one of flutter's generated files 😅

import 'package:wger/providers/add_exercise.dart';

@GenerateMocks([AddExerciseProvider])
import 'add_exercise_translation_test.mocks.dart';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be add_exercise_screen_test.mocks.dart

mockAddExerciseProvider = MockAddExerciseProvider();
});

group('Language validation - correct language', () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that since we're mocking the provider, these don't actually test anything. The backend already has some tests for that so the most we could do here is make sure validateLanguage makes the correct requests to the server

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 14 unit tests verifying correct validateLanguage calls

GlobalKey<FormState>(),
];

Future<bool> _validateLanguageOnServer(BuildContext context) async {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had hoped we could add something to the fields themselves so that the logic would be directly in e.g. Step3Description or AddExerciseTextArea. I find it very baffling that flutter does not have support for async validators, then this would be way easier

bool _isLoading = false;
bool _isValidating = false;
Widget errorWidget = const SizedBox.shrink();
String? _validationError;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can take a look at FormHttpErrorsWidget, you can give it a WgerHttpException directly and it will render it nicely

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now using FormHttpErrorsWidget instead of plain Text widget

@rolandgeider
Copy link
Member

@Richard141201 I hadn't time to review this, sorry. It's approved so it should count towards hacktoberfest, even if it's not merged. Will merge it as soon as I can

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants