/
index.test.tsx
77 lines (63 loc) · 2.63 KB
/
index.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
import { render } from "../../../../jest.setup"
import * as React from "react"
import { renderToString, renderToStaticMarkup } from "react-dom/server"
import { useRef, useLayoutEffect, useState } from "react"
import { Reorder } from ".."
describe("Reorder", () => {
it("Correctly renders HTML", () => {
const Component = () => (
<Reorder.Group as="article" onReorder={() => {}} values={[]}>
<Reorder.Item as="main" value={0} />
</Reorder.Group>
)
const staticMarkup = renderToStaticMarkup(<Component />)
const string = renderToString(<Component />)
const expectedMarkup = `<article><main style="z-index:unset;transform:none;-webkit-touch-callout:none;-webkit-user-select:none;user-select:none;touch-action:pan-x" draggable="false"></main></article>`
expect(staticMarkup).toBe(expectedMarkup)
expect(string).toBe(expectedMarkup)
})
it("onReorder is typed correctly", () => {
const Component = () => {
const [_items, setItems] = useState(["a"])
return (
<Reorder.Group as="article" onReorder={setItems} values={[]}>
<Reorder.Item as="main" value={0} />
</Reorder.Group>
)
}
const staticMarkup = renderToStaticMarkup(<Component />)
const string = renderToString(<Component />)
const expectedMarkup = `<article><main style="z-index:unset;transform:none;-webkit-touch-callout:none;-webkit-user-select:none;user-select:none;touch-action:pan-x" draggable="false"></main></article>`
expect(staticMarkup).toBe(expectedMarkup)
expect(string).toBe(expectedMarkup)
})
it("Correctly hydrates ref", () => {
let groupRefPass = false
let itemRefPass = false
const Component = () => {
const groupRef = useRef<HTMLElement>(null)
const itemRef = useRef<HTMLElement>(null)
useLayoutEffect(() => {
if (groupRef.current !== null) {
groupRefPass = true
}
if (itemRef.current !== null) {
itemRefPass = true
}
})
return (
<Reorder.Group
as="article"
ref={groupRef}
onReorder={() => {}}
values={[]}
>
<Reorder.Item as="main" ref={itemRef} value={0} />
</Reorder.Group>
)
}
render(<Component />)
expect(groupRefPass).toBe(true)
expect(itemRefPass).toBe(true)
})
})