Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReactART:-Added unit Tests in the ReactART, increasing the code coverage #23195

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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