MM-69835 Convert remaining Enzyme tests to RTL - #8
Conversation
|
@coderabbitai If possible, review this |
|
✅ Action performedReview finished.
|
|
|
📝 WalkthroughWalkthroughThe test suite migrates from Enzyme to React Testing Library. Shared DOM assertion helpers and controlled interaction fixtures replace Enzyme APIs. Enzyme dependencies are removed, and Karma uses ChromeHeadless by default. ChangesReact Testing Library migration
Estimated code review effort: 3 (Moderate) | ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/MenuItemSpec.js`:
- Around line 148-155: Update the tests in MenuItemSpec.js to verify behavior
rather than checking the absent onselect attribute: use a callback spy and
dispatch the appropriate selection event to assert onSelect is invoked, and use
a separate onClick callback for click behavior. Remove the duplicated
onSelect-based click test while preserving coverage that internal props do not
leak and click handlers are called.
In `@test/SafeAnchorSpec.js`:
- Around line 85-89: Update the disabled-link test around SafeAnchor.handleClick
to verify propagation is stopped, not only that the component’s onClick prop is
skipped. Render SafeAnchor inside a parent with a separate onClick spy, trigger
the disabled click, and assert the parent spy was not called while preserving
the existing defaultPrevented and clickSpy assertions.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a85dd4e7-c6dc-40da-a5ff-f545210fb695
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (20)
karma.conf.jspackage.jsontest/CheckboxSpec.jstest/ControlLabelSpec.jstest/FormControlFeedbackSpec.jstest/FormControlSpec.jstest/FormControlStaticSpec.jstest/FormSpec.jstest/HelpBlockSpec.jstest/InputGroupSpec.jstest/MenuItemSpec.jstest/NavSpec.jstest/PanelGroupSpec.jstest/PanelSpec.jstest/RadioSpec.jstest/SafeAnchorSpec.jstest/TabContainerSpec.jstest/ToggleButtonGroupSpec.jstest/helpers.jstest/index.js
💤 Files with no reviewable changes (1)
- package.json
| // `onSelect` is an internal prop and must not leak onto the rendered DOM | ||
| // node. There is no DOM attribute for `onSelect`, so the closest observable | ||
| // check is that the rendered anchor carries no `onselect` attribute (and no | ||
| // React unknown-prop warning is emitted, which the harness would surface). | ||
| const { container } = render(<MenuItem onSelect={() => {}}>Item</MenuItem>); | ||
| const anchor = container.querySelector('a'); | ||
|
|
||
| assert.equal(anchor.getAttribute('onselect'), null); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the exact prop filtering and forwarding path. Do not execute repository code.
rg -n -C 6 'splitBsPropsAndOmit|onSelect|onClick|SafeAnchor|createChainedFunction' src/MenuItem.js
fd -i '^SafeAnchor\.js$' src -0 |
xargs -0 -r rg -n -C 6 'onSelect|onClick|elementProps|props|<a'Repository: mattermost/react-bootstrap
Length of output: 4972
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- test/MenuItemSpec.js ---'
sed -n '130,172p' test/MenuItemSpec.js
printf '%s\n' '--- splitBsPropsAndOmit implementation ---'
rg -n -C 8 'function splitBsPropsAndOmit|const splitBsPropsAndOmit|export.*splitBsPropsAndOmit' src/utilsRepository: mattermost/react-bootstrap
Length of output: 2829
Replace the onselect attribute checks with behavioural assertions.
onSelect is a React synthetic event, so getAttribute('onselect') remains null even when onSelect reaches SafeAnchor. Both tests can therefore pass without proving prop omission. The second test also passes onSelect, not onClick, and duplicates the first test. Use a callback spy with a selection event, and pass an onClick callback when testing click behaviour.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/MenuItemSpec.js` around lines 148 - 155, Update the tests in
MenuItemSpec.js to verify behavior rather than checking the absent onselect
attribute: use a callback spy and dispatch the appropriate selection event to
assert onSelect is invoked, and use a separate onClick callback for click
behavior. Remove the duplicated onSelect-based click test while preserving
coverage that internal props do not leak and click handlers are called.
| // Disabled links must not fire the user-provided onClick handler. This also | ||
| // stands in for the removed `isPropagationStopped()` assertion: the disabled | ||
| // path returns early after stopping propagation, so onClick is never called. | ||
| expect(clickSpy).to.have.not.been.called; | ||
| expect(spy.getCall(0).args[0].isDefaultPrevented()).to.equal(true); | ||
| expect(spy.getCall(0).args[0].isPropagationStopped()).to.equal(true); | ||
| expect(spy.getCall(0).args[0].defaultPrevented).to.equal(true); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Retain the propagation assertion.
clickSpy verifies only that SafeAnchor does not call its own onClick prop. It does not verify event.stopPropagation().
If SafeAnchor.handleClick removes event.stopPropagation() but keeps the early return, this test still passes while disabled-link clicks bubble to parent handlers. Render the anchor inside a parent with an onClick spy, then assert that the parent spy was not called.
Proposed test update
it('Should disable link behavior', () => {
let clickSpy = sinon.spy();
+ let parentClickSpy = sinon.spy();
let spy = sinon.spy(SafeAnchor.prototype, 'handleClick');
const { container } = render(
- <SafeAnchor disabled href="`#foo`" onClick={clickSpy}>
- Title
- </SafeAnchor>
+ <div onClick={parentClickSpy}>
+ <SafeAnchor disabled href="`#foo`" onClick={clickSpy}>
+ Title
+ </SafeAnchor>
+ </div>
);
fireEvent.click(container.querySelector('a'));
expect(spy).to.have.been.calledOnce;
expect(clickSpy).to.have.not.been.called;
+ expect(parentClickSpy).to.have.not.been.called;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/SafeAnchorSpec.js` around lines 85 - 89, Update the disabled-link test
around SafeAnchor.handleClick to verify propagation is stopped, not only that
the component’s onClick prop is skipped. Render SafeAnchor inside a parent with
a separate onClick spy, trigger the disabled click, and assert the parent spy
was not called while preserving the existing defaultPrevented and clickSpy
assertions.
Summary
This is the first part of updating to React 19 by finally getting rid of Enzyme in the tests for React Bootstrap. This was done primarily using Claude
Ticket Link
https://mattermost.atlassian.net/browse/MM-69835