Skip to content

Commit cd551c0

Browse files
committed
update test cases of dot and snap of jest
1 parent 342a009 commit cd551c0

File tree

6 files changed

+97
-19
lines changed

6 files changed

+97
-19
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export default () => (
140140
<td>dot</td>
141141
<td>Boolean | Object</td>
142142
<td>false</td>
143-
<td>within dot or not, value: true, false, { size: Number }</td>
143+
<td>within dot or not, value: true, false, { size: Number }, if the size is not a number, it will be the strokeWidth as default</td>
144144
</tr>
145145
</tbody>
146146
</table>

docs/examples/gap.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Example extends React.Component<ProgressProps, any> {
4141
Change State [{percent}]
4242
</button>
4343
</p>
44+
<h3>within dot</h3>
4445
<div style={circleContainerStyle}>
4546
<Circle
4647
percent={percent}
@@ -65,6 +66,7 @@ class Example extends React.Component<ProgressProps, any> {
6566
/>
6667
</div>
6768

69+
<h3>without dot</h3>
6870
<div style={circleContainerStyle}>
6971
<Circle
7072
percent={percent}
@@ -73,7 +75,6 @@ class Example extends React.Component<ProgressProps, any> {
7375
strokeWidth={6}
7476
strokeLinecap="square"
7577
strokeColor={color}
76-
dot={{ size: 'p' }}
7778
/>
7879
</div>
7980
<div style={circleContainerStyle}>
@@ -84,7 +85,6 @@ class Example extends React.Component<ProgressProps, any> {
8485
strokeWidth={6}
8586
strokeLinecap="square"
8687
strokeColor={color}
87-
dot={{ size: [] }}
8888
/>
8989
</div>
9090
</div>

docs/examples/gradient-circle.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const Example = () => {
1010

1111
return (
1212
<div>
13-
<h3>Circle Progress {90}%</h3>
13+
<h3>Circle Progress {90}% (within dot)</h3>
1414
<div style={circleContainerStyle}>
1515
<Circle
1616
percent={90}
@@ -20,7 +20,7 @@ const Example = () => {
2020
'0%': '#108ee9',
2121
'100%': '#87d068',
2222
}}
23-
dot={{ size: '10' }}
23+
dot={true}
2424
/>
2525
</div>
2626
<h3>Circle Progress {100}%</h3>
@@ -33,7 +33,6 @@ const Example = () => {
3333
'100%': '#108ee9',
3434
'0%': '#87d068',
3535
}}
36-
dot={{}}
3736
/>
3837
</div>
3938
<h3>Circle With Success Percent {65}%</h3>

src/Circle.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,18 @@ const Circle: React.FC<ProgressProps> = ({
115115

116116
path.setAttribute('d', pathDom.props.d);
117117
const dotPoint = path.getPointAtLength(strokeLength);
118+
118119
return (
119120
<circle
120121
key={index + 10}
121122
className={`${prefixCls}-circle-dot`}
122123
cx={dotPoint.x}
123124
cy={dotPoint.y}
124-
r={typeof dot === 'object' ? dot.size : strokeWidth}
125+
r={
126+
typeof dot === 'object' && dot.size && typeof dot.size === 'number'
127+
? dot.size
128+
: strokeWidth
129+
}
125130
fill={pathDom.props.stroke ? pathDom.props.stroke : pathDom.props.style.stroke}
126131
/>
127132
);

tests/__snapshots__/index.spec.js.snap

+60-12
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,21 @@ Array [
153153
strokeColor="#2db7f5"
154154
strokeLinecap="square"
155155
strokeWidth="6"
156-
style={Object {}}
156+
style={
157+
Object {
158+
"overflow": "visible",
159+
}
160+
}
157161
trailColor="#D9D9D9"
158162
trailWidth={1}
159163
>
160164
<svg
161165
className="rc-progress-circle"
162-
style={Object {}}
166+
style={
167+
Object {
168+
"overflow": "visible",
169+
}
170+
}
163171
viewBox="0 0 100 100"
164172
>
165173
<path
@@ -211,13 +219,21 @@ Array [
211219
strokeColor="#2db7f5"
212220
strokeLinecap="square"
213221
strokeWidth="6"
214-
style={Object {}}
222+
style={
223+
Object {
224+
"overflow": "visible",
225+
}
226+
}
215227
trailColor="#D9D9D9"
216228
trailWidth={1}
217229
>
218230
<svg
219231
className="rc-progress-circle"
220-
style={Object {}}
232+
style={
233+
Object {
234+
"overflow": "visible",
235+
}
236+
}
221237
viewBox="0 0 100 100"
222238
>
223239
<path
@@ -269,13 +285,21 @@ Array [
269285
strokeColor="#2db7f5"
270286
strokeLinecap="square"
271287
strokeWidth="6"
272-
style={Object {}}
288+
style={
289+
Object {
290+
"overflow": "visible",
291+
}
292+
}
273293
trailColor="#D9D9D9"
274294
trailWidth={1}
275295
>
276296
<svg
277297
className="rc-progress-circle"
278-
style={Object {}}
298+
style={
299+
Object {
300+
"overflow": "visible",
301+
}
302+
}
279303
viewBox="0 0 100 100"
280304
>
281305
<path
@@ -327,13 +351,21 @@ Array [
327351
strokeColor="#2db7f5"
328352
strokeLinecap="square"
329353
strokeWidth="6"
330-
style={Object {}}
354+
style={
355+
Object {
356+
"overflow": "visible",
357+
}
358+
}
331359
trailColor="#D9D9D9"
332360
trailWidth={1}
333361
>
334362
<svg
335363
className="rc-progress-circle"
336-
style={Object {}}
364+
style={
365+
Object {
366+
"overflow": "visible",
367+
}
368+
}
337369
viewBox="0 0 100 100"
338370
>
339371
<path
@@ -385,13 +417,21 @@ Array [
385417
strokeColor="#2db7f5"
386418
strokeLinecap="round"
387419
strokeWidth="6"
388-
style={Object {}}
420+
style={
421+
Object {
422+
"overflow": "visible",
423+
}
424+
}
389425
trailColor="#D9D9D9"
390426
trailWidth={1}
391427
>
392428
<svg
393429
className="rc-progress-circle"
394-
style={Object {}}
430+
style={
431+
Object {
432+
"overflow": "visible",
433+
}
434+
}
395435
viewBox="0 0 100 100"
396436
>
397437
<path
@@ -443,13 +483,21 @@ Array [
443483
strokeColor="#2db7f5"
444484
strokeLinecap="round"
445485
strokeWidth="6"
446-
style={Object {}}
486+
style={
487+
Object {
488+
"overflow": "visible",
489+
}
490+
}
447491
trailColor="#D9D9D9"
448492
trailWidth={1}
449493
>
450494
<svg
451495
className="rc-progress-circle"
452-
style={Object {}}
496+
style={
497+
Object {
498+
"overflow": "visible",
499+
}
500+
}
453501
viewBox="0 0 100 100"
454502
>
455503
<path

tests/index.spec.js

+26
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,30 @@ describe('Progress', () => {
156156
);
157157
});
158158
});
159+
160+
describe('dot', () => {
161+
it('the size of dot must be a number', () => {
162+
const wrapper = mount(
163+
<Circle
164+
percent={70}
165+
gapDegree={70}
166+
gapPosition="top"
167+
strokeWidth={6}
168+
strokeLinecap="square"
169+
strokeColor="#3FC7FA"
170+
dot={{ size: '10' }}
171+
/>,
172+
);
173+
expect(wrapper.find('.rc-progress-circle-dot').getDOMNode().r).toBe('6');
174+
175+
wrapper.setProps({ dot: { size: 10 } });
176+
expect(wrapper.find('.rc-progress-circle-dot').getDOMNode().r).toBe('10');
177+
178+
wrapper.setProps({ dot: true });
179+
expect(wrapper.find('.rc-progress-circle-dot').getDOMNode().r).toBe('6');
180+
181+
wrapper.setProps({ dot: [] });
182+
expect(wrapper.find('.rc-progress-circle-dot').getDOMNode().r).toBe('6');
183+
});
184+
});
159185
});

0 commit comments

Comments
 (0)