Skip to content

Commit 0864434

Browse files
authored
Added unit Tests in the ReactART, increasing the code coverage (#23195)
1 parent f6c130f commit 0864434

File tree

2 files changed

+223
-0
lines changed

2 files changed

+223
-0
lines changed

packages/react-art/src/__tests__/ReactART-test.js

+54
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,60 @@ describe('ReactARTComponents', () => {
440440
expect(rectangle.toJSON()).toMatchSnapshot();
441441
});
442442

443+
it('should generate a <Shape> with positive width when width prop is negative', () => {
444+
const rectangle = ReactTestRenderer.create(
445+
<Rectangle width={-50} height={50} />,
446+
);
447+
expect(rectangle.toJSON()).toMatchSnapshot();
448+
});
449+
450+
it('should generate a <Shape> with positive height when height prop is negative', () => {
451+
const rectangle = ReactTestRenderer.create(
452+
<Rectangle height={-50} width={50} />,
453+
);
454+
expect(rectangle.toJSON()).toMatchSnapshot();
455+
});
456+
457+
it('should generate a <Shape> with a radius property of 0 when top left radius prop is negative', () => {
458+
const rectangle = ReactTestRenderer.create(
459+
<Rectangle radiusTopLeft={-25} width={50} height={50} />,
460+
);
461+
expect(rectangle.toJSON()).toMatchSnapshot();
462+
});
463+
464+
it('should generate a <Shape> with a radius property of 0 when top right radius prop is negative', () => {
465+
const rectangle = ReactTestRenderer.create(
466+
<Rectangle radiusTopRight={-25} width={50} height={50} />,
467+
);
468+
expect(rectangle.toJSON()).toMatchSnapshot();
469+
});
470+
471+
it('should generate a <Shape> with a radius property of 0 when bottom right radius prop is negative', () => {
472+
const rectangle = ReactTestRenderer.create(
473+
<Rectangle radiusBottomRight={-30} width={50} height={50} />,
474+
);
475+
expect(rectangle.toJSON()).toMatchSnapshot();
476+
});
477+
478+
it('should generate a <Shape> with a radius property of 0 when bottom left radius prop is negative', () => {
479+
const rectangle = ReactTestRenderer.create(
480+
<Rectangle radiusBottomLeft={-25} width={50} height={50} />,
481+
);
482+
expect(rectangle.toJSON()).toMatchSnapshot();
483+
});
484+
485+
it('should generate a <Shape> where top radius is 0 if the sum of the top radius is greater than width', () => {
486+
const rectangle = ReactTestRenderer.create(
487+
<Rectangle
488+
radiusTopRight={25}
489+
radiusTopLeft={26}
490+
width={50}
491+
height={40}
492+
/>,
493+
);
494+
expect(rectangle.toJSON()).toMatchSnapshot();
495+
});
496+
443497
it('should warn if width/height is missing on a Rectangle component', () => {
444498
expect(() =>
445499
ReactTestRenderer.create(<Rectangle stroke="green" fill="blue" />),

packages/react-art/src/__tests__/__snapshots__/ReactART-test.js.snap

+169
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,174 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`ReactARTComponents should generate a <Shape> where top radius is 0 if the sum of the top radius is greater than width 1`] = `
4+
<Shape
5+
d={
6+
Object {
7+
"_pivotX": 0,
8+
"_pivotY": 0,
9+
"path": Array [
10+
[Function],
11+
[Function],
12+
[Function],
13+
[Function],
14+
[Function],
15+
],
16+
"penDownX": 0,
17+
"penDownY": 0,
18+
"penX": 0,
19+
"penY": 0,
20+
}
21+
}
22+
height={40}
23+
radiusTopLeft={26}
24+
radiusTopRight={25}
25+
width={50}
26+
/>
27+
`;
28+
exports[`ReactARTComponents should generate a <Shape> with a radius property of 0 when bottom left radius prop is negative 1`] = `
29+
<Shape
30+
d={
31+
Object {
32+
"_pivotX": 0,
33+
"_pivotY": 0,
34+
"path": Array [
35+
[Function],
36+
[Function],
37+
[Function],
38+
[Function],
39+
[Function],
40+
],
41+
"penDownX": 0,
42+
"penDownY": 0,
43+
"penX": 0,
44+
"penY": 0,
45+
}
46+
}
47+
height={50}
48+
radiusBottomLeft={-25}
49+
width={50}
50+
/>
51+
`;
52+
exports[`ReactARTComponents should generate a <Shape> with a radius property of 0 when bottom right radius prop is negative 1`] = `
53+
<Shape
54+
d={
55+
Object {
56+
"_pivotX": 0,
57+
"_pivotY": 0,
58+
"path": Array [
59+
[Function],
60+
[Function],
61+
[Function],
62+
[Function],
63+
[Function],
64+
],
65+
"penDownX": 0,
66+
"penDownY": 0,
67+
"penX": 0,
68+
"penY": 0,
69+
}
70+
}
71+
height={50}
72+
radiusBottomRight={-30}
73+
width={50}
74+
/>
75+
`;
76+
exports[`ReactARTComponents should generate a <Shape> with a radius property of 0 when top left radius prop is negative 1`] = `
77+
<Shape
78+
d={
79+
Object {
80+
"_pivotX": 0,
81+
"_pivotY": 0,
82+
"path": Array [
83+
[Function],
84+
[Function],
85+
[Function],
86+
[Function],
87+
[Function],
88+
],
89+
"penDownX": 0,
90+
"penDownY": 0,
91+
"penX": 0,
92+
"penY": 0,
93+
}
94+
}
95+
height={50}
96+
radiusTopLeft={-25}
97+
width={50}
98+
/>
99+
`;
100+
exports[`ReactARTComponents should generate a <Shape> with a radius property of 0 when top right radius prop is negative 1`] = `
101+
<Shape
102+
d={
103+
Object {
104+
"_pivotX": 0,
105+
"_pivotY": 0,
106+
"path": Array [
107+
[Function],
108+
[Function],
109+
[Function],
110+
[Function],
111+
[Function],
112+
],
113+
"penDownX": 0,
114+
"penDownY": 0,
115+
"penX": 0,
116+
"penY": 0,
117+
}
118+
}
119+
height={50}
120+
radiusTopRight={-25}
121+
width={50}
122+
/>
123+
`;
124+
exports[`ReactARTComponents should generate a <Shape> with positive height when height prop is negative 1`] = `
125+
<Shape
126+
d={
127+
Object {
128+
"_pivotX": 0,
129+
"_pivotY": -50,
130+
"path": Array [
131+
[Function],
132+
[Function],
133+
[Function],
134+
[Function],
135+
[Function],
136+
[Function],
137+
],
138+
"penDownX": 0,
139+
"penDownY": -50,
140+
"penX": 0,
141+
"penY": -50,
142+
}
143+
}
144+
height={-50}
145+
width={50}
146+
/>
147+
`;
148+
exports[`ReactARTComponents should generate a <Shape> with positive width when width prop is negative 1`] = `
149+
<Shape
150+
d={
151+
Object {
152+
"_pivotX": -50,
153+
"_pivotY": 0,
154+
"path": Array [
155+
[Function],
156+
[Function],
157+
[Function],
158+
[Function],
159+
[Function],
160+
[Function],
161+
],
162+
"penDownX": -50,
163+
"penDownY": 0,
164+
"penX": -50,
165+
"penY": 0,
166+
}
167+
}
168+
height={50}
169+
width={-50}
170+
/>
171+
`;
3172
exports[`ReactARTComponents should generate a <Shape> with props for drawing the Circle 1`] = `
4173
<Shape
5174
d={

0 commit comments

Comments
 (0)