Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent double prefixing paths for navigation items in system menu. #5703

Merged
merged 2 commits into from Feb 26, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -3,10 +3,8 @@ import PropTypes from 'prop-types';
import { MenuItem } from 'react-bootstrap';
import { LinkContainer } from 'react-router-bootstrap';

import URLUtils from 'util/URLUtils';

const NavigationLink = ({ description, path, ...rest }) => (
<LinkContainer key={path} to={URLUtils.appPrefixed(path)} {...rest}>
<LinkContainer key={path} to={path} {...rest}>
<MenuItem>{description}</MenuItem>
</LinkContainer>
);
@@ -1,17 +1,25 @@
import React from 'react';
import { mount, shallow } from 'enzyme';
import NavigationLink from './NavigationLink';
import URLUtils from '../../util/URLUtils';

jest.mock('util/URLUtils', () => ({ appPrefixed: path => `/prefix${path}` }));
jest.mock('util/URLUtils', () => ({ appPrefixed: jest.fn(path => path) }));

describe('NavigationLink', () => {
it('renders with simple props', () => {
const wrapper = mount(<NavigationLink description="Hello there!" path="/hello" />);
expect(wrapper.find('LinkContainer')).toHaveProp('to', '/prefix/hello');
expect(wrapper.find('LinkContainer')).toHaveProp('to', '/hello');
expect(wrapper.find('MenuItem')).toHaveText('Hello there!');
});
it('passes props to LinkContainer', () => {
const wrapper = shallow(<NavigationLink description="Hello there!" path="/hello" someProp={42} />);
expect(wrapper.find('LinkContainer')).toHaveProp('someProp', 42);
});
it('does not prefix URL with app prefix', () => {
URLUtils.appPrefixed.mockImplementation(path => `/someprefix${path}`);
const wrapper = shallow(<NavigationLink description="Hello there!" path="/hello" someProp={42} />);
const linkContainer = wrapper.find('LinkContainer');
expect(linkContainer.props().to).not.toContain('/someprefix');
expect(URLUtils.appPrefixed).not.toHaveBeenCalled();
});
});
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.