-
Notifications
You must be signed in to change notification settings - Fork 743
/
ssr.test.tsx
179 lines (158 loc) · 5.48 KB
/
ssr.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
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
import * as React from "react"
import { renderToString, renderToStaticMarkup } from "react-dom/server"
import { motion } from "../../"
import { motionValue } from "../../value"
import { AnimatePresence } from "../../components/AnimatePresence"
import { Reorder } from "../../components/Reorder"
function runTests(render: (components: any) => string) {
test("doesn't throw", () => {
render(
<motion.div
initial={{ x: 100 }}
whileTap={{ opacity: 0 }}
drag
layout
layoutId="a"
style={{ opacity: 1 }}
/>
)
expect(true).toBe(true)
})
test("correctly renders HTML", () => {
const y = motionValue(200)
const div = render(
<AnimatePresence>
<motion.div
initial={{ x: 100 }}
animate={{ x: 50 }}
style={{ y }}
exit={{ x: 0 }}
/>
</AnimatePresence>
)
expect(div).toBe(
'<div style="transform:translateX(100px) translateY(200px) translateZ(0)"></div>'
)
})
test("correctly renders custom HTML tag", () => {
const y = motionValue(200)
const CustomComponent = motion("element-test")
const customElement = render(
<AnimatePresence>
<CustomComponent
initial={{ x: 100 }}
animate={{ x: 50 }}
style={{ y }}
exit={{ x: 0 }}
/>
</AnimatePresence>
)
expect(customElement).toBe(
'<element-test style="transform:translateX(100px) translateY(200px) translateZ(0)"></element-test>'
)
})
test("correctly renders SVG", () => {
const cx = motionValue(100)
const pathLength = motionValue(0.5)
const circle = render(
<motion.circle
cx={cx}
initial={{ strokeWidth: 10 }}
style={{
background: "#fff",
pathLength,
x: 100,
}}
/>
)
expect(circle).toBe(
'<circle cx="100" style="background:#fff" stroke-width="10" pathLength="1" stroke-dashoffset="0px" stroke-dasharray="0.5px 1px"></circle>'
)
const rect = render(
<AnimatePresence>
<motion.rect
initial={{ x: 0 }}
animate={{ x: 100 }}
exit={{ x: 0 }}
mask=""
style={{
background: "#fff",
}}
className="test"
onMouseMove={() => {}}
/>
</AnimatePresence>
)
expect(rect).toBe(
'<rect mask="" style="background:#fff" class="test"></rect>'
)
})
test("initial correctly overrides style", () => {
const div = render(
<motion.div initial={{ x: 100 }} style={{ x: 200 }} />
)
expect(div).toBe(
`<div style="transform:translateX(100px) translateZ(0)"></div>`
)
})
test("initial correctly overrides style with keyframes and initial={false}", () => {
const div = render(
<motion.div
initial={false}
animate={{ x: [0, 100] }}
style={{ x: 200 }}
/>
)
expect(div).toBe(
`<div style="transform:translateX(100px) translateZ(0)"></div>`
)
})
test("Reorder: Renders correct element", () => {
function Component() {
const [state, setState] = React.useState([0])
return (
<Reorder.Group onReorder={setState} values={state}>
<Reorder.Item value="a" />
</Reorder.Group>
)
}
const div = render(<Component />)
expect(div).toBe(
`<ul><li style="z-index:unset;transform:none;-webkit-touch-callout:none;-webkit-user-select:none;user-select:none;touch-action:pan-x" draggable="false"></li></ul>`
)
})
test("Reorder: Doesn't render touch-scroll disabling styles if dragListener === false", () => {
function Component() {
const [state, setState] = React.useState([0])
return (
<Reorder.Group onReorder={setState} values={state}>
<Reorder.Item value="a" dragListener={false} />
</Reorder.Group>
)
}
const div = render(<Component />)
expect(div).toBe(
`<ul><li style="z-index:unset;transform:none"></li></ul>`
)
})
test("Reorder: Renders provided element", () => {
function Component() {
const [state, setState] = React.useState([0])
return (
<Reorder.Group as="div" onReorder={setState} values={state}>
<Reorder.Item as="div" value="a" />
</Reorder.Group>
)
}
const div = render(<Component />)
expect(div).toBe(
`<div><div style="z-index:unset;transform:none;-webkit-touch-callout:none;-webkit-user-select:none;user-select:none;touch-action:pan-x" draggable="false"></div></div>`
)
})
}
describe("render", () => {
runTests(renderToString)
})
describe("renderToStaticMarkup", () => {
runTests(renderToStaticMarkup)
})