-
-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathMarkdownComponents_.test.res
More file actions
374 lines (300 loc) · 11.2 KB
/
MarkdownComponents_.test.res
File metadata and controls
374 lines (300 loc) · 11.2 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
open ReactRouter
open Vitest
test("renders headings h1 through h5", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="headings-wrapper">
<Markdown.H1> {React.string("Heading Level 1")} </Markdown.H1>
<Markdown.H2 id="heading-2"> {React.string("Heading Level 2")} </Markdown.H2>
<Markdown.H3 id="heading-3"> {React.string("Heading Level 3")} </Markdown.H3>
<Markdown.H4 id="heading-4"> {React.string("Heading Level 4")} </Markdown.H4>
<Markdown.H5 id="heading-5"> {React.string("Heading Level 5")} </Markdown.H5>
</div>,
)
let heading1 = await screen->getByText("Heading Level 1")
await element(heading1)->toBeVisible
let wrapper = await screen->getByTestId("headings-wrapper")
await element(wrapper)->toMatchScreenshot("markdown-headings")
})
test("renders paragraph, strong, and intro", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="text-wrapper">
<Markdown.Intro> {React.string("This is an introduction paragraph.")} </Markdown.Intro>
<Markdown.P>
{React.string("This is a regular paragraph with ")}
<Markdown.Strong> {React.string("bold text")} </Markdown.Strong>
{React.string(" inside it.")}
</Markdown.P>
</div>,
)
let intro = await screen->getByText("This is an introduction paragraph.")
await element(intro)->toBeVisible
let wrapper = await screen->getByTestId("text-wrapper")
await element(wrapper)->toMatchScreenshot("markdown-text-elements")
})
test("renders Info and Warn admonitions", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="admonitions-wrapper">
<Markdown.Info>
<Markdown.P> {React.string("This is an informational message.")} </Markdown.P>
</Markdown.Info>
<Markdown.Warn>
<Markdown.P> {React.string("This is a warning message.")} </Markdown.P>
</Markdown.Warn>
</div>,
)
let infoMsg = await screen->getByText("This is an informational message.")
await element(infoMsg)->toBeVisible
let warnMsg = await screen->getByText("This is a warning message.")
await element(warnMsg)->toBeVisible
let wrapper = await screen->getByTestId("admonitions-wrapper")
await element(wrapper)->toMatchScreenshot("markdown-admonitions")
})
test("renders Cite with author", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="cite-wrapper">
<Markdown.Cite author=Some("Jane Doe")>
{React.string("ReScript is the future of typed JavaScript.")}
</Markdown.Cite>
</div>,
)
let author = await screen->getByText("Jane Doe")
await element(author)->toBeVisible
let quote = await screen->getByText("ReScript is the future of typed JavaScript.")
await element(quote)->toBeVisible
let wrapper = await screen->getByTestId("cite-wrapper")
await element(wrapper)->toMatchScreenshot("markdown-cite")
})
test("renders blockquote", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="blockquote-wrapper">
<Markdown.Blockquote>
<Markdown.P> {React.string("This is a blockquote with some important text.")} </Markdown.P>
</Markdown.Blockquote>
</div>,
)
let text = await screen->getByText("This is a blockquote with some important text.")
await element(text)->toBeVisible
let wrapper = await screen->getByTestId("blockquote-wrapper")
await element(wrapper)->toMatchScreenshot("markdown-blockquote")
})
test("renders lists", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="lists-wrapper">
<Markdown.Ul>
<Markdown.Li> {React.string("Apple")} </Markdown.Li>
<Markdown.Li> {React.string("Banana")} </Markdown.Li>
</Markdown.Ul>
<Markdown.Ol>
<Markdown.Li> {React.string("First step")} </Markdown.Li>
<Markdown.Li> {React.string("Second step")} </Markdown.Li>
</Markdown.Ol>
</div>,
)
let unorderedItem = await screen->getByText("Apple")
await element(unorderedItem)->toBeVisible
let orderedItem = await screen->getByText("First step")
await element(orderedItem)->toBeVisible
let wrapper = await screen->getByTestId("lists-wrapper")
await element(wrapper)->toMatchScreenshot("markdown-lists")
})
test("renders table", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="table-wrapper">
<Markdown.Table>
<Markdown.Thead>
<tr>
<Markdown.Th> {React.string("Name")} </Markdown.Th>
<Markdown.Th> {React.string("Type")} </Markdown.Th>
</tr>
</Markdown.Thead>
<tbody>
<tr>
<Markdown.Td> {React.string("foo")} </Markdown.Td>
<Markdown.Td> {React.string("string")} </Markdown.Td>
</tr>
<tr>
<Markdown.Td> {React.string("bar")} </Markdown.Td>
<Markdown.Td> {React.string("int")} </Markdown.Td>
</tr>
</tbody>
</Markdown.Table>
</div>,
)
let nameHeader = await screen->getByText("Name")
await element(nameHeader)->toBeVisible
let fooCell = await screen->getByText("foo")
await element(fooCell)->toBeVisible
let wrapper = await screen->getByTestId("table-wrapper")
await element(wrapper)->toMatchScreenshot("markdown-table")
})
test("renders links", async () => {
await viewport(1440, 900)
let screen = await render(
<BrowserRouter>
<div dataTestId="links-wrapper">
<Markdown.P>
<Markdown.A href="https://rescript-lang.org">
{React.string("External link")}
</Markdown.A>
</Markdown.P>
<Markdown.P>
<Markdown.A href="/docs/manual/introduction">
{React.string("Internal link")}
</Markdown.A>
</Markdown.P>
</div>
</BrowserRouter>,
)
let externalLink = await screen->getByText("External link")
await element(externalLink)->toBeVisible
let internalLink = await screen->getByText("Internal link")
await element(internalLink)->toBeVisible
let wrapper = await screen->getByTestId("links-wrapper")
await element(wrapper)->toMatchScreenshot("markdown-links")
})
test("renders Image with caption", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="image-wrapper">
<Markdown.Image
className="rounded-lg border border-gray-90/5 text-gray-60"
src="/lp/community-3.avif"
caption="A sample image caption"
/>
</div>,
)
let caption = await screen->getByText("A sample image caption")
await element(caption)->toBeVisible
let wrapper = await screen->getByTestId("image-wrapper")
await waitForImages("[data-testid='image-wrapper']")
await element(wrapper)->toMatchScreenshot("markdown-image")
})
test("renders Video with caption", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="video-wrapper">
<Markdown.Video src="https://player.vimeo.com/video/477758754" caption="A sample video" />
</div>,
)
let caption = await screen->getByText("A sample video")
await element(caption)->toBeVisible
})
test("renders horizontal rule", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="hr-wrapper">
<Markdown.P> {React.string("Content above the rule.")} </Markdown.P>
<Markdown.Hr />
<Markdown.P> {React.string("Content below the rule.")} </Markdown.P>
</div>,
)
let above = await screen->getByText("Content above the rule.")
await element(above)->toBeVisible
let below = await screen->getByText("Content below the rule.")
await element(below)->toBeVisible
let wrapper = await screen->getByTestId("hr-wrapper")
await element(wrapper)->toMatchScreenshot("markdown-hr")
})
test("renders inline code", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="inline-code-wrapper">
<Markdown.P>
{React.string("Use ")}
<code
className="md-inline-code px-2 py-0.5 text-gray-60 font-mono rounded-sm bg-gray-10-tr border border-gray-90/5"
>
{React.string("Array.map")}
</code>
{React.string(" to transform elements.")}
</Markdown.P>
</div>,
)
let code = await screen->getByText("Array.map")
await element(code)->toBeVisible
let wrapper = await screen->getByTestId("inline-code-wrapper")
await element(wrapper)->toMatchScreenshot("markdown-inline-code")
})
test("renders Anchor with link icon", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="anchor-wrapper">
<Markdown.H2 id="test-section"> {React.string("Test Section")} </Markdown.H2>
</div>,
)
let heading = await screen->getByText("Test Section")
await element(heading)->toBeVisible
let wrapper = await screen->getByTestId("anchor-wrapper")
await element(wrapper)->toMatchScreenshot("markdown-anchor")
})
test("renders Image with small size", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="image-small-wrapper">
<Markdown.Image
src="https://rescript-lang.org/brand/rescript-brandmark.svg"
size=#small
caption="Small image"
/>
</div>,
)
let caption = await screen->getByText("Small image")
await element(caption)->toBeVisible
let wrapper = await screen->getByTestId("image-small-wrapper")
await element(wrapper)->toMatchScreenshot("markdown-image-small")
})
test("renders Cite without author", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="cite-no-author-wrapper">
<Markdown.Cite author=None>
{React.string("An anonymous quote about functional programming.")}
</Markdown.Cite>
</div>,
)
let quote = await screen->getByText("An anonymous quote about functional programming.")
await element(quote)->toBeVisible
let wrapper = await screen->getByTestId("cite-no-author-wrapper")
await element(wrapper)->toMatchScreenshot("markdown-cite-no-author")
})
test("renders nested list (ul inside li)", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="nested-list-wrapper">
<Markdown.Ul>
<Markdown.Li> {React.string("Parent item")} </Markdown.Li>
</Markdown.Ul>
<Markdown.Ol>
<Markdown.Li> {React.string("Numbered item")} </Markdown.Li>
</Markdown.Ol>
</div>,
)
let parentItem = await screen->getByText("Parent item")
await element(parentItem)->toBeVisible
let numberedItem = await screen->getByText("Numbered item")
await element(numberedItem)->toBeVisible
let wrapper = await screen->getByTestId("nested-list-wrapper")
await element(wrapper)->toMatchScreenshot("markdown-nested-lists")
})
test("renders Strong text", async () => {
await viewport(1440, 900)
let screen = await render(
<div dataTestId="strong-wrapper">
<Markdown.P>
<Markdown.Strong> {React.string("Bold text")} </Markdown.Strong>
{React.string(" and normal text")}
</Markdown.P>
</div>,
)
let bold = await screen->getByText("Bold text")
await element(bold)->toBeVisible
let wrapper = await screen->getByTestId("strong-wrapper")
await element(wrapper)->toMatchScreenshot("markdown-strong")
})