1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

use beginning of location path name when checking for active items

This commit is contained in:
Jake McDermott 2018-12-17 00:03:27 -05:00
parent 3d730ef8d2
commit 1bb86dbdf0
No known key found for this signature in database
GPG Key ID: 9A6F084352C3A0B7
2 changed files with 35 additions and 1 deletions

View File

@ -26,4 +26,38 @@ describe('NavExpandableGroup', () => {
expect(component.navItemPaths).toEqual(['/foo', '/bar', '/fiz']); expect(component.navItemPaths).toEqual(['/foo', '/bar', '/fiz']);
expect(component.isActiveGroup()).toEqual(true); 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(
<MemoryRouter initialEntries={[location]}>
<Nav aria-label="Test Navigation">
<NavExpandableGroup
groupId="test"
title="Test"
routes={[
{ path: '/foo', title: 'Foo' },
{ path: '/bar', title: 'Bar' },
{ path: '/fiz', title: 'Fiz' },
]}
/>
</Nav>
</MemoryRouter>
).find('NavExpandableGroup').instance();
expect(component.isActivePath(path)).toEqual(expected);
});
});
});
}); });

View File

@ -21,7 +21,7 @@ class NavExpandableGroup extends Component {
isActivePath = (path) => { isActivePath = (path) => {
const { history } = this.props; const { history } = this.props;
return history.location.pathname.includes(path); return history.location.pathname.startsWith(path);
}; };
render () { render () {