Skip to content

Commit

Permalink
Added unit Tests in the ReactART, increasing the code coverage (faceb…
Browse files Browse the repository at this point in the history
  • Loading branch information
Biki-das authored and zhengjitf committed Apr 15, 2022
1 parent 66f2ce8 commit 9e6604f
Show file tree
Hide file tree
Showing 2 changed files with 223 additions and 0 deletions.
54 changes: 54 additions & 0 deletions packages/react-art/src/__tests__/ReactART-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,60 @@ describe('ReactARTComponents', () => {
expect(rectangle.toJSON()).toMatchSnapshot();
});

it('should generate a <Shape> with positive width when width prop is negative', () => {
const rectangle = ReactTestRenderer.create(
<Rectangle width={-50} height={50} />,
);
expect(rectangle.toJSON()).toMatchSnapshot();
});

it('should generate a <Shape> with positive height when height prop is negative', () => {
const rectangle = ReactTestRenderer.create(
<Rectangle height={-50} width={50} />,
);
expect(rectangle.toJSON()).toMatchSnapshot();
});

it('should generate a <Shape> with a radius property of 0 when top left radius prop is negative', () => {
const rectangle = ReactTestRenderer.create(
<Rectangle radiusTopLeft={-25} width={50} height={50} />,
);
expect(rectangle.toJSON()).toMatchSnapshot();
});

it('should generate a <Shape> with a radius property of 0 when top right radius prop is negative', () => {
const rectangle = ReactTestRenderer.create(
<Rectangle radiusTopRight={-25} width={50} height={50} />,
);
expect(rectangle.toJSON()).toMatchSnapshot();
});

it('should generate a <Shape> with a radius property of 0 when bottom right radius prop is negative', () => {
const rectangle = ReactTestRenderer.create(
<Rectangle radiusBottomRight={-30} width={50} height={50} />,
);
expect(rectangle.toJSON()).toMatchSnapshot();
});

it('should generate a <Shape> with a radius property of 0 when bottom left radius prop is negative', () => {
const rectangle = ReactTestRenderer.create(
<Rectangle radiusBottomLeft={-25} width={50} height={50} />,
);
expect(rectangle.toJSON()).toMatchSnapshot();
});

it('should generate a <Shape> where top radius is 0 if the sum of the top radius is greater than width', () => {
const rectangle = ReactTestRenderer.create(
<Rectangle
radiusTopRight={25}
radiusTopLeft={26}
width={50}
height={40}
/>,
);
expect(rectangle.toJSON()).toMatchSnapshot();
});

it('should warn if width/height is missing on a Rectangle component', () => {
expect(() =>
ReactTestRenderer.create(<Rectangle stroke="green" fill="blue" />),
Expand Down
169 changes: 169 additions & 0 deletions packages/react-art/src/__tests__/__snapshots__/ReactART-test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,174 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ReactARTComponents should generate a <Shape> where top radius is 0 if the sum of the top radius is greater than width 1`] = `
<Shape
d={
Object {
"_pivotX": 0,
"_pivotY": 0,
"path": Array [
[Function],
[Function],
[Function],
[Function],
[Function],
],
"penDownX": 0,
"penDownY": 0,
"penX": 0,
"penY": 0,
}
}
height={40}
radiusTopLeft={26}
radiusTopRight={25}
width={50}
/>
`;
exports[`ReactARTComponents should generate a <Shape> with a radius property of 0 when bottom left radius prop is negative 1`] = `
<Shape
d={
Object {
"_pivotX": 0,
"_pivotY": 0,
"path": Array [
[Function],
[Function],
[Function],
[Function],
[Function],
],
"penDownX": 0,
"penDownY": 0,
"penX": 0,
"penY": 0,
}
}
height={50}
radiusBottomLeft={-25}
width={50}
/>
`;
exports[`ReactARTComponents should generate a <Shape> with a radius property of 0 when bottom right radius prop is negative 1`] = `
<Shape
d={
Object {
"_pivotX": 0,
"_pivotY": 0,
"path": Array [
[Function],
[Function],
[Function],
[Function],
[Function],
],
"penDownX": 0,
"penDownY": 0,
"penX": 0,
"penY": 0,
}
}
height={50}
radiusBottomRight={-30}
width={50}
/>
`;
exports[`ReactARTComponents should generate a <Shape> with a radius property of 0 when top left radius prop is negative 1`] = `
<Shape
d={
Object {
"_pivotX": 0,
"_pivotY": 0,
"path": Array [
[Function],
[Function],
[Function],
[Function],
[Function],
],
"penDownX": 0,
"penDownY": 0,
"penX": 0,
"penY": 0,
}
}
height={50}
radiusTopLeft={-25}
width={50}
/>
`;
exports[`ReactARTComponents should generate a <Shape> with a radius property of 0 when top right radius prop is negative 1`] = `
<Shape
d={
Object {
"_pivotX": 0,
"_pivotY": 0,
"path": Array [
[Function],
[Function],
[Function],
[Function],
[Function],
],
"penDownX": 0,
"penDownY": 0,
"penX": 0,
"penY": 0,
}
}
height={50}
radiusTopRight={-25}
width={50}
/>
`;
exports[`ReactARTComponents should generate a <Shape> with positive height when height prop is negative 1`] = `
<Shape
d={
Object {
"_pivotX": 0,
"_pivotY": -50,
"path": Array [
[Function],
[Function],
[Function],
[Function],
[Function],
[Function],
],
"penDownX": 0,
"penDownY": -50,
"penX": 0,
"penY": -50,
}
}
height={-50}
width={50}
/>
`;
exports[`ReactARTComponents should generate a <Shape> with positive width when width prop is negative 1`] = `
<Shape
d={
Object {
"_pivotX": -50,
"_pivotY": 0,
"path": Array [
[Function],
[Function],
[Function],
[Function],
[Function],
[Function],
],
"penDownX": -50,
"penDownY": 0,
"penX": -50,
"penY": 0,
}
}
height={50}
width={-50}
/>
`;
exports[`ReactARTComponents should generate a <Shape> with props for drawing the Circle 1`] = `
<Shape
d={
Expand Down

0 comments on commit 9e6604f

Please sign in to comment.