Skip to content

test(AlertDialog): lazy mount dialog content (#1847)#2068

Open
kotAPI wants to merge 2 commits into
mainfrom
test/issue-1847-alertdialog-lazy-mount
Open

test(AlertDialog): lazy mount dialog content (#1847)#2068
kotAPI wants to merge 2 commits into
mainfrom
test/issue-1847-alertdialog-lazy-mount

Conversation

@kotAPI

@kotAPI kotAPI commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Adds tests verifying alert dialog content is not mounted until opened.\n\nRelated to #1847

Summary by CodeRabbit

  • Tests
    • Added coverage for dialog lazy-mount behavior.
    • Verified dialog content stays out of the page until opened, and appears when the dialog is open.
    • Stabilized dialog rendering in tests for more reliable results.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A new test file is added for AlertDialog that mocks window.matchMedia and contains two tests: one asserting that dialog content is absent from the DOM when the dialog is closed, and another asserting that content is present when the dialog is rendered with open.

Changes

AlertDialog Lazy Mount Tests

Layer / File(s) Summary
AlertDialog lazy mount test suite
src/components/ui/AlertDialog/tests/AlertDialog.lazyMount.test.tsx
Adds two tests rendered within Theme: one checks that AlertDialog.Content children are not in the DOM before the dialog opens, and one checks that the description text appears when AlertDialog.Root has open set. Includes a window.matchMedia mock for stable dialog rendering.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 Hop, hop — the dialog sleeps,
Content hidden in DOM's deeps.
Open the latch, and there it grows,
Text appearing as the test shows.
A lazy mount, a tidy check —
No broken dialogs on my deck! ✨

🚥 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 change: adding AlertDialog lazy-mount tests for dialog content.
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-1847-alertdialog-lazy-mount

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

@changeset-bot

changeset-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7203075

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

Align lazy mount coverage with portal/theme test setup used elsewhere.
@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.

🧹 Nitpick comments (1)
src/components/ui/AlertDialog/tests/AlertDialog.lazyMount.test.tsx (1)

6-16: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Normalize matchMedia even when it already exists.

The early return makes this suite depend on whatever jsdom provides. Since Theme calls addEventListener/removeEventListener, patch missing methods (or always override in this suite) to keep tests deterministic across environments.

Suggested change
 const mockMatchMedia = () => {
-    if ('matchMedia' in window && typeof window.matchMedia === 'function') return;
-    Object.defineProperty(window, 'matchMedia', {
+    const existing = window.matchMedia?.bind(window);
+    Object.defineProperty(window, 'matchMedia', {
         writable: true,
-        value: jest.fn().mockImplementation(() => ({
-            matches: false,
-            addEventListener: jest.fn(),
-            removeEventListener: jest.fn()
-        }))
+        value: jest.fn().mockImplementation((query: string) => {
+            const base = existing?.(query) ?? ({ matches: false } as MediaQueryList);
+            return {
+                ...base,
+                addEventListener: base.addEventListener ?? jest.fn(),
+                removeEventListener: base.removeEventListener ?? jest.fn()
+            };
+        })
     });
 };
🤖 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/AlertDialog/tests/AlertDialog.lazyMount.test.tsx` around
lines 6 - 16, The mockMatchMedia helper in AlertDialog.lazyMount.test.tsx
currently returns early when window.matchMedia already exists, which leaves the
suite dependent on the jsdom implementation. Update mockMatchMedia to always
normalize matchMedia for this test suite, or extend the existing
window.matchMedia so it always provides addEventListener and removeEventListener
for Theme, keeping the AlertDialog tests deterministic across environments.
🤖 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.

Nitpick comments:
In `@src/components/ui/AlertDialog/tests/AlertDialog.lazyMount.test.tsx`:
- Around line 6-16: The mockMatchMedia helper in AlertDialog.lazyMount.test.tsx
currently returns early when window.matchMedia already exists, which leaves the
suite dependent on the jsdom implementation. Update mockMatchMedia to always
normalize matchMedia for this test suite, or extend the existing
window.matchMedia so it always provides addEventListener and removeEventListener
for Theme, keeping the AlertDialog tests deterministic across environments.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f0759ef8-eebc-4c17-b2d5-f47ed8f42090

📥 Commits

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

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

@kotAPI

kotAPI commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

Code review

Reviewed and pushed follow-up fixes addressing handler composition, test patterns (rerender vs unmount), Theme/mockMatchMedia wrappers, and flaky focus assertions.

CI was green before fixes; please re-run checks on latest commit.

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