11import { render , screen } from '@testing-library/react' ;
2- import { createIcon } from '../createIcon' ;
2+ import { IconDefinition , CreateIconProps , createIcon , SVGPathObject } from '../createIcon' ;
33
4- const iconDef = {
4+ const multiPathIcon : IconDefinition = {
55 name : 'IconName' ,
66 width : 10 ,
77 height : 20 ,
8- svgPath : 'svgPath'
8+ svgPathData : [
9+ { path : 'svgPath1' , className : 'class1' } ,
10+ { path : 'svgPath2' , className : 'class2' }
11+ ] ,
12+ svgClassName : 'test'
913} ;
1014
11- const iconDefWithArrayPath = {
15+ const singlePathIcon : IconDefinition = {
1216 name : 'IconName' ,
1317 width : 10 ,
1418 height : 20 ,
15- svgPath : [
16- { path : 'svgPath1' , className : 'class1' } ,
17- { path : 'svgPath2' , className : 'class2' }
18- ] ,
19+ svgPathData : 'svgPath' ,
1920 svgClassName : 'test'
2021} ;
2122
23+ const iconDef : CreateIconProps = {
24+ name : 'SinglePathIconName' ,
25+ icon : singlePathIcon
26+ } ;
27+
28+ const iconDefWithArrayPath : CreateIconProps = {
29+ name : 'MultiPathIconName' ,
30+ icon : multiPathIcon
31+ } ;
32+
2233const SVGIcon = createIcon ( iconDef ) ;
2334const SVGArrayIcon = createIcon ( iconDefWithArrayPath ) ;
2435
2536test ( 'sets correct viewBox' , ( ) => {
2637 render ( < SVGIcon /> ) ;
2738 expect ( screen . getByRole ( 'img' , { hidden : true } ) ) . toHaveAttribute (
2839 'viewBox' ,
29- `0 0 ${ iconDef . width } ${ iconDef . height } `
40+ `0 0 ${ singlePathIcon . width } ${ singlePathIcon . height } `
3041 ) ;
3142} ) ;
3243
@@ -39,16 +50,16 @@ test('sets correct svgPath if array', () => {
3950 render ( < SVGArrayIcon /> ) ;
4051 const paths = screen . getByRole ( 'img' , { hidden : true } ) . querySelectorAll ( 'path' ) ;
4152 expect ( paths ) . toHaveLength ( 2 ) ;
42- expect ( paths [ 0 ] ) . toHaveAttribute ( 'd' , iconDefWithArrayPath . svgPath [ 0 ] . path ) ;
43- expect ( paths [ 1 ] ) . toHaveAttribute ( 'd' , iconDefWithArrayPath . svgPath [ 1 ] . path ) ;
44- expect ( paths [ 0 ] ) . toHaveClass ( iconDefWithArrayPath . svgPath [ 0 ] . className ) ;
45- expect ( paths [ 1 ] ) . toHaveClass ( iconDefWithArrayPath . svgPath [ 1 ] . className ) ;
53+ expect ( paths [ 0 ] ) . toHaveAttribute ( 'd' , ( multiPathIcon . svgPathData as SVGPathObject [ ] ) [ 0 ] . path ) ;
54+ expect ( paths [ 1 ] ) . toHaveAttribute ( 'd' , ( multiPathIcon . svgPathData as SVGPathObject [ ] ) [ 1 ] . path ) ;
55+ expect ( paths [ 0 ] ) . toHaveClass ( ( multiPathIcon . svgPathData as SVGPathObject [ ] ) [ 0 ] . className ?? '' ) ;
56+ expect ( paths [ 1 ] ) . toHaveClass ( ( multiPathIcon . svgPathData as SVGPathObject [ ] ) [ 1 ] . className ?? '' ) ;
4657} ) ;
4758
4859test ( 'sets correct svgClassName' , ( ) => {
4960 render ( < SVGArrayIcon /> ) ;
5061 const paths = screen . getByRole ( 'img' , { hidden : true } ) ;
51- expect ( paths ) . toHaveClass ( iconDefWithArrayPath . svgClassName ) ;
62+ expect ( paths ) . toHaveClass ( multiPathIcon . svgClassName ?? '' ) ;
5263} ) ;
5364
5465test ( 'aria-hidden is true if no title is specified' , ( ) => {
0 commit comments