Skip to content

Quiz exercises: Fix 'Invalid Input' persisting after deleting and restoring the only question#12544

Open
MaximilianAnzinger wants to merge 1 commit intodevelopfrom
fix/quiz/invalid-input
Open

Quiz exercises: Fix 'Invalid Input' persisting after deleting and restoring the only question#12544
MaximilianAnzinger wants to merge 1 commit intodevelopfrom
fix/quiz/invalid-input

Conversation

@MaximilianAnzinger
Copy link
Copy Markdown
Collaborator

@MaximilianAnzinger MaximilianAnzinger commented Apr 16, 2026

Summary

Fixes #12475. When re-evaluating a quiz, deleting all questions (or the only question) and then clicking Reset Quiz to restore them left the "Invalid Input" badge permanently visible — even though the quiz was fully valid again after the reset.

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 #12475.

In the re-evaluate flow (QuizReEvaluateComponent), the resetAll() method clones savedEntity back into quizExercise — effectively restoring any questions that were previously deleted. However, it never called cacheValidation(), so the cached validation state (quizIsValid, invalidReasons) remained stale from when the questions were deleted. As a result, the "Invalid Input" badge kept showing the "The quiz has no questions" message even after the questions had been restored.

Description

Root cause: resetAll() in quiz-re-evaluate.component.ts only restored quizExercise from savedEntity but omitted the cacheValidation(this.changeDetector) call that updates quizIsValid and invalidReasons.

Fix: Added this.cacheValidation(this.changeDetector) at the end of resetAll(). This is a one-line change mirroring what every other mutation in this component already does (e.g. deleteQuestion, onQuestionUpdated).

Test added: A new Vitest test in quiz-re-evaluate.component.spec.ts that:

  1. Deletes all questions → asserts quizIsValid === false
  2. Calls resetAll() → asserts questions are restored and quizIsValid === true

Steps for Testing

Prerequisites:

  • 1 Instructor account
  • 1 Quiz exercise that has already ended (so the Re-evaluate button is available)
  1. Log in as Instructor.
  2. Navigate to the course → Exercises → the finished quiz exercise.
  3. Click Re-evaluate (wrench icon).
  4. Delete the only (or all) question(s) using the trash icon.
  5. Observe the "Invalid Input" badge appears with the message "The quiz has no questions".
  6. Click the Reset Quiz button.
  7. ✅ Expected: The badge disappears and the quiz is shown as valid again.
  8. ❌ Before fix: The badge persisted even though the question was visible.

Testserver States

You can manage test servers using Helios. Check environment statuses in the environment list. To deploy to a test server, go to the CI/CD page, find your PR or branch, and trigger the deployment.

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
quiz-re-evaluate.component.ts 84.12% 156 31 19.9

Last updated: 2026-04-16 09:34:21 UTC

When all questions were deleted and the quiz was restored via "Reset Quiz",
the "Invalid Input" badge persisted because resetAll() did not call
cacheValidation(). Add the call so quizIsValid and invalidReasons are
refreshed after the quiz is restored from savedEntity.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@MaximilianAnzinger MaximilianAnzinger requested a review from a team as a code owner April 16, 2026 09:31
@github-project-automation github-project-automation bot moved this to Work In Progress in Artemis Development Apr 16, 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 16, 2026
@MaximilianAnzinger MaximilianAnzinger changed the title Quiz re-evaluate: Fix 'Invalid Input' persisting after deleting and restoring the only question Quiz exercise: Fix 'Invalid Input' persisting after deleting and restoring the only question Apr 16, 2026
@MaximilianAnzinger MaximilianAnzinger changed the title Quiz exercise: Fix 'Invalid Input' persisting after deleting and restoring the only question Quiz exercises: Fix 'Invalid Input' persisting after deleting and restoring the only question Apr 16, 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 16, 2026

Walkthrough

The changes address a validation state bug in quiz re-evaluation by ensuring that the resetAll() method re-caches validation after restoring the quiz exercise. A unit test is added to verify that validation state is correctly updated when questions are deleted and the reset operation is performed.

Changes

Cohort / File(s) Summary
Component validation fix
src/main/webapp/app/quiz/manage/re-evaluate/quiz-re-evaluate.component.ts
Added cacheValidation() call in resetAll() method to update validation state after restoring the quiz exercise from saved state.
Component test
src/main/webapp/app/quiz/manage/re-evaluate/quiz-re-evaluate.component.spec.ts
Added unit test verifying that resetAll() correctly restores questions and fixes validation state after all questions are deleted.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The code changes directly address issue #12475 by adding validation caching in resetAll() and testing the fix with a unit test.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the validation state issue; no unrelated modifications are present in the component or test files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly and specifically describes the main bug being fixed: the 'Invalid Input' validation persisting after deleting and restoring questions in quiz exercises.

✏️ 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/invalid-input

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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 16, 2026

End-to-End Test Results

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

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 fix — resetAll() was the only mutation missing the cacheValidation() call. The new test covers the exact bug scenario nicely. Approving as-is.

@MaximilianAnzinger MaximilianAnzinger added this to the 9.0.1 milestone Apr 17, 2026
@SedaOran SedaOran requested review from SedaOran 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.

Hi @MaximilianAnzinger ,
Thanks for the clean fix, the validation issue and the added test make sense.

I had one question regarding the behavior after clicking Reset Quiz: once the questions are restored, the Save button remains disabled if no further changes are made. Only after modifying the quiz again does it become enabled.

Is this the expected behavior (i.e., no changes → nothing to save), or should resetting also mark the quiz as having pending changes so it can be saved immediately? Just wanted to clarify whether this is intentional or something we might want to revisit.

Thanks!

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

Projects

Status: Work In Progress

Development

Successfully merging this pull request may close these issues.

Quiz exercise: “Invalid Input” persists after deleting and restoring the only question

3 participants