forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkeleton.spec.js
146 lines (133 loc) · 3.6 KB
/
Skeleton.spec.js
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
// compare to Skeleton.story.js
/// <reference types="cypress" />
import React from 'react'
import { mount } from 'cypress-react-unit-test'
import SideBySide from './SideBySide'
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'
const Box = ({ children }) => (
<a
style={{
border: '1px solid #ccc',
display: 'block',
fontSize: 16,
lineHeight: 2,
padding: 20,
marginBottom: 10,
width: 100,
}}
>
{children}
</a>
)
describe('Skeleton', () => {
it('with wrapper', () =>
mount(
<SideBySide>
<Skeleton count={5} wrapper={Box} />
<div>
<Box key={1}>A</Box>
<Box key={2}>B</Box>
<Box key={3}>C</Box>
<Box key={4}>D</Box>
</div>
</SideBySide>,
))
it('with wrapper and theme', () =>
mount(
<SideBySide>
<SkeletonTheme color="#333" highlightColor="#666">
<Skeleton count={5} wrapper={Box} />
</SkeletonTheme>
<div>
<Box key={1}>A</Box>
<Box key={2}>B</Box>
</div>
</SideBySide>,
))
it('with dynamic theme', () => {
const Dynamic = () => {
const [theme, setTheme] = React.useState('light')
const skeletonColor =
theme === 'light' ? 'rgba(0, 0, 0, .1)' : 'rgba(255, 255, 255, .1)'
const skeletonHighlight =
theme === 'light' ? 'rgba(0, 0, 0, .2)' : 'rgba(255,255,255, .2)'
const handleToggle = () => {
setTheme(oldTheme => (oldTheme === 'light' ? 'dark' : 'light'))
}
const backgroundColor = theme === 'light' ? 'white' : '#222'
return (
<div style={{ backgroundColor }}>
<button onClick={handleToggle}>Toggle Theme</button>
<SideBySide>
<SkeletonTheme
color={skeletonColor}
highlightColor={skeletonHighlight}
>
<Skeleton count={5} wrapper={Box} />
</SkeletonTheme>
<div>
<Box key={1}>A</Box>
<Box key={2}>B</Box>
</div>
</SideBySide>
</div>
)
}
mount(<Dynamic />)
cy.contains('Toggle Theme')
.click()
.wait(500)
.click()
.wait(500)
.click()
.wait(500)
.click()
.wait(500)
.click()
.wait(500)
.click()
})
it('with different durations', () => {
const Test = () => (
<div>
<Skeleton count={1} duration={1} />
<Skeleton count={1} duration={2} />
<Skeleton count={1} duration={3} />
<Skeleton count={1} duration={4} />
</div>
)
mount(<Test />)
})
it('with different widths', () => {
const Test = () => (
<div style={{ display: 'flex', flexDirection: 'column' }}>
<Skeleton count={1} />
<Skeleton count={1} width={50} />
<Skeleton count={1} width={100} />
<Skeleton count={1} width={200} />
<Skeleton count={1} width="50em" />
</div>
)
mount(<Test />)
})
it('with different heights', () => {
const Test = () => (
<div style={{ display: 'flex', flexDirection: 'column' }}>
<Skeleton count={1} />
<Skeleton count={1} height={200} />
<Skeleton count={1} height={400} />
<Skeleton count={1} height={600} />
<Skeleton count={1} height="50em" />
</div>
)
mount(<Test />)
})
it('Skeleton displayed as circle', () => {
const Test = () => (
<div style={{ display: 'flex', flexDirection: 'column' }}>
<Skeleton count={1} height={50} width={50} circle={true} />
</div>
)
mount(<Test />)
})
})