diff --git a/packages/react/src/accordion/root/AccordionRoot.test.tsx b/packages/react/src/accordion/root/AccordionRoot.test.tsx index ed0d42860c..5864f84278 100644 --- a/packages/react/src/accordion/root/AccordionRoot.test.tsx +++ b/packages/react/src/accordion/root/AccordionRoot.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { expect } from 'chai'; import { spy } from 'sinon'; -import { flushMicrotasks } from '@mui/internal-test-utils'; import { DirectionProvider } from '@base-ui-components/react/direction-provider'; import { Accordion } from '@base-ui-components/react/accordion'; import { createRenderer, describeConformance, isJSDOM } from '#test-utils'; @@ -149,8 +148,7 @@ describe('', () => { expect(trigger).to.have.attribute('aria-expanded', 'false'); expect(queryByText(PANEL_CONTENT_1)).to.equal(null); - setProps({ value: [0] }); - await flushMicrotasks(); + await setProps({ value: [0] }); expect(trigger).to.have.attribute('aria-expanded', 'true'); expect(trigger).to.have.attribute('data-panel-open'); @@ -158,8 +156,7 @@ describe('', () => { expect(queryByText(PANEL_CONTENT_1)).toBeVisible(); expect(queryByText(PANEL_CONTENT_1)).to.have.attribute('data-open'); - setProps({ value: [] }); - await flushMicrotasks(); + await setProps({ value: [] }); expect(trigger).to.have.attribute('aria-expanded', 'false'); expect(queryByText(PANEL_CONTENT_1)).to.equal(null); diff --git a/packages/react/src/alert-dialog/root/AlertDialogRoot.test.tsx b/packages/react/src/alert-dialog/root/AlertDialogRoot.test.tsx index f4dbee48a1..0b572d37a6 100644 --- a/packages/react/src/alert-dialog/root/AlertDialogRoot.test.tsx +++ b/packages/react/src/alert-dialog/root/AlertDialogRoot.test.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { expect } from 'chai'; import { act, screen, waitFor } from '@mui/internal-test-utils'; import { AlertDialog } from '@base-ui-components/react/alert-dialog'; -import { createRenderer, isJSDOM } from '#test-utils'; +import { createRenderer, isJSDOM, popupConformanceTests } from '#test-utils'; import { spy } from 'sinon'; describe('', () => { @@ -12,6 +12,20 @@ describe('', () => { globalThis.BASE_UI_ANIMATIONS_DISABLED = true; }); + popupConformanceTests({ + createComponent: (props) => ( + + Open dialog + + Dialog + + + ), + render, + triggerMouseAction: 'click', + expectedPopupRole: 'alertdialog', + }); + it('ARIA attributes', async () => { const { queryByRole, getByText } = await render( diff --git a/packages/react/src/checkbox/root/CheckboxRoot.test.tsx b/packages/react/src/checkbox/root/CheckboxRoot.test.tsx index c7f74e7e23..e3b0c4e7b9 100644 --- a/packages/react/src/checkbox/root/CheckboxRoot.test.tsx +++ b/packages/react/src/checkbox/root/CheckboxRoot.test.tsx @@ -201,7 +201,7 @@ describe('', () => { expect(indicator).to.have.attribute('data-readonly', ''); expect(indicator).to.have.attribute('data-required', ''); - setProps({ disabled: false, readOnly: false }); + await setProps({ disabled: false, readOnly: false }); fireEvent.click(checkbox); expect(checkbox).to.have.attribute('data-unchecked', ''); diff --git a/packages/react/src/collapsible/root/CollapsibleRoot.test.tsx b/packages/react/src/collapsible/root/CollapsibleRoot.test.tsx index f09c088559..069f9b99e6 100644 --- a/packages/react/src/collapsible/root/CollapsibleRoot.test.tsx +++ b/packages/react/src/collapsible/root/CollapsibleRoot.test.tsx @@ -1,7 +1,6 @@ 'use client'; import * as React from 'react'; import { expect } from 'chai'; -import { flushMicrotasks } from '@mui/internal-test-utils'; import { Collapsible } from '@base-ui-components/react/collapsible'; import { createRenderer, describeConformance, isJSDOM } from '#test-utils'; @@ -48,8 +47,7 @@ describe('', () => { expect(trigger).to.have.attribute('aria-expanded', 'false'); expect(queryByText(PANEL_CONTENT)).to.equal(null); - setProps({ open: true }); - await flushMicrotasks(); + await setProps({ open: true }); expect(trigger).to.have.attribute('aria-expanded', 'true'); @@ -58,8 +56,7 @@ describe('', () => { expect(queryByText(PANEL_CONTENT)).to.have.attribute('data-open'); expect(trigger).to.have.attribute('data-panel-open'); - setProps({ open: false }); - await flushMicrotasks(); + await setProps({ open: false }); expect(trigger).to.not.have.attribute('aria-controls'); expect(trigger).to.have.attribute('aria-expanded', 'false'); diff --git a/packages/react/src/dialog/root/DialogRoot.test.tsx b/packages/react/src/dialog/root/DialogRoot.test.tsx index 9683c2aa5e..1f8ace8a7d 100644 --- a/packages/react/src/dialog/root/DialogRoot.test.tsx +++ b/packages/react/src/dialog/root/DialogRoot.test.tsx @@ -3,16 +3,30 @@ import { expect } from 'chai'; import { spy } from 'sinon'; import { act, fireEvent, screen, waitFor } from '@mui/internal-test-utils'; import { Dialog } from '@base-ui-components/react/dialog'; -import { createRenderer, isJSDOM } from '#test-utils'; +import { createRenderer, isJSDOM, popupConformanceTests } from '#test-utils'; import { Menu } from '@base-ui-components/react/menu'; import { Select } from '@base-ui-components/react/select'; describe('', () => { + const { render } = createRenderer(); + beforeEach(() => { globalThis.BASE_UI_ANIMATIONS_DISABLED = true; }); - const { render } = createRenderer(); + popupConformanceTests({ + createComponent: (props) => ( + + Open dialog + + Dialog + + + ), + render, + triggerMouseAction: 'click', + expectedPopupRole: 'dialog', + }); it('ARIA attributes', async () => { const { queryByRole, getByText } = await render( @@ -40,139 +54,6 @@ describe('', () => { ); }); - describe('uncontrolled mode', () => { - it('should open the dialog with the trigger', async () => { - const { queryByRole, getByRole } = await render( - - - - - - , - ); - - const button = getByRole('button'); - expect(queryByRole('dialog')).to.equal(null); - - await act(async () => { - button.click(); - }); - - expect(queryByRole('dialog')).not.to.equal(null); - }); - }); - - describe('controlled mode', () => { - it('should open and close the dialog with the `open` prop', async () => { - const { queryByRole, setProps } = await render( - - - - - , - ); - - expect(queryByRole('dialog')).to.equal(null); - - setProps({ open: true }); - expect(queryByRole('dialog')).not.to.equal(null); - - setProps({ open: false }); - expect(queryByRole('dialog')).to.equal(null); - }); - - it('should remove the popup when there is no exit animation defined', async ({ skip }) => { - if (isJSDOM) { - skip(); - } - - function Test() { - const [open, setOpen] = React.useState(true); - - return ( -
- - - - - - -
- ); - } - - const { user } = await render(); - - const closeButton = screen.getByText('Close'); - await user.click(closeButton); - - await waitFor(() => { - expect(screen.queryByRole('dialog')).to.equal(null); - }); - }); - - it('should remove the popup when the animation finishes', async ({ skip }) => { - if (isJSDOM) { - skip(); - } - - globalThis.BASE_UI_ANIMATIONS_DISABLED = false; - - let animationFinished = false; - const notifyAnimationFinished = () => { - animationFinished = true; - }; - - function Test() { - const style = ` - @keyframes test-anim { - to { - opacity: 0; - } - } - - .animation-test-popup[data-open] { - opacity: 1; - } - - .animation-test-popup[data-ending-style] { - animation: test-anim 1ms; - } - `; - - const [open, setOpen] = React.useState(true); - - return ( -
- {/* eslint-disable-next-line react/no-danger */} -