@@ -26,6 +26,11 @@ const ReactART = require('react-art');
2626const ARTSVGMode = require ( 'art/modes/svg' ) ;
2727const ARTCurrentMode = require ( 'art/modes/current' ) ;
2828
29+ const renderer = require ( 'react-test-renderer' ) ;
30+ const Circle = require ( 'react-art/Circle' ) ;
31+ const Rectangle = require ( 'react-art/Rectangle' ) ;
32+ const Wedge = require ( 'react-art/Wedge' ) ;
33+
2934function testDOMNodeStructure ( domNode , expectedStructure ) {
3035 expect ( domNode ) . toBeDefined ( ) ;
3136 expect ( domNode . nodeName ) . toBe ( expectedStructure . nodeName ) ;
@@ -329,3 +334,91 @@ describe('ReactART', () => {
329334 expect ( onClick2 ) . toBeCalled ( ) ;
330335 } ) ;
331336} ) ;
337+
338+ describe ( 'ReactARTComponents' , ( ) => {
339+ function normalizeCodeLocInfo ( str ) {
340+ return str && str . replace ( / \( a t .+ ?: \d + \) / g, '(at **)' ) ;
341+ }
342+
343+ it ( 'should generate a <Shape> with props for drawing the Circle' , ( ) => {
344+ const circle = renderer . create (
345+ < Circle radius = { 10 } stroke = "green" strokeWidth = { 3 } fill = "blue" /> ,
346+ ) ;
347+ expect ( circle . toJSON ( ) ) . toMatchSnapshot ( ) ;
348+ } ) ;
349+
350+ it ( 'should warn if radius is missing on a Circle component' , ( ) => {
351+ spyOnDev ( console , 'error' ) ;
352+ renderer . create ( < Circle stroke = "green" strokeWidth = { 3 } fill = "blue" /> ) ;
353+ if ( __DEV__ ) {
354+ expect ( console . error . calls . count ( ) ) . toBe ( 1 ) ;
355+ expect ( normalizeCodeLocInfo ( console . error . calls . argsFor ( 0 ) [ 0 ] ) ) . toEqual (
356+ 'Warning: Failed prop type: The prop `radius` is marked as required in `Circle`, ' +
357+ 'but its value is `undefined`.' +
358+ '\n in Circle (at **)' ,
359+ ) ;
360+ }
361+ } ) ;
362+
363+ it ( 'should generate a <Shape> with props for drawing the Rectangle' , ( ) => {
364+ const rectangle = renderer . create (
365+ < Rectangle width = { 50 } height = { 50 } stroke = "green" fill = "blue" /> ,
366+ ) ;
367+ expect ( rectangle . toJSON ( ) ) . toMatchSnapshot ( ) ;
368+ } ) ;
369+
370+ it ( 'should warn if width/height is missing on a Rectangle component' , ( ) => {
371+ spyOnDev ( console , 'error' ) ;
372+ renderer . create ( < Rectangle stroke = "green" fill = "blue" /> ) ;
373+ if ( __DEV__ ) {
374+ expect ( console . error . calls . count ( ) ) . toBe ( 2 ) ;
375+ expect ( normalizeCodeLocInfo ( console . error . calls . argsFor ( 0 ) [ 0 ] ) ) . toEqual (
376+ 'Warning: Failed prop type: The prop `width` is marked as required in `Rectangle`, ' +
377+ 'but its value is `undefined`.' +
378+ '\n in Rectangle (at **)' ,
379+ ) ;
380+ expect ( normalizeCodeLocInfo ( console . error . calls . argsFor ( 1 ) [ 0 ] ) ) . toEqual (
381+ 'Warning: Failed prop type: The prop `height` is marked as required in `Rectangle`, ' +
382+ 'but its value is `undefined`.' +
383+ '\n in Rectangle (at **)' ,
384+ ) ;
385+ }
386+ } ) ;
387+
388+ it ( 'should generate a <Shape> with props for drawing the Wedge' , ( ) => {
389+ const wedge = renderer . create (
390+ < Wedge outerRadius = { 50 } startAngle = { 0 } endAngle = { 360 } fill = "blue" /> ,
391+ ) ;
392+ expect ( wedge . toJSON ( ) ) . toMatchSnapshot ( ) ;
393+ } ) ;
394+
395+ it ( 'should return null if startAngle equals to endAngle on Wedge' , ( ) => {
396+ const wedge = renderer . create (
397+ < Wedge outerRadius = { 50 } startAngle = { 0 } endAngle = { 0 } fill = "blue" /> ,
398+ ) ;
399+ expect ( wedge . toJSON ( ) ) . toBeNull ( ) ;
400+ } ) ;
401+
402+ it ( 'should warn if outerRadius/startAngle/endAngle is missing on a Wedge component' , ( ) => {
403+ spyOnDev ( console , 'error' ) ;
404+ renderer . create ( < Wedge fill = "blue" /> ) ;
405+ if ( __DEV__ ) {
406+ expect ( console . error . calls . count ( ) ) . toBe ( 3 ) ;
407+ expect ( normalizeCodeLocInfo ( console . error . calls . argsFor ( 0 ) [ 0 ] ) ) . toEqual (
408+ 'Warning: Failed prop type: The prop `outerRadius` is marked as required in `Wedge`, ' +
409+ 'but its value is `undefined`.' +
410+ '\n in Wedge (at **)' ,
411+ ) ;
412+ expect ( normalizeCodeLocInfo ( console . error . calls . argsFor ( 1 ) [ 0 ] ) ) . toEqual (
413+ 'Warning: Failed prop type: The prop `startAngle` is marked as required in `Wedge`, ' +
414+ 'but its value is `undefined`.' +
415+ '\n in Wedge (at **)' ,
416+ ) ;
417+ expect ( normalizeCodeLocInfo ( console . error . calls . argsFor ( 2 ) [ 0 ] ) ) . toEqual (
418+ 'Warning: Failed prop type: The prop `endAngle` is marked as required in `Wedge`, ' +
419+ 'but its value is `undefined`.' +
420+ '\n in Wedge (at **)' ,
421+ ) ;
422+ }
423+ } ) ;
424+ } ) ;
0 commit comments