Skip to content

Commit

Permalink
Fix root redirects not working as expected
Browse files Browse the repository at this point in the history
- If enterpriseSearchUrl hasn't been set, all pages should redirect to SetupGuide, not just root
- The engines redirect simply wasn't working at all - it would always show a blank page when '/' was clicked in the Kibana breadcrumbs. Not sure if this is a Kibana issue - had to change to a component load to fix
+ Simplify index.test.tsx (probably unreasonable and not super helpful to add assertions for each new route)
  • Loading branch information
cee-chen committed Aug 10, 2020
1 parent 113a620 commit e94f8ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,22 @@ import React, { useContext } from 'react';
import { Redirect } from 'react-router-dom';
import { shallow } from 'enzyme';

import { SideNav, SideNavLink } from '../shared/layout';
import { SetupGuide } from './components/setup_guide';
import { EngineOverview } from './components/engine_overview';

import { Layout, SideNav, SideNavLink } from '../shared/layout';
import { AppSearch, AppSearchNav } from './';

describe('App Search Routes', () => {
describe('/', () => {
it('redirects to Setup Guide when enterpriseSearchUrl is not set', () => {
(useContext as jest.Mock).mockImplementationOnce(() => ({ enterpriseSearchUrl: '' }));
const wrapper = shallow(<AppSearch />);

expect(wrapper.find(Redirect)).toHaveLength(1);
expect(wrapper.find(EngineOverview)).toHaveLength(0);
});

it('renders Engine Overview when enterpriseSearchUrl is set', () => {
(useContext as jest.Mock).mockImplementationOnce(() => ({
enterpriseSearchUrl: 'https://foo.bar',
}));
const wrapper = shallow(<AppSearch />);

expect(wrapper.find(EngineOverview)).toHaveLength(1);
expect(wrapper.find(Redirect)).toHaveLength(0);
});
describe('AppSearch', () => {
it('renders', () => {
const wrapper = shallow(<AppSearch />);

expect(wrapper.find(Layout)).toHaveLength(1);
});

describe('/setup_guide', () => {
it('renders', () => {
const wrapper = shallow(<AppSearch />);
it('redirects to Setup Guide when enterpriseSearchUrl is not set', () => {
(useContext as jest.Mock).mockImplementationOnce(() => ({ enterpriseSearchUrl: '' }));
const wrapper = shallow(<AppSearch />);

expect(wrapper.find(SetupGuide)).toHaveLength(1);
});
expect(wrapper.find(Redirect)).toHaveLength(1);
expect(wrapper.find(Layout)).toHaveLength(0);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,30 @@ import { EngineOverview } from './components/engine_overview';

export const AppSearch: React.FC = () => {
const { enterpriseSearchUrl } = useContext(KibanaContext) as IKibanaContext;
if (!enterpriseSearchUrl)
return (
<Switch>
<Route exact path="/setup_guide">
<SetupGuide />
</Route>
<Route>
<Redirect to="/setup_guide" />
<SetupGuide />
</Route>
</Switch>
);

return (
<Switch>
<Route exact path="/">
{!enterpriseSearchUrl ? <Redirect to="/setup_guide" /> : <Redirect to="/engines" />}
</Route>
<Route exact path="/setup_guide">
<SetupGuide />
</Route>
<Route>
<Layout navigation={<AppSearchNav />}>
<Switch>
<Route exact path="/">
<EngineOverview />
</Route>
<Route exact path="/engines">
<EngineOverview />
</Route>
Expand Down

0 comments on commit e94f8ff

Please sign in to comment.