-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathContentLoader.test.tsx
More file actions
139 lines (121 loc) · 4.61 KB
/
Copy pathContentLoader.test.tsx
File metadata and controls
139 lines (121 loc) · 4.61 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
import * as React from 'react'
import * as renderer from 'react-test-renderer'
import * as ShallowRenderer from 'react-test-renderer/shallow'
import { Rect as SvgRect } from 'react-native-svg'
import ContentLoader, { Circle, Rect } from '../ContentLoader'
jest.useFakeTimers()
describe('ContentLoader', () => {
describe('when type is custom', () => {
const customWrapper = renderer.create(
<ContentLoader animate={false}>
<Rect x="80" y="17" rx="4" ry="4" width="300" height="13" />
<Rect x="82" y="44" rx="3" ry="3" width="250" height="10" />
<Circle cx="35" cy="35" r="35" />
</ContentLoader>
).root
it('should render custom element', () => {
const rect = customWrapper.findAllByType(Rect)
const svgRect = customWrapper.findAllByType(SvgRect)
const circle = customWrapper.findAllByType(Circle)
expect(rect.length).toBe(2)
expect(svgRect.length).toBe(3)
expect(circle.length).toBe(1)
})
})
describe('Props are propagated', () => {
const noPropsComponent = ShallowRenderer.createRenderer()
noPropsComponent.render(
<ContentLoader>
<Rect />
</ContentLoader>
)
const withPropsComponent = ShallowRenderer.createRenderer()
withPropsComponent.render(
<ContentLoader
animate={false}
height={200}
preserveAspectRatio="xMaxYMax meet"
backgroundColor="#000"
rtl
foregroundColor="#fff"
speed={10}
style={{ marginBottom: 10 }}
width={200}
beforeMask={<Rect />}
>
<Rect />
</ContentLoader>
)
const { props: propsFromEmpty } = noPropsComponent.getRenderOutput()
const { props: propsFromFullField } = withPropsComponent.getRenderOutput()
it("`speed` is a number and it's used", () => {
// defaultProps
expect(typeof propsFromEmpty.speed).toBe('number')
expect(propsFromEmpty.speed).toBe(1.2)
// custom props
expect(typeof propsFromFullField.speed).toBe('number')
expect(propsFromFullField.speed).toBe(10)
})
it("`height` is a number and it's used", () => {
// custom props
expect(typeof propsFromFullField.height).toBe('number')
expect(propsFromFullField.height).toBe(200)
})
it("`width` is a number and it's used", () => {
// custom props
expect(typeof propsFromFullField.width).toBe('number')
expect(propsFromFullField.width).toBe(200)
})
it("`animate` is a boolean and it's used", () => {
// defaultProps
expect(typeof propsFromEmpty.animate).toBe('boolean')
expect(propsFromEmpty.animate).toBe(true)
// custom props
expect(typeof propsFromFullField.animate).toBe('boolean')
expect(propsFromFullField.animate).toBe(false)
})
it("`backgroundColor` is a string and it's used", () => {
// defaultProps
expect(typeof propsFromEmpty.backgroundColor).toBe('string')
expect(propsFromEmpty.backgroundColor).toBe('#f5f6f7')
// custom props
expect(typeof propsFromFullField.backgroundColor).toBe('string')
expect(propsFromFullField.backgroundColor).toBe('#000')
})
it("`foregroundColor` is a string and it's used", () => {
// defaultProps
expect(typeof propsFromEmpty.foregroundColor).toBe('string')
expect(propsFromEmpty.foregroundColor).toBe('#eee')
// custom props
expect(typeof propsFromFullField.foregroundColor).toBe('string')
expect(propsFromFullField.foregroundColor).toBe('#fff')
})
it("`preserveAspectRatio` is a string and it's used", () => {
// custom props
expect(typeof propsFromFullField.preserveAspectRatio).toBe('string')
expect(propsFromFullField.preserveAspectRatio).toBe('xMaxYMax meet')
})
it("`style` is an object and it's used", () => {
// defaultProps
expect(propsFromEmpty.style).toMatchObject({})
// custom props
expect(propsFromFullField.style).toMatchObject({ marginBottom: 10 })
})
it("`rtl` is a boolean and it's used", () => {
// defaultProps
expect(typeof propsFromEmpty.rtl).toBe('boolean')
expect(propsFromEmpty.rtl).toBe(false)
// custom props
expect(typeof propsFromFullField.rtl).toBe('boolean')
expect(propsFromFullField.rtl).toBe(true)
})
it("`beforeMask` is a JSX Element and it's used", () => {
// defaultProps
expect(typeof propsFromEmpty.beforeMask).toBe('object')
expect(propsFromEmpty.beforeMask).toBe(null)
// custom props
expect(typeof propsFromFullField.beforeMask).toBe('object')
expect(propsFromFullField.beforeMask).toEqual(<Rect />)
})
})
})