Skip to content

Commit 92d6646

Browse files
author
charles-edouard.breteche
committed
Use install properties to check if triggers is installed
1 parent 57082bc commit 92d6646

File tree

7 files changed

+34
-36
lines changed

7 files changed

+34
-36
lines changed

src/containers/App/App.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import * as selectors from '../../reducers';
2424
beforeEach(() => {
2525
jest.spyOn(API, 'getPipelines').mockImplementation(() => {});
2626
jest.spyOn(selectors, 'isReadOnly').mockImplementation(() => true);
27+
jest.spyOn(selectors, 'isTriggersInstalled').mockImplementation(() => false);
2728
});
2829

2930
it('App renders successfully', () => {

src/containers/SideNav/SideNav.js

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,19 @@ import { selectNamespace } from '../../actions/namespaces';
3030
import {
3131
getExtensions,
3232
getSelectedNamespace,
33-
isReadOnly
33+
isReadOnly,
34+
isTriggersInstalled
3435
} from '../../reducers';
35-
import { getCustomResource } from '../../api';
3636

3737
import './SideNav.scss';
3838

3939
class SideNav extends Component {
40-
state = {
41-
isTriggersInstalled: false
42-
};
43-
4440
componentDidMount() {
4541
const { match } = this.props;
4642

4743
if (match && match.params.namespace) {
4844
this.props.selectNamespace(match.params.namespace);
4945
}
50-
51-
this.checkTriggersInstalled();
5246
}
5347

5448
componentDidUpdate(prevProps) {
@@ -150,22 +144,8 @@ class SideNav extends Component {
150144
history.push('/');
151145
};
152146

153-
checkTriggersInstalled() {
154-
getCustomResource({
155-
group: 'apiextensions.k8s.io',
156-
version: 'v1beta1',
157-
type: 'customresourcedefinitions',
158-
name: 'eventlisteners.triggers.tekton.dev'
159-
})
160-
.then(() => {
161-
this.setState({ isTriggersInstalled: true });
162-
})
163-
.catch(() => {});
164-
}
165-
166147
render() {
167148
const { extensions, intl, namespace } = this.props;
168-
const { isTriggersInstalled } = this.state;
169149

170150
return (
171151
<CarbonSideNav
@@ -224,7 +204,7 @@ class SideNav extends Component {
224204
>
225205
TaskRuns
226206
</SideNavMenuItem>
227-
{isTriggersInstalled && (
207+
{this.props.isTriggersInstalled && (
228208
<>
229209
<SideNavMenuItem
230210
element={NavLink}
@@ -358,10 +338,15 @@ class SideNav extends Component {
358338
}
359339
}
360340

341+
SideNav.defaultProps = {
342+
isTriggersInstalled: false
343+
};
344+
361345
/* istanbul ignore next */
362346
const mapStateToProps = state => ({
363347
extensions: getExtensions(state),
364348
isReadOnly: isReadOnly(state),
349+
isTriggersInstalled: isTriggersInstalled(state),
365350
namespace: getSelectedNamespace(state)
366351
});
367352

src/containers/SideNav/SideNav.test.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import { ALL_NAMESPACES, paths, urls } from '@tektoncd/dashboard-utils';
2020

2121
import { renderWithRouter } from '../../utils/test';
2222
import SideNavContainer, { SideNavWithIntl as SideNav } from './SideNav';
23-
import * as API from '../../api';
2423
import * as selectors from '../../reducers';
2524

2625
beforeEach(() => {
2726
jest.spyOn(selectors, 'isReadOnly').mockImplementation(() => true);
27+
jest.spyOn(selectors, 'isTriggersInstalled').mockImplementation(() => false);
2828
});
2929

3030
it('SideNav renders with extensions', () => {
@@ -62,17 +62,15 @@ it('SideNav renders with extensions', () => {
6262
});
6363

6464
it('SideNav renders with triggers', async () => {
65-
jest.spyOn(selectors, 'isReadOnly').mockImplementation(() => false);
65+
selectors.isReadOnly.mockImplementation(() => false);
66+
selectors.isTriggersInstalled.mockImplementation(() => true);
6667

6768
const middleware = [thunk];
6869
const mockStore = configureStore(middleware);
6970
const store = mockStore({
7071
extensions: { byName: {} },
7172
namespaces: { byName: {} }
7273
});
73-
jest
74-
.spyOn(API, 'getCustomResource')
75-
.mockImplementation(() => Promise.resolve());
7674
const { queryByText } = renderWithRouter(
7775
<Provider store={store}>
7876
<SideNavContainer />
@@ -589,17 +587,14 @@ it('SideNav updates namespace in URL', async () => {
589587
});
590588

591589
it('SideNav renders import in not read-only mode', async () => {
592-
jest.spyOn(selectors, 'isReadOnly').mockImplementation(() => false);
590+
selectors.isReadOnly.mockImplementation(() => false);
593591

594592
const middleware = [thunk];
595593
const mockStore = configureStore(middleware);
596594
const store = mockStore({
597595
extensions: { byName: {} },
598596
namespaces: { byName: {} }
599597
});
600-
jest
601-
.spyOn(API, 'getCustomResource')
602-
.mockImplementation(() => Promise.resolve());
603598
const { queryByText } = renderWithRouter(
604599
<Provider store={store}>
605600
<SideNavContainer />
@@ -615,9 +610,6 @@ it('SideNav does not render import in read-only mode', async () => {
615610
extensions: { byName: {} },
616611
namespaces: { byName: {} }
617612
});
618-
jest
619-
.spyOn(API, 'getCustomResource')
620-
.mockImplementation(() => Promise.resolve());
621613
const { queryByText } = renderWithRouter(
622614
<Provider store={store}>
623615
<SideNavContainer isReadOnly />

src/reducers/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,7 @@ export function isFetchingEventListeners(state) {
482482
export function isReadOnly(state) {
483483
return propertiesSelectors.isReadOnly(state.properties);
484484
}
485+
486+
export function isTriggersInstalled(state) {
487+
return propertiesSelectors.isTriggersInstalled(state.properties);
488+
}

src/reducers/index.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ import {
4949
isFetchingSecrets,
5050
isFetchingTaskRuns,
5151
isFetchingTasks,
52-
isReadOnly
52+
isReadOnly,
53+
isTriggersInstalled
5354
} from '.';
5455
import * as clusterTaskSelectors from './clusterTasks';
5556
import * as extensionSelectors from './extensions';
@@ -504,3 +505,13 @@ it('isReadOnly', () => {
504505
expect(isReadOnly(state)).toBe(true);
505506
expect(propertiesSelectors.isReadOnly).toHaveBeenCalledWith(state.properties);
506507
});
508+
509+
it('isTriggersInstalled', () => {
510+
jest
511+
.spyOn(propertiesSelectors, 'isTriggersInstalled')
512+
.mockImplementation(() => true);
513+
expect(isTriggersInstalled(state)).toBe(true);
514+
expect(propertiesSelectors.isTriggersInstalled).toHaveBeenCalledWith(
515+
state.properties
516+
);
517+
});

src/reducers/properties.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ export function isReadOnly(state) {
2525
return state.ReadOnly;
2626
}
2727

28+
export function isTriggersInstalled(state) {
29+
return (state.TriggersNamespace && state.TriggersVersion) || false;
30+
}
31+
2832
export default properties;

src/reducers/properties.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ it('INSTALL_PROPERTIES_SUCCESS', () => {
2828

2929
const state = propertiesReducer({}, action);
3030
expect(selectors.isReadOnly(state)).toBe(false);
31+
expect(selectors.isTriggersInstalled(state)).toBe(false);
3132
});

0 commit comments

Comments
 (0)