Skip to content

Commit

Permalink
Fixes bug where pipelineresources and taskrun pages get changed to pi…
Browse files Browse the repository at this point in the history
…pelineruns page on change to all namespaces
  • Loading branch information
CarolynMabbott authored and tekton-robot committed Dec 10, 2019
1 parent 01538d4 commit 30a0392
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/containers/SideNav/SideNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ export class SideNav extends Component {

if (namespace === ALL_NAMESPACES) {
this.props.selectNamespace(namespace);
const currentURL = this.props.match.url;
if (currentURL.includes(urls.taskRuns.all())) {
history.push(urls.taskRuns.all());
return;
}
if (currentURL.includes(urls.pipelineResources.all())) {
history.push(urls.pipelineResources.all());
return;
}
if (currentURL.includes(urls.pipelines.all())) {
history.push(urls.pipelines.all());
return;
}
history.push('/');
return;
}
Expand Down
106 changes: 104 additions & 2 deletions src/containers/SideNav/SideNav.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { fireEvent } from 'react-testing-library';
import { ALL_NAMESPACES, paths } from '@tektoncd/dashboard-utils';
import { ALL_NAMESPACES, paths, urls } from '@tektoncd/dashboard-utils';

import { renderWithRouter } from '../../utils/test';
import SideNavContainer, { SideNav } from './SideNav';
Expand Down Expand Up @@ -142,7 +142,7 @@ it('SideNav redirects to root when all namespaces selected on namespaced URL', a
<SideNav
extensions={[]}
history={{ push }}
match={{ params: { namespace } }}
match={{ params: { namespace }, url: urls.secrets.all() }}
namespace={namespace}
selectNamespace={selectNamespace}
/>
Expand All @@ -154,6 +154,108 @@ it('SideNav redirects to root when all namespaces selected on namespaced URL', a
expect(push).toHaveBeenCalledWith('/');
});

it('SideNav redirects to TaskRuns page when all namespaces selected on namespaced URL on TaskRuns', async () => {
const middleware = [thunk];
const mockStore = configureStore(middleware);
const namespace = 'default';
const store = mockStore({
namespaces: {
byName: {
[namespace]: true
},
isFetching: false,
selected: namespace
}
});
const selectNamespace = jest.fn();
const push = jest.fn();
const { getByText } = renderWithRouter(
<Provider store={store}>
<SideNav
extensions={[]}
history={{ push }}
match={{ params: { namespace }, url: urls.taskRuns.all() }}
namespace={namespace}
selectNamespace={selectNamespace}
/>
</Provider>
);
fireEvent.click(getByText(namespace));
fireEvent.click(getByText(/all namespaces/i));
expect(selectNamespace).toHaveBeenCalledWith(ALL_NAMESPACES);
expect(push).toHaveBeenCalledWith(urls.taskRuns.all());
});

it('SideNav redirects to PipelineResources page when all namespaces selected on namespaced URL on PipelineResources', async () => {
const middleware = [thunk];
const mockStore = configureStore(middleware);
const namespace = 'default';
const store = mockStore({
namespaces: {
byName: {
[namespace]: true
},
isFetching: false,
selected: namespace
}
});
const selectNamespace = jest.fn();
const push = jest.fn();
const { getByText } = renderWithRouter(
<Provider store={store}>
<SideNav
extensions={[]}
history={{ push }}
match={{
params: { namespace },
url: urls.pipelineResources.all()
}}
namespace={namespace}
selectNamespace={selectNamespace}
/>
</Provider>
);
fireEvent.click(getByText(namespace));
fireEvent.click(getByText(/all namespaces/i));
expect(selectNamespace).toHaveBeenCalledWith(ALL_NAMESPACES);
expect(push).toHaveBeenCalledWith(urls.pipelineResources.all());
});

it('SideNav redirects to Pipelines page when all namespaces selected on namespaced URL on Pipelines', async () => {
const middleware = [thunk];
const mockStore = configureStore(middleware);
const namespace = 'default';
const store = mockStore({
namespaces: {
byName: {
[namespace]: true
},
isFetching: false,
selected: namespace
}
});
const selectNamespace = jest.fn();
const push = jest.fn();
const { getByText } = renderWithRouter(
<Provider store={store}>
<SideNav
extensions={[]}
history={{ push }}
match={{
params: { namespace },
url: urls.pipelines.all()
}}
namespace={namespace}
selectNamespace={selectNamespace}
/>
</Provider>
);
fireEvent.click(getByText(namespace));
fireEvent.click(getByText(/all namespaces/i));
expect(selectNamespace).toHaveBeenCalledWith(ALL_NAMESPACES);
expect(push).toHaveBeenCalledWith(urls.pipelines.all());
});

it('SideNav updates namespace in URL', async () => {
const middleware = [thunk];
const mockStore = configureStore(middleware);
Expand Down

0 comments on commit 30a0392

Please sign in to comment.