Skip to content

Commit a18b204

Browse files
GregOnNetGregor Woiwode
authored and
Gregor Woiwode
committed
test(dialog): provide basic tests
1 parent aa7cf41 commit a18b204

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

Diff for: packages/kit-headless/src/components/dialog/dialog.spec.tsx

+38-5
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,51 @@ import * as Dialog from './dialog';
44
describe('Dialog', () => {
55
it('renders an opened Dialog', () => {
66
mount(
7-
<Dialog.Root open={true}>
8-
<h2>Hello World!</h2>
7+
<Dialog.Root>
8+
<Dialog.Trigger>
9+
<button>Open</button>
10+
</Dialog.Trigger>
11+
<Dialog.Portal>
12+
<h2 data-test="dialog-title">Hello World!</h2>
13+
</Dialog.Portal>
914
</Dialog.Root>
1015
);
1116

12-
cy.get('dialog').should('contain', 'Hello World');
17+
cy.get('button').contains(/open/i).click();
18+
19+
cy.get('[data-test=dialog-title]')
20+
.should('be.visible')
21+
.should('contain', 'Hello World');
22+
});
23+
24+
it('closes on backdrop-click', () => {
25+
mount(
26+
<Dialog.Root>
27+
<Dialog.Trigger>
28+
<button>Open</button>
29+
</Dialog.Trigger>
30+
<Dialog.Portal>
31+
<h2 data-test="dialog-title">Hello World!</h2>
32+
</Dialog.Portal>
33+
</Dialog.Root>
34+
);
35+
36+
cy.get('button').contains(/open/i).click();
37+
38+
cy.get('dialog').click('top');
39+
40+
cy.get('dialog').should('not.be.visible');
1341
});
1442

1543
it('does not show if Dialog is closed', () => {
1644
mount(
17-
<Dialog.Root open={false}>
18-
<h2>Hello World!</h2>
45+
<Dialog.Root>
46+
<Dialog.Trigger>
47+
<button>Open</button>
48+
</Dialog.Trigger>
49+
<Dialog.Portal>
50+
<h2>Hello World!</h2>
51+
</Dialog.Portal>
1952
</Dialog.Root>
2053
);
2154

0 commit comments

Comments
 (0)