import GlobalNavPlusMenu from './GlobalNavPlusMenu';
interface Props {
- appState: Pick<T.AppState, 'qualifiers'>;
+ appState: Pick<T.AppState, 'branchesEnabled' | 'qualifiers'>;
currentUser: T.LoggedInUser;
router: Router;
}
componentDidMount() {
this.mounted = true;
- if (hasGlobalPermission(this.props.currentUser, 'provisioning')) {
- this.fetchAlmBindings();
- }
+ this.fetchAlmBindings();
if (this.props.appState.qualifiers.includes('VW')) {
getExtensionStart('governance/console').then(
};
fetchAlmBindings = async () => {
+ const {
+ appState: { branchesEnabled },
+ currentUser
+ } = this.props;
+ const canCreateProject = hasGlobalPermission(currentUser, 'provisioning');
+
+ // getAlmSettings requires branchesEnabled
+ if (!canCreateProject || !branchesEnabled) {
+ return;
+ }
+
const almSettings = await getAlmSettings();
// Import is only available if exactly one binding is configured
return (
<>
<Dropdown
- onOpen={canCreateProject ? this.fetchAlmBindings : undefined}
+ onOpen={this.fetchAlmBindings}
overlay={
<GlobalNavPlusMenu
canCreateApplication={canCreateApplication}
});
it('should render correctly when no rights', async () => {
- const wrapper = shallowRender();
+ const wrapper = shallowRender([], {});
expect(wrapper.type()).toBeNull();
await waitAndUpdate(wrapper);
expect(getAlmSettings).not.toBeCalled();
});
+it('should render correctly if branches not enabled', async () => {
+ const wrapper = shallowRender([PROJECT_CREATION_RIGHT], { branchesEnabled: false });
+ await waitAndUpdate(wrapper);
+ expect(wrapper).toMatchSnapshot();
+ expect(getAlmSettings).not.toBeCalled();
+});
+
it('should render correctly', () => {
expect(
- shallowRender([APP_CREATION_RIGHT, PORTFOLIO_CREATION_RIGHT, PROJECT_CREATION_RIGHT])
+ shallowRender([APP_CREATION_RIGHT, PORTFOLIO_CREATION_RIGHT, PROJECT_CREATION_RIGHT], {})
).toMatchSnapshot('no governance');
const wrapper = shallowRender(
[APP_CREATION_RIGHT, PORTFOLIO_CREATION_RIGHT, PROJECT_CREATION_RIGHT],
- true
+ { enableGovernance: true }
);
wrapper.setState({ boundAlms: ['bitbucket'] });
expect(wrapper).toMatchSnapshot('full rights and alms');
{ alm: AlmKeys.GitHub, key: 'GH1' }
]);
- const wrapper = shallowRender([PROJECT_CREATION_RIGHT]);
+ const wrapper = shallowRender([PROJECT_CREATION_RIGHT], {});
await waitAndUpdate(wrapper);
});
it('should display component creation form', () => {
- const wrapper = shallowRender([PORTFOLIO_CREATION_RIGHT], true);
+ const wrapper = shallowRender([PORTFOLIO_CREATION_RIGHT], { enableGovernance: true });
wrapper.instance().handleComponentCreationClick(ComponentQualifier.Portfolio);
wrapper.setState({ governanceReady: true });
const portfolio = { key: 'portfolio', qualifier: ComponentQualifier.Portfolio };
- const wrapper = shallowRender([], true);
+ const wrapper = shallowRender([], { enableGovernance: true });
it('should redirect to admin', async () => {
wrapper.instance().handleComponentCreate(portfolio);
});
});
-function shallowRender(permissions: string[] = [], enableGovernance = false) {
+function shallowRender(
+ permissions: string[] = [],
+ { enableGovernance = false, branchesEnabled = true }
+) {
return shallow<GlobalNavPlus>(
<GlobalNavPlus
- appState={{ qualifiers: enableGovernance ? [ComponentQualifier.Portfolio] : [] }}
+ appState={{
+ branchesEnabled,
+ qualifiers: enableGovernance ? [ComponentQualifier.Portfolio] : []
+ }}
currentUser={mockLoggedInUser({ permissions: { global: permissions } })}
router={mockRouter()}
/>