Skip to content

Quiz exercises: Validate short answer question title length#12533

Open
MaximilianAnzinger wants to merge 2 commits intodevelopfrom
fix/quiz/input-validation
Open

Quiz exercises: Validate short answer question title length#12533
MaximilianAnzinger wants to merge 2 commits intodevelopfrom
fix/quiz/input-validation

Conversation

@MaximilianAnzinger
Copy link
Copy Markdown
Collaborator

@MaximilianAnzinger MaximilianAnzinger commented Apr 14, 2026

Summary

Add inline title length validation to the short answer question editor so excessively long titles are blocked directly in the quiz creation flow instead of only surfacing later through overall quiz validation.

Checklist

General

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the principle of data economy for all client-server REST calls.
  • I strictly followed the client coding guidelines.
  • I added multiple integration tests (Vitest) related to the features (with a high test coverage), while following the test guidelines.

Motivation and Context

Fixes #12452.

The short answer question title input currently accepts arbitrarily long text even though the quiz editor already treats long question titles as invalid. This means instructors can enter very large titles without immediate feedback in the short answer creation flow.

Description

  • apply the existing quiz question title threshold directly to the short answer question title input
  • show inline maxlength feedback when the title exceeds the allowed limit
  • apply the same protection in the re-evaluation title input for consistency
  • add a focused component test that verifies the configured maxlength on the short answer title field

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 Course
  • 1 Quiz exercise
  1. Log in as an instructor.
  2. Open a quiz exercise in edit mode, or create a new one.
  3. Add a short answer question.
  4. Paste a very long string into the short answer question title field.
  5. Verify that the field does not accept more than the allowed title length and shows validation feedback when the limit is reached.
  6. Save the quiz and verify that no additional invalid-reason is caused by an oversized short answer title entered through this editor.
  7. Open quiz re-evaluation for a quiz containing a short answer question.
  8. Verify that the short answer title field there also enforces the same maximum length and displays the same validation feedback.

Exam Mode Testing

This change only affects the quiz exercise editing UI for instructors and does not affect exam mode participation.

Review Progress

Performance Review

  • I (as a reviewer) confirm that the client changes (in particular related to REST calls and UI responsiveness) are implemented with a very good performance even for very large courses with more than 2000 students.

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Client

Class/File Line Coverage Lines Expects Ratio
short-answer-question-edit.component.ts 93.40% 473 53 11.2

Last updated: 2026-04-14 15:12:55 UTC

@MaximilianAnzinger MaximilianAnzinger requested a review from a team as a code owner April 14, 2026 14:03
@github-project-automation github-project-automation Bot moved this to Work In Progress in Artemis Development Apr 14, 2026
@github-actions github-actions Bot added client Pull requests that update TypeScript code. (Added Automatically!) quiz Pull requests that affect the corresponding module labels Apr 14, 2026
@MaximilianAnzinger MaximilianAnzinger changed the title Quiz: Validate short answer question title length Quiz exercises: Validate short answer question title length Apr 14, 2026
@github-actions
Copy link
Copy Markdown

@MaximilianAnzinger Test coverage has been automatically updated in the PR description.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 14, 2026

Walkthrough

Input length validation was added to short answer question title fields in a quiz editing component, implementing a maximum character limit constraint (MAX_QUIZ_QUESTION_LENGTH_THRESHOLD - 1) with form validation, visual feedback for invalid states, and localized error messages.

Changes

Cohort / File(s) Summary
Template Validation
src/main/webapp/app/quiz/manage/short-answer-question/short-answer-question-edit.component.html
Added template-driven validation to question title inputs in both normal and re-evaluation sections, including ngModel bindings, maxlength attribute constraints, invalid CSS styling, unique name attributes based on question index, and conditional translation-aware error message display for maxlength violations.
Component Constants & Logic
src/main/webapp/app/quiz/manage/short-answer-question/short-answer-question-edit.component.ts
Imported MAX_QUIZ_QUESTION_LENGTH_THRESHOLD and introduced new public readonly field MAX_QUESTION_TITLE_LENGTH calculated as MAX_QUIZ_QUESTION_LENGTH_THRESHOLD - 1 for use in template validation.
Test Coverage
src/main/webapp/app/quiz/manage/short-answer-question/short-answer-question-edit.component.spec.ts
Added import of MAX_QUIZ_QUESTION_LENGTH_THRESHOLD and introduced new test assertion verifying that the #short-answer-question-title DOM element has its maxlength attribute properly set.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding validation for short answer question title length in quiz exercises.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #12452: enforces maxlength validation on the title input, provides inline validation feedback, and applies the validation consistently to both edit and re-evaluation sections.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing input validation for short answer question titles as specified in issue #12452; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/quiz/input-validation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/main/webapp/app/quiz/manage/short-answer-question/short-answer-question-edit.component.spec.ts (1)

654-659: Add a companion maxlength assertion for the re-evaluation title input.

This test currently covers only the default edit branch; the re-evaluation branch has a separate input and should be asserted too.

Suggested test addition
+    it('should enforce the title maxlength on the re-evaluation short answer question input', () => {
+        fixture.componentRef.setInput('reEvaluationInProgress', true);
+        fixture.detectChanges();
+
+        const titleInput = fixture.nativeElement.querySelector<HTMLInputElement>(
+            'input[name="short-answer-question-title-reevaluate-0"]',
+        );
+
+        expect(titleInput).not.toBeNull();
+        expect(titleInput?.getAttribute('maxlength')).toBe(String(MAX_QUIZ_QUESTION_LENGTH_THRESHOLD - 1));
+    });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/webapp/app/quiz/manage/short-answer-question/short-answer-question-edit.component.spec.ts`
around lines 654 - 659, Add a companion assertion that verifies the maxlength on
the re-evaluation title input: query the DOM for the re-evaluation input (e.g.,
the element with id '#short-answer-question-re-evaluation-title' or the
component's re-evaluation title selector used in the template), assert it is not
null, and check its maxlength equals String(MAX_QUIZ_QUESTION_LENGTH_THRESHOLD -
1) just like the existing check for '#short-answer-question-title' so both the
default edit and re-evaluation branches are covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@src/main/webapp/app/quiz/manage/short-answer-question/short-answer-question-edit.component.spec.ts`:
- Around line 654-659: Add a companion assertion that verifies the maxlength on
the re-evaluation title input: query the DOM for the re-evaluation input (e.g.,
the element with id '#short-answer-question-re-evaluation-title' or the
component's re-evaluation title selector used in the template), assert it is not
null, and check its maxlength equals String(MAX_QUIZ_QUESTION_LENGTH_THRESHOLD -
1) just like the existing check for '#short-answer-question-title' so both the
default edit and re-evaluation branches are covered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 90ccfc63-e232-4962-96b9-03525d268c62

📥 Commits

Reviewing files that changed from the base of the PR and between 300a20c and bff4725.

📒 Files selected for processing (3)
  • src/main/webapp/app/quiz/manage/short-answer-question/short-answer-question-edit.component.html
  • src/main/webapp/app/quiz/manage/short-answer-question/short-answer-question-edit.component.spec.ts
  • src/main/webapp/app/quiz/manage/short-answer-question/short-answer-question-edit.component.ts

@github-actions
Copy link
Copy Markdown

@MaximilianAnzinger Your PR description needs attention before it can be reviewed:

Issues Found

  1. Screenshots are missing but this PR contains visual/UI changes

How to Fix

  • Add screenshots of the UI changes.

This check validates that your PR description follows the PR template. A complete description helps reviewers understand your changes and speeds up the review process.

Note: This description validation is an experimental feature. If you observe false positives, please send a DM with a link to the wrong comment to Patrick Bassner on Slack. Thank you!

@github-actions
Copy link
Copy Markdown

@MaximilianAnzinger Test coverage has been automatically updated in the PR description.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 14, 2026

End-to-End Test Results

Phase Status Details
Phase 1 (Relevant) ✅ Passed
TestsPassed ✅Skipped ⚠️FailedTime ⏱
Phase 1: E2E Test Report37 ran36 passed1 skipped0 failed3m 20s
Phase 2 (Remaining) ❌ Failed
TestsPassed ☑️Skipped ⚠️Failed ❌️Time ⏱
Phase 2: E2E Test Report215 ran213 passed1 skipped1 failed26m 20s

Test Strategy: Two-phase execution

  • Phase 1: e2e/Login.spec.ts e2e/Logout.spec.ts e2e/SystemHealth.spec.ts e2e/exercise/quiz-exercise/
  • Phase 2: e2e/atlas/ e2e/course/ e2e/exam/ExamAssessment.spec.ts e2e/exam/ExamChecklists.spec.ts e2e/exam/ExamCreationDeletion.spec.ts e2e/exam/ExamDateVerification.spec.ts e2e/exam/ExamManagement.spec.ts e2e/exam/ExamParticipation.spec.ts e2e/exam/ExamResults.spec.ts e2e/exam/ExamTestRun.spec.ts e2e/exam/test-exam/ e2e/exercise/ExerciseImport.spec.ts e2e/exercise/file-upload/ e2e/exercise/modeling/ e2e/exercise/programming/ e2e/exercise/text/ e2e/lecture/

Overall: ❌ Phase 2 (remaining tests) failed

🔗 Workflow Run · 📊 Test Report

Copy link
Copy Markdown
Contributor

@Claudia-Anthropica Claudia-Anthropica left a comment

Choose a reason for hiding this comment

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

@MaximilianAnzinger Clean and focused change. The maxlength of 249 correctly matches the existing >= 250 threshold, both inputs (edit and re-evaluation) are covered, and the translation key wires up properly. Nice work.

@MaximilianAnzinger MaximilianAnzinger added this to the 9.0.1 milestone Apr 17, 2026
@SedaOran SedaOran self-requested a review April 20, 2026 12:27
Copy link
Copy Markdown
Contributor

@SedaOran SedaOran left a comment

Choose a reason for hiding this comment

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

Looks good overall.

One small suggestion: since you're using MAX_QUIZ_QUESTION_LENGTH_THRESHOLD - 1 to derive MAX_QUESTION_TITLE_LENGTH, it might be helpful to add a short comment explaining the -1 (to align with the < threshold validation).

I was also wondering if it might be worth considering server-side validation for this as well (and possibly tests for it), just to ensure consistency and avoid relying only on client-side checks.

Otherwise, really clean and well-structured change. Thanks.

@bensofficial bensofficial modified the milestones: 9.1.0, 9.1.1 Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client Pull requests that update TypeScript code. (Added Automatically!) quiz Pull requests that affect the corresponding module ready for review small

Projects

Status: Work In Progress

Development

Successfully merging this pull request may close these issues.

Quiz exercise: No input length validation for Short Answer question title

4 participants