2018-12-17 07:42:36 +03:00
import React from 'react' ;
import { MemoryRouter } from 'react-router-dom' ;
import { mount } from 'enzyme' ;
import { Nav } from '@patternfly/react-core' ;
import NavExpandableGroup from '../../src/components/NavExpandableGroup' ;
describe ( 'NavExpandableGroup' , ( ) => {
test ( 'initialization and render' , ( ) => {
const component = mount (
< MemoryRouter initialEntries = { [ '/foo' ] } >
< Nav aria - label = "Test Navigation" >
< NavExpandableGroup
groupId = "test"
2019-01-03 17:40:48 +03:00
groupTitle = "Test"
2018-12-17 07:42:36 +03:00
routes = { [
{ path : '/foo' , title : 'Foo' } ,
{ path : '/bar' , title : 'Bar' } ,
{ path : '/fiz' , title : 'Fiz' } ,
] }
/ >
< / Nav >
< / MemoryRouter >
) . find ( 'NavExpandableGroup' ) . instance ( ) ;
expect ( component . navItemPaths ) . toEqual ( [ '/foo' , '/bar' , '/fiz' ] ) ;
expect ( component . isActiveGroup ( ) ) . toEqual ( true ) ;
} ) ;
2018-12-17 08:03:27 +03:00
describe ( 'isActivePath' , ( ) => {
const params = [
[ '/fo' , '/foo' , false ] ,
[ '/foo' , '/foo' , true ] ,
[ '/foo/1/bar/fiz' , '/foo' , true ] ,
[ '/foo/1/bar/fiz' , 'foo' , false ] ,
[ '/foo/1/bar/fiz' , 'foo/' , false ] ,
[ '/foo/1/bar/fiz' , '/bar' , false ] ,
[ '/foo/1/bar/fiz' , '/fiz' , false ] ,
] ;
params . forEach ( ( [ location , path , expected ] ) => {
2019-04-22 23:34:33 +03:00
test ( ` when location is ${ location } , isActivePath(' ${ path } ') returns ${ expected } ` , ( ) => {
2018-12-17 08:03:27 +03:00
const component = mount (
< MemoryRouter initialEntries = { [ location ] } >
< Nav aria - label = "Test Navigation" >
< NavExpandableGroup
groupId = "test"
2019-01-03 17:40:48 +03:00
groupTitle = "Test"
2018-12-17 08:03:27 +03:00
routes = { [
{ path : '/foo' , title : 'Foo' } ,
{ path : '/bar' , title : 'Bar' } ,
{ path : '/fiz' , title : 'Fiz' } ,
] }
/ >
< / Nav >
< / MemoryRouter >
) . find ( 'NavExpandableGroup' ) . instance ( ) ;
expect ( component . isActivePath ( path ) ) . toEqual ( expected ) ;
} ) ;
} ) ;
} ) ;
2018-12-17 07:42:36 +03:00
} ) ;