From 8ec146c38ee4f4c84b6ecf59f52de3371224e8bd Mon Sep 17 00:00:00 2001 From: Yu Tian Date: Wed, 13 Dec 2017 23:45:30 +1100 Subject: [PATCH] Rudimentary tests for not covered entry points (#11835) * Add basic snapshot tests to ReactART components (Circle, Rectangle, Wedge) * More tests on Circle, Rectangle, Wedge * linc warning fixes * - remove tests to Wedge component internal function * More test on Wedge component, update snapshots --- packages/react-art/Circle.js | 14 +++ packages/react-art/Rectangle.js | 14 +++ packages/react-art/Wedge.js | 14 +++ .../react-art/src/__tests__/ReactART-test.js | 93 +++++++++++++++++++ .../__snapshots__/ReactART-test.js.snap | 77 +++++++++++++++ 5 files changed, 212 insertions(+) create mode 100644 packages/react-art/Circle.js create mode 100644 packages/react-art/Rectangle.js create mode 100644 packages/react-art/Wedge.js create mode 100644 packages/react-art/src/__tests__/__snapshots__/ReactART-test.js.snap diff --git a/packages/react-art/Circle.js b/packages/react-art/Circle.js new file mode 100644 index 0000000000..5964953de9 --- /dev/null +++ b/packages/react-art/Circle.js @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +'use strict'; + +const Circle = require('./npm/Circle'); + +module.exports = Circle; diff --git a/packages/react-art/Rectangle.js b/packages/react-art/Rectangle.js new file mode 100644 index 0000000000..e3c16d36cc --- /dev/null +++ b/packages/react-art/Rectangle.js @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +'use strict'; + +const Rectangle = require('./npm/Rectangle'); + +module.exports = Rectangle; diff --git a/packages/react-art/Wedge.js b/packages/react-art/Wedge.js new file mode 100644 index 0000000000..906fbd0041 --- /dev/null +++ b/packages/react-art/Wedge.js @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +'use strict'; + +const Wedge = require('./npm/Wedge'); + +module.exports = Wedge; diff --git a/packages/react-art/src/__tests__/ReactART-test.js b/packages/react-art/src/__tests__/ReactART-test.js index 2bc5314a1d..5aed8ca6b2 100644 --- a/packages/react-art/src/__tests__/ReactART-test.js +++ b/packages/react-art/src/__tests__/ReactART-test.js @@ -26,6 +26,11 @@ const ReactART = require('react-art'); const ARTSVGMode = require('art/modes/svg'); const ARTCurrentMode = require('art/modes/current'); +const renderer = require('react-test-renderer'); +const Circle = require('react-art/Circle'); +const Rectangle = require('react-art/Rectangle'); +const Wedge = require('react-art/Wedge'); + function testDOMNodeStructure(domNode, expectedStructure) { expect(domNode).toBeDefined(); expect(domNode.nodeName).toBe(expectedStructure.nodeName); @@ -329,3 +334,91 @@ describe('ReactART', () => { expect(onClick2).toBeCalled(); }); }); + +describe('ReactARTComponents', () => { + function normalizeCodeLocInfo(str) { + return str && str.replace(/\(at .+?:\d+\)/g, '(at **)'); + } + + it('should generate a with props for drawing the Circle', () => { + const circle = renderer.create( + , + ); + expect(circle.toJSON()).toMatchSnapshot(); + }); + + it('should warn if radius is missing on a Circle component', () => { + spyOnDev(console, 'error'); + renderer.create(); + if (__DEV__) { + expect(console.error.calls.count()).toBe(1); + expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual( + 'Warning: Failed prop type: The prop `radius` is marked as required in `Circle`, ' + + 'but its value is `undefined`.' + + '\n in Circle (at **)', + ); + } + }); + + it('should generate a with props for drawing the Rectangle', () => { + const rectangle = renderer.create( + , + ); + expect(rectangle.toJSON()).toMatchSnapshot(); + }); + + it('should warn if width/height is missing on a Rectangle component', () => { + spyOnDev(console, 'error'); + renderer.create(); + if (__DEV__) { + expect(console.error.calls.count()).toBe(2); + expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual( + 'Warning: Failed prop type: The prop `width` is marked as required in `Rectangle`, ' + + 'but its value is `undefined`.' + + '\n in Rectangle (at **)', + ); + expect(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toEqual( + 'Warning: Failed prop type: The prop `height` is marked as required in `Rectangle`, ' + + 'but its value is `undefined`.' + + '\n in Rectangle (at **)', + ); + } + }); + + it('should generate a with props for drawing the Wedge', () => { + const wedge = renderer.create( + , + ); + expect(wedge.toJSON()).toMatchSnapshot(); + }); + + it('should return null if startAngle equals to endAngle on Wedge', () => { + const wedge = renderer.create( + , + ); + expect(wedge.toJSON()).toBeNull(); + }); + + it('should warn if outerRadius/startAngle/endAngle is missing on a Wedge component', () => { + spyOnDev(console, 'error'); + renderer.create(); + if (__DEV__) { + expect(console.error.calls.count()).toBe(3); + expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual( + 'Warning: Failed prop type: The prop `outerRadius` is marked as required in `Wedge`, ' + + 'but its value is `undefined`.' + + '\n in Wedge (at **)', + ); + expect(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toEqual( + 'Warning: Failed prop type: The prop `startAngle` is marked as required in `Wedge`, ' + + 'but its value is `undefined`.' + + '\n in Wedge (at **)', + ); + expect(normalizeCodeLocInfo(console.error.calls.argsFor(2)[0])).toEqual( + 'Warning: Failed prop type: The prop `endAngle` is marked as required in `Wedge`, ' + + 'but its value is `undefined`.' + + '\n in Wedge (at **)', + ); + } + }); +}); diff --git a/packages/react-art/src/__tests__/__snapshots__/ReactART-test.js.snap b/packages/react-art/src/__tests__/__snapshots__/ReactART-test.js.snap new file mode 100644 index 0000000000..6ee55d2081 --- /dev/null +++ b/packages/react-art/src/__tests__/__snapshots__/ReactART-test.js.snap @@ -0,0 +1,77 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ReactARTComponents should generate a with props for drawing the Circle 1`] = ` + +`; + +exports[`ReactARTComponents should generate a with props for drawing the Rectangle 1`] = ` + +`; + +exports[`ReactARTComponents should generate a with props for drawing the Wedge 1`] = ` + +`;