diff --git a/__tests__/components/NavExpandableGroup.test.jsx b/__tests__/components/NavExpandableGroup.test.jsx index 56b0f499fd..68cf571f7d 100644 --- a/__tests__/components/NavExpandableGroup.test.jsx +++ b/__tests__/components/NavExpandableGroup.test.jsx @@ -26,4 +26,38 @@ describe('NavExpandableGroup', () => { expect(component.navItemPaths).toEqual(['/foo', '/bar', '/fiz']); expect(component.isActiveGroup()).toEqual(true); }); + + 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]) => { + test(`when location is ${location}', isActivePath('${path}') returns ${expected} `, () => { + const component = mount( + + + + ).find('NavExpandableGroup').instance(); + + expect(component.isActivePath(path)).toEqual(expected); + }); + }); + }); }); diff --git a/src/components/NavExpandableGroup.jsx b/src/components/NavExpandableGroup.jsx index 70cdbf5adb..ba3058b3df 100644 --- a/src/components/NavExpandableGroup.jsx +++ b/src/components/NavExpandableGroup.jsx @@ -21,7 +21,7 @@ class NavExpandableGroup extends Component { isActivePath = (path) => { const { history } = this.props; - return history.location.pathname.includes(path); + return history.location.pathname.startsWith(path); }; render () {