-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModal.test.tsx
More file actions
52 lines (42 loc) · 1.55 KB
/
Copy pathModal.test.tsx
File metadata and controls
52 lines (42 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// @vitest-environment jsdom
import React from 'react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { cleanup, render, screen } from '@testing-library/react';
import { Modal, ModalBody } from './Modal';
afterEach(() => {
cleanup();
});
function renderOpenModal(props: Partial<React.ComponentProps<typeof Modal>> = {}) {
const onClose = vi.fn();
render(
<Modal open onClose={onClose} {...props}>
<ModalBody>Modal content</ModalBody>
</Modal>
);
return { onClose };
}
describe('Modal panel API', () => {
it('applies className, panelClassName, and style to the dialog panel', () => {
renderOpenModal({
className: 'consumer-panel',
panelClassName: 'batch-run-panel',
style: { maxWidth: 520 },
});
const panel = screen.getByRole('dialog');
expect(panel.classList.contains('oc-modal')).toBe(true);
expect(panel.classList.contains('consumer-panel')).toBe(true);
expect(panel.classList.contains('batch-run-panel')).toBe(true);
expect((panel as HTMLElement).style.maxWidth).toBe('520px');
});
it('keeps overlayClassName scoped to the backdrop overlay', () => {
renderOpenModal({
panelClassName: 'consumer-panel',
overlayClassName: 'consumer-overlay',
});
const panel = screen.getByRole('dialog');
const overlay = panel.parentElement;
expect(panel.classList.contains('consumer-overlay')).toBe(false);
expect(overlay?.classList.contains('consumer-overlay')).toBe(true);
expect(overlay?.classList.contains('consumer-panel')).toBe(false);
});
});