|
1
|
import React from "react" |
|
2
|
import { beforeEach, describe, expect, test, vi } from "vitest" |
|
3
|
import { render } from "@testing-library/react" |
|
4
|
|
|
5
|
// mock components |
|
6
|
vi.mock("@/components/Note/Types/default", () => ({ |
|
7
|
DefaultNote: ({ |
|
8
|
children, |
|
9
|
title, |
|
10
|
}: { |
|
11
|
children?: React.ReactNode |
|
12
|
title?: string |
|
13
|
}) => ( |
|
14
|
<div data-testid="default-note" data-title={title}> |
|
15
|
{children} |
|
16
|
</div> |
|
17
|
), |
|
18
|
})) |
|
19
|
|
|
20
|
vi.mock("@/components/Note/Types/warning", () => ({ |
|
21
|
WarningNote: ({ |
|
22
|
children, |
|
23
|
title, |
|
24
|
}: { |
|
25
|
children?: React.ReactNode |
|
26
|
title?: string |
|
27
|
}) => ( |
|
28
|
<div data-testid="warning-note" data-title={title}> |
|
29
|
{children} |
|
30
|
</div> |
|
31
|
), |
|
32
|
})) |
|
33
|
|
|
34
|
vi.mock("@/components/Note/Types/sucess", () => ({ |
|
35
|
SuccessNote: ({ |
|
36
|
children, |
|
37
|
title, |
|
38
|
}: { |
|
39
|
children?: React.ReactNode |
|
40
|
title?: string |
|
41
|
}) => ( |
|
42
|
<div data-testid="success-note" data-title={title}> |
|
43
|
{children} |
|
44
|
</div> |
|
45
|
), |
|
46
|
})) |
|
47
|
|
|
48
|
vi.mock("@/components/Note/Types/error", () => ({ |
|
49
|
ErrorNote: ({ |
|
50
|
children, |
|
51
|
title, |
|
52
|
}: { |
|
53
|
children?: React.ReactNode |
|
54
|
title?: string |
|
55
|
}) => ( |
|
56
|
<div data-testid="error-note" data-title={title}> |
|
57
|
{children} |
|
58
|
</div> |
|
59
|
), |
|
60
|
})) |
|
61
|
|
|
62
|
vi.mock("@/components/Note/Types/checks", () => ({ |
|
63
|
CheckNote: ({ |
|
64
|
children, |
|
65
|
title, |
|
66
|
}: { |
|
67
|
children?: React.ReactNode |
|
68
|
title?: string |
|
69
|
}) => ( |
|
70
|
<div data-testid="check-note" data-title={title}> |
|
71
|
{children} |
|
72
|
</div> |
|
73
|
), |
|
74
|
})) |
|
75
|
|
|
76
|
vi.mock("@/components/Note/Types/soon", () => ({ |
|
77
|
SoonNote: ({ |
|
78
|
children, |
|
79
|
title, |
|
80
|
}: { |
|
81
|
children?: React.ReactNode |
|
82
|
title?: string |
|
83
|
}) => ( |
|
84
|
<div data-testid="soon-note" data-title={title}> |
|
85
|
{children} |
|
86
|
</div> |
|
87
|
), |
|
88
|
})) |
|
89
|
|
|
90
|
import { Note } from "../../Note" |
|
91
|
|
|
92
|
beforeEach(() => { |
|
93
|
vi.clearAllMocks() |
|
94
|
}) |
|
95
|
|
|
96
|
describe("rendering", () => { |
|
97
|
test("renders default note by default", () => { |
|
98
|
const { container } = render(<Note>Content</Note>) |
|
99
|
const defaultNote = container.querySelector("[data-testid='default-note']") |
|
100
|
expect(defaultNote).toBeInTheDocument() |
|
101
|
}) |
|
102
|
|
|
103
|
test("renders default note when type is default", () => { |
|
104
|
const { container } = render(<Note type="default">Content</Note>) |
|
105
|
const defaultNote = container.querySelector("[data-testid='default-note']") |
|
106
|
expect(defaultNote).toBeInTheDocument() |
|
107
|
}) |
|
108
|
|
|
109
|
test("renders warning note when type is warning", () => { |
|
110
|
const { container } = render(<Note type="warning">Content</Note>) |
|
111
|
const warningNote = container.querySelector("[data-testid='warning-note']") |
|
112
|
expect(warningNote).toBeInTheDocument() |
|
113
|
}) |
|
114
|
|
|
115
|
test("renders success note when type is success", () => { |
|
116
|
const { container } = render(<Note type="success">Content</Note>) |
|
117
|
const successNote = container.querySelector("[data-testid='success-note']") |
|
118
|
expect(successNote).toBeInTheDocument() |
|
119
|
}) |
|
120
|
|
|
121
|
test("renders error note when type is error", () => { |
|
122
|
const { container } = render(<Note type="error">Content</Note>) |
|
123
|
const errorNote = container.querySelector("[data-testid='error-note']") |
|
124
|
expect(errorNote).toBeInTheDocument() |
|
125
|
}) |
|
126
|
|
|
127
|
test("renders check note when type is check", () => { |
|
128
|
const { container } = render(<Note type="check">Content</Note>) |
|
129
|
const checkNote = container.querySelector("[data-testid='check-note']") |
|
130
|
expect(checkNote).toBeInTheDocument() |
|
131
|
}) |
|
132
|
|
|
133
|
test("renders soon note when type is soon", () => { |
|
134
|
const { container } = render(<Note type="soon">Content</Note>) |
|
135
|
const soonNote = container.querySelector("[data-testid='soon-note']") |
|
136
|
expect(soonNote).toBeInTheDocument() |
|
137
|
}) |
|
138
|
|
|
139
|
test("passes children to note component", () => { |
|
140
|
const { container } = render(<Note>Test Content</Note>) |
|
141
|
expect(container).toHaveTextContent("Test Content") |
|
142
|
}) |
|
143
|
|
|
144
|
test("passes title to note component", () => { |
|
145
|
const { container } = render(<Note title="Custom Title">Content</Note>) |
|
146
|
const note = container.querySelector("[data-testid='default-note']") |
|
147
|
expect(note).toHaveAttribute("data-title", "Custom Title") |
|
148
|
}) |
|
149
|
|
|
150
|
test("passes forceMultiline to note component", () => { |
|
151
|
const { container } = render(<Note forceMultiline={true}>Content</Note>) |
|
152
|
const note = container.querySelector("[data-testid='default-note']") |
|
153
|
expect(note).toBeInTheDocument() |
|
154
|
}) |
|
155
|
}) |