forked from rebassjs/rebass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeading.spec.js
206 lines (163 loc) · 4.92 KB
/
Heading.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
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
import React from 'react'
import TestUtils from 'react-addons-test-utils'
import expect from 'expect'
import { config, Heading, Base } from '../src'
const renderer = TestUtils.createRenderer()
describe('Heading', () => {
const { fontSizes } = config
let tree
beforeEach(() => {
renderer.render(<Heading />)
tree = renderer.getRenderOutput()
})
it('should render', () => {
expect(tree.type).toEqual(Base)
})
it('should set tagName h2', () => {
expect(tree.props.tagName).toEqual('h2')
})
it('should have a className', () => {
expect(tree.props.className).toEqual('Heading')
})
it('should have default font size', () => {
expect(tree.props.baseStyle.fontSize).toEqual(fontSizes[2])
})
context('when level is 1', () => {
beforeEach(() => {
renderer.render(<Heading level={1} />)
tree = renderer.getRenderOutput()
})
it('should set tagName h1', () => {
expect(tree.props.tagName).toEqual('h1')
})
it('should have h1 font size', () => {
expect(tree.props.baseStyle.fontSize).toEqual(fontSizes[1])
})
})
context('when level is 2', () => {
beforeEach(() => {
renderer.render(<Heading level={2} />)
tree = renderer.getRenderOutput()
})
it('should set tagName h2', () => {
expect(tree.props.tagName).toEqual('h2')
})
it('should have h2 font size', () => {
expect(tree.props.baseStyle.fontSize).toEqual(fontSizes[2])
})
})
context('when level is 3', () => {
beforeEach(() => {
renderer.render(<Heading level={3} />)
tree = renderer.getRenderOutput()
})
it('should set tagName h3', () => {
expect(tree.props.tagName).toEqual('h3')
})
it('should have h3 font size', () => {
expect(tree.props.baseStyle.fontSize).toEqual(fontSizes[3])
})
})
context('when level is 4', () => {
beforeEach(() => {
renderer.render(<Heading level={4} />)
tree = renderer.getRenderOutput()
})
it('should set tagName h4', () => {
expect(tree.props.tagName).toEqual('h4')
})
it('should have h4 font size', () => {
expect(tree.props.baseStyle.fontSize).toEqual(fontSizes[4])
})
})
context('when level is 5', () => {
beforeEach(() => {
renderer.render(<Heading level={5} />)
tree = renderer.getRenderOutput()
})
it('should set tagName h5', () => {
expect(tree.props.tagName).toEqual('h5')
})
it('should have h5 font size', () => {
expect(tree.props.baseStyle.fontSize).toEqual(fontSizes[5])
})
})
context('when level is 6', () => {
beforeEach(() => {
renderer.render(<Heading level={6} />)
tree = renderer.getRenderOutput()
})
it('should set tagName h6', () => {
expect(tree.props.tagName).toEqual('h6')
})
it('should have h6 font size', () => {
expect(tree.props.baseStyle.fontSize).toEqual(fontSizes[6])
})
})
context('when size is 0', () => {
beforeEach(() => {
renderer.render(<Heading size={0} />)
tree = renderer.getRenderOutput()
})
it('should set tagName h2', () => {
expect(tree.props.tagName).toEqual('h2')
})
it('should have h0 font size', () => {
expect(tree.props.baseStyle.fontSize).toEqual(fontSizes[0])
})
})
context('when size is 0 and level is 4', () => {
beforeEach(() => {
renderer.render(<Heading size={0} level={4} />)
tree = renderer.getRenderOutput()
})
it('should set tagName h4', () => {
expect(tree.props.tagName).toEqual('h4')
})
it('should have h0 font size', () => {
expect(tree.props.baseStyle.fontSize).toEqual(fontSizes[0])
})
})
context('when big is true', () => {
beforeEach(() => {
renderer.render(<Heading big />)
tree = renderer.getRenderOutput()
})
it('should set tagName h2', () => {
expect(tree.props.tagName).toEqual('h2')
})
it('should have double the fontSize', () => {
expect(tree.props.baseStyle.fontSize).toEqual(fontSizes[2] * 2)
})
})
context('when alt is true', () => {
beforeEach(() => {
renderer.render(<Heading alt />)
tree = renderer.getRenderOutput()
})
it('should set className', () => {
expect(tree.props.className).toEqual('Heading Heading_alt')
})
it('should apply alt styles', () => {
expect(tree.props.baseStyle.opacity).toEqual(0.5)
})
})
context('when _className is set', () => {
beforeEach(() => {
renderer.render(<Heading _className='Test' />)
tree = renderer.getRenderOutput()
})
it('should set className', () => {
expect(tree.props.className).toEqual('Test')
})
})
context('when custom styles are set', () => {
beforeEach(() => {
renderer.render(<Heading style={{ color: 'tomato' }} />)
tree = renderer.getRenderOutput()
})
it('should have a custom color', () => {
expect(tree.props.style.color).toEqual('tomato')
})
})
})