-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdialog.test.tsx
134 lines (122 loc) · 3.41 KB
/
dialog.test.tsx
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { render, screen } from "@testing-library/react";
import { createRef } from "react";
import { describe, expect, it } from "vitest";
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "./dialog";
describe("DialogHeader", () => {
it("renders without crashing", () => {
render(
<Dialog open>
<DialogHeader />
</Dialog>,
);
const dialogHeaderElement = screen.getByTestId("dialog-header");
expect(dialogHeaderElement).toBeInTheDocument();
});
it("renders children", () => {
render(
<Dialog open>
<DialogHeader>children</DialogHeader>
</Dialog>,
);
const dialogContentElement = screen.getByText("children");
expect(dialogContentElement).toBeInTheDocument();
});
});
describe("DialogTitle", () => {
it("renders without crashing", () => {
render(
<Dialog open>
<DialogTitle />
</Dialog>,
);
const dialogTitleElement = screen.getByTestId("dialog-title");
expect(dialogTitleElement).toBeInTheDocument();
});
it("renders children", () => {
render(
<Dialog open>
<DialogTitle>children</DialogTitle>
</Dialog>,
);
const dialogTitleElement = screen.getByText("children");
expect(dialogTitleElement).toBeInTheDocument();
});
});
describe("DialogDescription", () => {
it("renders without crashing", () => {
render(
<Dialog open>
<DialogDescription />
</Dialog>,
);
const dialogDescriptionElement = screen.getByTestId("dialog-description");
expect(dialogDescriptionElement).toBeInTheDocument();
});
it("renders children", () => {
render(
<Dialog open>
<DialogDescription>children</DialogDescription>
</Dialog>,
);
const dialogDescriptionElement = screen.getByText("children");
expect(dialogDescriptionElement).toBeInTheDocument();
});
});
describe("DialogFooter", () => {
it("renders without crashing", () => {
render(
<Dialog open>
<DialogFooter />
</Dialog>,
);
const dialogFooterElement = screen.getByTestId("dialog-footer");
expect(dialogFooterElement).toBeInTheDocument();
});
it("renders children", () => {
render(
<Dialog open>
<DialogFooter>children</DialogFooter>
</Dialog>,
);
const dialogFooterElement = screen.getByText("children");
expect(dialogFooterElement).toBeInTheDocument();
});
});
describe("DialogContent", () => {
it("renders without crashing", () => {
render(
<Dialog open>
<DialogContent />
</Dialog>,
);
const dialogContentElement = screen.getByTestId("dialog-content");
expect(dialogContentElement).toBeInTheDocument();
});
it("forwards ref correctly", () => {
const ref = createRef<HTMLDivElement>();
render(
<Dialog open>
<DialogContent ref={ref} />
</Dialog>,
);
expect(ref.current).not.toBeNull();
});
it("renders DialogPrimitive.Close button", () => {
render(
<Dialog open>
<DialogContent />
</Dialog>,
);
const closeButtonElement = screen.getByRole("button");
expect(closeButtonElement).toBeInTheDocument();
});
it("renders DialogOverlay", () => {
render(
<Dialog open>
<DialogContent />
</Dialog>,
);
const dialogOverlayElement = screen.getByTestId("dialog-overlay");
expect(dialogOverlayElement).toBeInTheDocument();
});
});