Skip to content

test(CheckboxGroup): controlled/uncontrolled value switch (#1825)#2081

Open
kotAPI wants to merge 1 commit into
mainfrom
test/issue-1825-checkboxgroup-controlled-switch
Open

test(CheckboxGroup): controlled/uncontrolled value switch (#1825)#2081
kotAPI wants to merge 1 commit into
mainfrom
test/issue-1825-checkboxgroup-controlled-switch

Conversation

@kotAPI

@kotAPI kotAPI commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

add controlled/uncontrolled value switch regression tests

Test plan

  • Related unit tests pass locally

Related to #1825

Summary by CodeRabbit

  • Tests
    • Added coverage for CheckboxGroup switching between uncontrolled and controlled states.
    • Verified that selected items update correctly after rerendering with new selection values.
    • Confirmed click interactions continue to report the expected combined selection when choices change.

@changeset-bot

changeset-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 1c9b20a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A new test file is added for CheckboxGroup that covers "controlled switch" behavior: two async tests verify aria-checked state transitions and onValueChange invocations when the component rerenders switching between uncontrolled (defaultValue) and controlled (value) modes.

Changes

CheckboxGroup Controlled Switch Tests

Layer / File(s) Summary
Controlled↔Uncontrolled switch test suite
src/components/ui/CheckboxGroup/tests/CheckboxGroup.controlledSwitch.test.tsx
Defines render helpers and two async tests: one asserts aria-checked reflects controlled value after an uncontrolled→controlled rerender and verifies onValueChange is called with the combined next selection; the other asserts checkbox state after a controlled→uncontrolled rerender via defaultValue.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Possibly related issues

Possibly related PRs

  • rad-ui/ui#1239: Overlaps in CheckboxGroup controlled/uncontrolled rerender test scenarios and RTL assertion patterns.

Poem

🐇 Hop, hop, a checkbox sings,
Controlled to free, then back it swings!
Apple checked, banana too,
onValueChange rings out true.
The rabbit tests with care and glee —
Uncontrolled, controlled, all states run free! ✅

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the PR’s main change: adding CheckboxGroup tests for controlled/uncontrolled value switching.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 test/issue-1825-checkboxgroup-controlled-switch

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

@github-actions

Copy link
Copy Markdown
Contributor

Coverage

This report compares the PR with the base branch. "Δ" shows how the PR affects each metric.

Metric PR Δ
Statements 78.2% +0.00%
Branches 60.85% +0.00%
Functions 63.51% +0.00%
Lines 79.79% +0.00%

Coverage improved or stayed the same. Great job!

Run npm run coverage:ci locally for detailed reports and target untested areas to raise these numbers.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 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
`@src/components/ui/CheckboxGroup/tests/CheckboxGroup.controlledSwitch.test.tsx`:
- Around line 46-60: The controlled-to-uncontrolled test currently remounts a
new tree with unmount() and render(), so it does not verify switching the same
CheckboxGroup instance from value to defaultValue. Update the test in
CheckboxGroup.controlledSwitch.test.tsx to use rerender() on the existing render
result when moving from the controlled props to the uncontrolled props, and keep
the assertions against CheckboxGroup behavior (and the group helper) aligned
with that same-instance transition; if you intend to keep remounting, rename the
test to reflect that instead.
🪄 Autofix (Beta)

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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5f63702a-b43f-4a73-a948-09dfe83ffb51

📥 Commits

Reviewing files that changed from the base of the PR and between 56746ce and 1c9b20a.

📒 Files selected for processing (1)
  • src/components/ui/CheckboxGroup/tests/CheckboxGroup.controlledSwitch.test.tsx

Comment on lines +46 to +60
test('switches from controlled value to uncontrolled defaultValue', async() => {
const user = userEvent.setup();

const { unmount } = render(group({ value: ['banana'], onValueChange: () => {} }));

expect(screen.getByRole('checkbox', { name: 'Banana' })).toHaveAttribute('aria-checked', 'true');
unmount();

render(group({ defaultValue: ['apple'] }));

expect(screen.getByRole('checkbox', { name: 'Apple' })).toHaveAttribute('aria-checked', 'true');

await user.click(screen.getByRole('checkbox', { name: 'Banana' }));
expect(screen.getByRole('checkbox', { name: 'Banana' })).toHaveAttribute('aria-checked', 'true');
});

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.

📐 Maintainability & Code Quality | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect how CheckboxGroup.Root handles controlled vs uncontrolled value, and any switch handling/warnings.
fd -t f 'CheckboxGroup' src/components/ui/CheckboxGroup --exec echo {}
ast-grep outline src/components/ui/CheckboxGroup/CheckboxGroup.tsx 2>/dev/null
rg -nP -C3 '(defaultValue|value|onValueChange|isControlled|useControll)' src/components/ui/CheckboxGroup

Repository: rad-ui/ui

Length of output: 21808


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the component implementation and the exact test file.
ast-grep outline src/components/ui/CheckboxGroup/fragments/CheckboxGroupRoot.tsx
printf '\n--- CheckboxGroupRoot.tsx ---\n'
sed -n '1,220p' src/components/ui/CheckboxGroup/fragments/CheckboxGroupRoot.tsx

printf '\n--- CheckboxGroup.controlledSwitch.test.tsx ---\n'
sed -n '1,220p' src/components/ui/CheckboxGroup/tests/CheckboxGroup.controlledSwitch.test.tsx

# Search for any explicit controlled/uncontrolled switch handling or docs in the repo.
printf '\n--- switch-related search ---\n'
rg -n "controlled.*uncontrolled|uncontrolled.*controlled|defaultValue|value=.*defaultValue|switches from controlled|switches from uncontrolled" src/components/ui/CheckboxGroup src | sed -n '1,220p'

Repository: rad-ui/ui

Length of output: 32419


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the component implementation and the exact test file.
ast-grep outline src/components/ui/CheckboxGroup/fragments/CheckboxGroupRoot.tsx
printf '\n--- CheckboxGroupRoot.tsx ---\n'
sed -n '1,220p' src/components/ui/CheckboxGroup/fragments/CheckboxGroupRoot.tsx

printf '\n--- CheckboxGroup.controlledSwitch.test.tsx ---\n'
sed -n '1,220p' src/components/ui/CheckboxGroup/tests/CheckboxGroup.controlledSwitch.test.tsx

# Search for any explicit controlled/uncontrolled switch handling or docs in the repo.
printf '\n--- switch-related search ---\n'
rg -n "controlled.*uncontrolled|uncontrolled.*controlled|defaultValue|value=.*defaultValue|switches from controlled|switches from uncontrolled" src/components/ui/CheckboxGroup src | sed -n '1,220p'

Repository: rad-ui/ui

Length of output: 32467


🏁 Script executed:

#!/bin/bash
set -euo pipefail
sed -n '1,220p' src/components/ui/CheckboxGroup/fragments/CheckboxGroupRoot.tsx

Repository: rad-ui/ui

Length of output: 1911


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n--- useControllableState ---\n'
sed -n '1,220p' src/core/hooks/useControllableState/index.tsx

printf '\n--- CheckboxGroupPrimitiveRoot ---\n'
sed -n '1,220p' src/core/primitives/CheckboxGroup/fragments/CheckboxGroupPrimitiveRoot.tsx

printf '\n--- CheckboxGroupPrimitive tests around switching ---\n'
sed -n '1,240p' src/core/primitives/CheckboxGroup/tests/CheckboxGroupPrimitive.test.tsx

Repository: rad-ui/ui

Length of output: 14950


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n--- useControllableState ---\n'
sed -n '1,220p' src/core/hooks/useControllableState/index.tsx

printf '\n--- CheckboxGroupPrimitiveRoot ---\n'
sed -n '1,220p' src/core/primitives/CheckboxGroup/fragments/CheckboxGroupPrimitiveRoot.tsx

printf '\n--- CheckboxGroupPrimitive tests around switching ---\n'
sed -n '1,240p' src/core/primitives/CheckboxGroup/tests/CheckboxGroupPrimitive.test.tsx

Repository: rad-ui/ui

Length of output: 14950


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n--- useControllableState ---\n'
sed -n '1,220p' src/core/hooks/useControllableState/index.tsx

printf '\n--- CheckboxGroupPrimitiveRoot ---\n'
sed -n '1,220p' src/core/primitives/CheckboxGroup/fragments/CheckboxGroupPrimitiveRoot.tsx

printf '\n--- CheckboxGroupPrimitive tests around switching ---\n'
sed -n '1,240p' src/core/primitives/CheckboxGroup/tests/CheckboxGroupPrimitive.test.tsx

Repository: rad-ui/ui

Length of output: 14950


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n--- useControllableState ---\n'
sed -n '1,220p' src/core/hooks/useControllableState/index.tsx

printf '\n--- CheckboxGroupPrimitiveRoot ---\n'
sed -n '1,220p' src/core/primitives/CheckboxGroup/fragments/CheckboxGroupPrimitiveRoot.tsx

printf '\n--- CheckboxGroupPrimitive tests around switching ---\n'
sed -n '1,240p' src/core/primitives/CheckboxGroup/tests/CheckboxGroupPrimitive.test.tsx

Repository: rad-ui/ui

Length of output: 14950


Use rerender for the controlled→uncontrolled case. unmount() + render() mounts a fresh uncontrolled tree, so this doesn’t cover a same-instance switch and misses the behavior this test name implies. If remounting is intentional, rename the test.

🤖 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
`@src/components/ui/CheckboxGroup/tests/CheckboxGroup.controlledSwitch.test.tsx`
around lines 46 - 60, The controlled-to-uncontrolled test currently remounts a
new tree with unmount() and render(), so it does not verify switching the same
CheckboxGroup instance from value to defaultValue. Update the test in
CheckboxGroup.controlledSwitch.test.tsx to use rerender() on the existing render
result when moving from the controlled props to the uncontrolled props, and keep
the assertions against CheckboxGroup behavior (and the group helper) aligned
with that same-instance transition; if you intend to keep remounting, rename the
test to reflect that instead.

@kotAPI

kotAPI commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

Code review

LGTM. Matches project patterns for portal Theme refs, Floating UI prop merge, controlled-switch/lazy-mount/RTL tests, or focused bug fixes. No changes requested.

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.

1 participant