-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathProgress-test.js
More file actions
237 lines (211 loc) · 7.61 KB
/
Progress-test.js
File metadata and controls
237 lines (211 loc) · 7.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import _ from 'lodash'
import React from 'react'
import { SUI } from 'src/lib'
import Progress from 'src/modules/Progress/Progress'
import * as common from 'test/specs/commonTests'
describe('Progress', () => {
common.isConformant(Progress)
common.hasUIClassName(Progress)
common.rendersChildren(Progress)
common.propKeyAndValueToClassName(Progress, 'attached', ['top', 'bottom'])
common.propKeyOnlyToClassName(Progress, 'active')
common.propKeyOnlyToClassName(Progress, 'disabled')
common.propKeyOnlyToClassName(Progress, 'error')
common.propKeyOnlyToClassName(Progress, 'indicating')
common.propKeyOnlyToClassName(Progress, 'inverted')
common.propKeyOnlyToClassName(Progress, 'success')
common.propKeyOnlyToClassName(Progress, 'warning')
common.propValueOnlyToClassName(Progress, 'color', SUI.COLORS)
common.propValueOnlyToClassName(Progress, 'size', _.without(SUI.SIZES, 'mini', 'huge', 'massive'))
it('contains div with className bar', () => {
shallow(<Progress />)
.should.have.descendants('.bar')
.and.have.tagName('div')
})
describe('attached', () => {
it('removes the progress label from the bar', () => {
shallow(<Progress attached='top' />)
.find('.bar')
.should.not.have.descendants('.progress')
})
})
describe('autoSuccess', () => {
it('applies the success class when percent >= 100%', () => {
const wrapper = shallow(<Progress autoSuccess />)
wrapper.setProps({ percent: 100, autoSuccess: true }).should.have.have.className('success')
wrapper.setProps({ percent: 99, autoSuccess: true }).should.not.have.have.className('success')
wrapper.setProps({ percent: 101, autoSuccess: true }).should.have.have.className('success')
})
it('applies the success class when value >= total', () => {
const wrapper = shallow(<Progress autoSuccess />)
wrapper
.setProps({ total: 1, value: 1, autoSuccess: true })
.should.have.have.className('success')
wrapper
.setProps({ total: 1, value: 0, autoSuccess: true })
.should.not.have.have.className('success')
wrapper
.setProps({ total: 1, value: 2, autoSuccess: true })
.should.have.have.className('success')
})
})
describe('bar', () => {
it('has a width equal to the percent complete', () => {
shallow(<Progress percent={33.333} />)
.find('.bar')
.should.have.style('width', '33.333%')
})
it('cannot have its width set >100%', () => {
shallow(<Progress percent={101} />)
.find('.bar')
.should.have.style('width', '100%')
})
it('cannot have its width set <0%', () => {
shallow(<Progress percent={-1} />)
.find('.bar')
.should.have.style('width', '0%')
})
it('has a width equal to the percentage of the value of the total, when progress="value"', () => {
shallow(<Progress progress='value' value={5} total={10} />)
.find('.bar')
.should.have.style('width', '50%')
})
it('cannot have its width set >100%, when progress="value"', () => {
shallow(<Progress progress='value' value={10} total={5} />)
.find('.bar')
.should.have.style('width', '100%')
shallow(<Progress progress='value' value={200} />)
.find('.bar')
.should.have.style('width', '100%')
})
})
describe('data-percent', () => {
it('adds prop by default', () => {
shallow(<Progress />).should.have.data('percent')
})
it('passes value of percent prop', () => {
shallow(<Progress percent={10} />).should.have.data('percent', 10)
})
it('floors the value of percent prop', () => {
shallow(<Progress percent={8.28} />).should.have.data('percent', 8)
})
it('floors the results value and total props', () => {
shallow(<Progress value={828} total={10000} />).should.have.data('percent', 8)
})
})
describe('indicating', () => {
it('adds the "active" class', () => {
shallow(<Progress indicating />).should.have.className('active')
})
})
describe('label', () => {
it('shows the label text when provided', () => {
shallow(<Progress label='some-label' />)
.children()
.find('.label')
.should.contain.text('some-label')
})
})
describe('progress', () => {
it('hides the progress text by default', () => {
shallow(<Progress />)
.find('.bar')
.should.not.have.descendants('.progress')
})
it('shows the progress text when true', () => {
shallow(<Progress progress />)
.find('.bar')
.should.have.descendants('.progress')
})
it('hides the progress text when false', () => {
shallow(<Progress progress={false} />)
.find('.bar')
.should.not.have.descendants('.progress')
})
it('displays the progress as a percentage by default', () => {
shallow(<Progress percent={20} progress />)
.should.have.descendants('.progress')
.and.contain.text('20%')
})
it('displays the progress as a ratio when set to "ratio"', () => {
shallow(<Progress progress='ratio' value={1} total={2} />)
.children()
.find('.progress')
.should.contain.text('1/2')
})
it('displays the progress as a percentage when set to "percent"', () => {
shallow(<Progress progress='percent' value={1} total={2} />)
.children()
.find('.progress')
.should.contain.text('50%')
})
it('displays the progress as text when set to "value"', () => {
shallow(<Progress progress='value' value={1} total={2} />)
.children()
.find('.progress')
.should.contain.text('1')
})
it('shows the percent complete', () => {
shallow(<Progress percent={72} progress />)
.children()
.find('.progress')
.should.contain.text('72%')
})
it('cannot be set >100%', () => {
shallow(<Progress percent={101} progress />)
.children()
.find('.progress')
.should.contain.text('100%')
})
it('cannot be set <0%', () => {
shallow(<Progress percent={-1} progress />)
.children()
.find('.progress')
.should.contain.text('0%')
})
it('displays values with a decimal', () => {
shallow(<Progress percent={10.12345} progress />)
.children()
.find('.progress')
.should.contain.text('10.12345%')
})
it('displays values without a decimal', () => {
shallow(<Progress percent={35} progress />)
.children()
.find('.progress')
.should.contain.text('35%')
})
})
describe('precision', () => {
it('rounds the progress label to 0 decimal places by default', () => {
shallow(<Progress percent={10.12345} precision={0} />)
.children()
.find('.progress')
.should.contain.text('10%')
})
it('removes the decimal from progress label when set to 0', () => {
shallow(<Progress percent={10.12345} precision={0} />)
.children()
.find('.progress')
.should.contain.text('10%')
})
it('rounds the decimal in the progress label to the number of digits', () => {
shallow(<Progress percent={10.12345} precision={1} />)
.children()
.find('.progress')
.should.contain.text('10.1%')
shallow(<Progress percent={10.12345} precision={4} />)
.children()
.find('.progress')
.should.contain.text('10.1235%')
})
})
describe('total/value', () => {
it('calculates the percent complete', () => {
shallow(<Progress value={1} total={2} progress />)
.children()
.find('.progress')
.should.contain.text('50%')
})
})
})