From 501cee07259840c345f37077c14b3d62afe07f97 Mon Sep 17 00:00:00 2001 From: Pranay Kothapalli Date: Tue, 23 Jun 2026 18:56:20 +0530 Subject: [PATCH] test(dialog): lazy mount and forceMount behavior Add regression tests for default lazy mounting and forceMount keeping dialog content in the DOM while closed. Related to #1847 --- .../ui/Dialog/tests/Dialog.lazyMount.test.tsx | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/components/ui/Dialog/tests/Dialog.lazyMount.test.tsx diff --git a/src/components/ui/Dialog/tests/Dialog.lazyMount.test.tsx b/src/components/ui/Dialog/tests/Dialog.lazyMount.test.tsx new file mode 100644 index 000000000..ce5ca5b5d --- /dev/null +++ b/src/components/ui/Dialog/tests/Dialog.lazyMount.test.tsx @@ -0,0 +1,52 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import Dialog from '../Dialog'; +import Theme from '~/components/ui/Theme/Theme'; + +const mockMatchMedia = () => { + if ('matchMedia' in window && typeof window.matchMedia === 'function') return; + Object.defineProperty(window, 'matchMedia', { + writable: true, + value: jest.fn().mockImplementation(() => ({ + matches: false, + addEventListener: jest.fn(), + removeEventListener: jest.fn() + })) + }); +}; + +describe('Dialog lazy mount behavior', () => { + beforeEach(() => mockMatchMedia()); + + test('does not mount content while closed by default', () => { + render( + + + Open + + Hidden dialog + + + + ); + + expect(screen.getByText('Open')).toBeInTheDocument(); + expect(screen.queryByText('Hidden dialog')).not.toBeInTheDocument(); + }); + + test('forceMount keeps content mounted while closed', () => { + render( + + + Open + + Mounted dialog + + + + ); + + expect(screen.getByText('Mounted dialog')).toBeInTheDocument(); + expect(screen.getByText('Mounted dialog')).toHaveAttribute('data-state', 'closed'); + }); +});