import { render, screen } from '@testing-library/react';
import { DrawerPanelContent } from '../DrawerPanelContent';
import { Drawer } from '../Drawer';
import styles from '@patternfly/react-styles/css/components/Drawer/drawer';
test(`Renders with only class ${styles.drawerPanel} by default`, () => {
render(
Drawer panel content
);
expect(screen.getByText('Drawer panel content')).toHaveClass(styles.drawerPanel, { exact: true });
});
test(`Renders with class ${styles.modifiers.noBackground} when deprecated colorVariant="no-background" is used`, () => {
render(
Drawer panel content
);
expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.noBackground);
});
test(`Renders with class ${styles.modifiers.secondary} when colorVariant="secondary"`, () => {
render(
Drawer panel content
);
expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.secondary);
});
jest.mock('../../../helpers/GenerateId/GenerateId');
jest.mock('../../../helpers/GenerateId/GenerateId');
test('Does not render with aria-labelledby by default', () => {
render(
Drawer panel content
);
expect(screen.getByText('Drawer panel content')).not.toHaveAccessibleName();
});
test('Renders with aria-labelledby when focusTrap.enabled is true', () => {
render(
Drawer panel content
);
expect(screen.getByText('Drawer panel content')).toHaveAccessibleName('Drawer panel content');
});
test('Renders with aria-labelledby when id is passed in', () => {
render(
Drawer panel content
);
expect(screen.getByText('Drawer panel content')).toHaveAccessibleName('Drawer panel content');
});
test('Renders with custom aria-labelledby', () => {
render(
Title
Drawer panel content
);
expect(screen.getByText('Drawer panel content').parentElement).toHaveAccessibleName('Title');
});
test('Does not render with aria-modal="true" by default', () => {
render(
Drawer panel content
);
expect(screen.getByText('Drawer panel content')).not.toHaveAttribute('aria-modal');
});
test('Renders with aria-modal="true" when focusTrap.enabled is true', () => {
render(
Drawer panel content
);
expect(screen.getByText('Drawer panel content')).toHaveAttribute('aria-modal', 'true');
});
test('Does not render with role="dialog" by default', () => {
render(
Drawer panel content
);
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
});
test('Renders with role="dialog" when focusTrap.enabled is true', () => {
render(
Drawer panel content
);
expect(screen.getByRole('dialog')).toBeInTheDocument();
});
test('Does not render with inert when drawer is expanded', () => {
render(
Drawer panel content
);
expect(screen.getByTestId('drawer-content')).not.toHaveAttribute('inert');
});
test('Renders with inert when drawer is collapsed', () => {
render(
Drawer panel content
);
expect(screen.getByTestId('drawer-content')).toHaveAttribute('inert');
});
test('Applies style prop as expected', () => {
render(
Drawer panel content
);
const panelContent = screen.getByText('Drawer panel content');
expect(panelContent).toHaveStyle({ backgroundColor: 'red', padding: '20px' });
});
test('Style prop overrides boundaryCssVars', () => {
render(
Drawer panel content
);
const panelContent = screen.getByText('Drawer panel content');
expect(panelContent).toHaveStyle({
'--pf-v6-c-drawer__panel--md--FlexBasis': '300px',
'--pf-v6-c-drawer__panel--md--FlexBasis--min': '150px',
'--pf-v6-c-drawer__panel--md--FlexBasis--max': '500px'
});
});
test(`Renders with class 'pf-m-no-glass' when hasNoGlass is true`, () => {
render(
Drawer panel content
);
expect(screen.getByText('Drawer panel content')).toHaveClass('pf-m-no-glass');
});
test(`Renders with class ${styles.modifiers.glass} when isGlass is true`, () => {
render(
Drawer panel content
);
expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.glass);
});
test(`Renders with class ${styles.modifiers.plain} when isPlain is true`, () => {
render(
Drawer panel content
);
expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.plain);
});
test(`Renders with class ${styles.modifiers.noPlainOnGlass} when isNoPlainOnGlass is true`, () => {
render(
Drawer panel content
);
expect(screen.getByText('Drawer panel content')).toHaveClass(styles.modifiers.noPlainOnGlass);
});