Skip to content

Convert assessment item editor unit tests to Vue Testing Library#6038

Open
vtushar06 wants to merge 1 commit into
learningequality:unstablefrom
vtushar06:convert-assessment-editor-tests-5814
Open

Convert assessment item editor unit tests to Vue Testing Library#6038
vtushar06 wants to merge 1 commit into
learningequality:unstablefrom
vtushar06:convert-assessment-editor-tests-5814

Conversation

@vtushar06

Copy link
Copy Markdown
Contributor

Summary

Converts AssessmentItemEditor.spec.js from @vue/test-utils to Vue Testing Library (VTL), rewriting the suite to reflect how a user actually interacts with the question editor.

Changes:

  • Replaced mount/shallowMount + wrapper.vm/findComponent/vm.$emit with render, screen queries, and userEvent
  • Tests now cover the main user workflows:
    • Viewing an item (response type, question, answers, hints)
    • Editing the question text
    • Changing the response type (single choice / true or false / numeric input) and the resulting answer changes
    • Changing which answer is correct
    • Editing a hint
    • Validation messages for an invalid item
  • Dropped implementation-detail assertions (component internals and CSS-class selectors) in favour of user-observable behaviour
  • No residual @vue/test-utils imports

Mirrors the existing VTL pattern in the sibling HintsEditor.spec.js.

Screen recording:

References

Closes #5814
Sub-issue of #5789

Reviewer guidance

  • Run pnpm test AssessmentItemEditor — 8 tests pass
  • Feature covered by these tests: Channels > My Channels > a channel > Topic > Options > Edit details > Questions tab, then add or edit a question

Copilot AI review requested due to automatic review settings July 11, 2026 06:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@learning-equality-bot

Copy link
Copy Markdown

👋 Hi @vtushar06, thanks for contributing!

For the review process to begin, please verify that the following is satisfied:

  • Contribution is aligned with our contributing guidelines

  • Pull request description has correctly filled AI usage section & follows our AI guidance:

    AI guidance

    State explicitly whether you didn't use or used AI & how.

    If you used it, ensure that the PR is aligned with Using AI as well as our DEEP framework. DEEP asks you:

    • Disclose — Be open about when you've used AI for support.
    • Engage critically — Question what is generated. Review code for correctness and unnecessary complexity.
    • Edit — Review and refine AI output. Remove unnecessary code and verify it still works after your edits.
    • Process sharing — Explain how you used the AI so others can learn.

    Examples of good disclosures:

    "I used Claude Code to implement the component, prompting it to follow the pattern in ComponentX. I reviewed the generated code, removed unnecessary error handling, and verified the tests pass."

    "I brainstormed the approach with Gemini, then had it write failing tests for the feature. After reviewing the tests, I used Claude Code to generate the implementation. I refactored the output to reduce verbosity and ran the full test suite."

Also check that issue requirements are satisfied & you ran pre-commit locally.

Pull requests that don't follow the guidelines will be closed.

Reviewer assignment can take up to 2 weeks.

@rtibbles rtibbles requested a review from rtibblesbot July 11, 2026 06:53
@learning-equality-bot

Copy link
Copy Markdown

📢✨ Before we assign a reviewer, we'll turn on @rtibblesbot to pre-review. Its comments are generated by an LLM, and should be evaluated accordingly.

@rtibblesbot

rtibblesbot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

🔵 Review posted

Last updated: 2026-07-11 07:00 UTC

@rtibblesbot rtibblesbot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PR #6038 cleanly migrates AssessmentItemEditor.spec.js from @vue/test-utils to Vue Testing Library + userEvent. The conversion is genuinely behavioral — it drives real clicks/inputs and asserts on emitted payloads rather than reaching into vm, and replacing the shared listeners mock with per-test emitted() removes cross-test mutable state. CI passing. No UI source changed, so Phase 3 (visual QA) not applicable.

Non-blocking findings:

  • suggestion (inline, L87): dropped the single→multiple-selection type-change case, a coverage regression vs the old four-case suite.
  • suggestion (inline, L54): openQuestionEditor selects the textbox by tagName, brittle vs the mock's rendering.
  • nitpick (inline, L176): lone fireEvent.click on the radio is inconsistent with the file's userEvent style.
  • nitpick — L65 test title says "and hints" but asserts none (hints render collapsed); trim the title or assert the collapsed section.

@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly

How was this generated?

Ran a phased review pipeline over the pull request diff:

  • Classified the diff to select review passes (core, frontend, backend) and whether manual QA was required
  • Core review pass checked correctness, design, architecture, testing, completeness, and DRY/SRP/Rule-of-Three principles
  • Specialized frontend/backend review passes applied framework-specific lenses where those files changed
  • For UI changes: manual QA and an accessibility audit against a live dev server, when available
  • Checked CI status and linked issue acceptance criteria
  • Synthesized one review from those passes and chose the verdict from the findings, CI status, and QA evidence

});
});
});
describe('changing the question type', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: The old suite exercised four type transitions (single, multiple, true/false, input); this block covers only single choice, true/false, and numeric input. The single→multiple-selection case (asserting answers are preserved) was dropped — a distinct branch of the kind-change logic, so this is a real coverage regression, not just a rename. Consider adding a fourth case mirroring the others to keep the conversion behavior-preserving. If the omission is intentional, ignore.

const openQuestionEditor = async user => {
await user.click(screen.getByTestId('questionText'));
// Both the type dropdown and the answers expose textboxes, so target the question editor's.
return screen.getAllByRole('textbox').find(el => el.tagName === 'TEXTAREA');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: Selecting the textbox by el.tagName === 'TEXTAREA' keys off the mock's rendering rather than anything semantic — if the mock ever rendered a contenteditable div (as a real rich-text editor does) this silently returns undefined. Scoping via within(...).getByRole('textbox') around the question editor would be more robust; the edit-mode TipTapEditor carries no data-test, so a fully clean scope may need a test id added in production code. Acceptable as-is — flagging so the fragility is a conscious choice.

];
// Selecting the second answer's correctness control makes it the correct one.
const radios = screen.getAllByRole('radio');
await fireEvent.click(radios[1]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: Most tests click via user.click(...), but this drops to fireEvent.click(radios[1]). fireEvent.update for v-model values is idiomatic and fine to keep, but prefer await user.click(radios[1]) here so the interaction style is uniform.

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.

Convert assessment item editor unit tests to Vue Testing Library

3 participants