From 6bc6f772716da5677aebf976d27e39aa74143d8d Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Thu, 5 Dec 2019 16:03:08 +0100 Subject: [PATCH] SONAR-12512 SONAR-12514 SONAR-12515 Limit binding to 1 if multi ALM is not enabled --- .../AzureTabRenderer.tsx | 6 ++++- .../BitbucketTabRenderer.tsx | 6 ++++- .../GithubTabRenderer.tsx | 6 ++++- .../pullRequestDecoration/TabHeader.tsx | 22 +++++++++++---- .../__tests__/TabHeader-test.tsx | 27 +++++++++++++++++-- .../AzureTabRenderer-test.tsx.snap | 9 ++++--- .../BitbucketTabRenderer-test.tsx.snap | 9 ++++--- .../GithubTabRenderer-test.tsx.snap | 9 ++++--- server/sonar-web/src/main/js/types/types.d.ts | 1 + 9 files changed, 76 insertions(+), 19 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTabRenderer.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTabRenderer.tsx index 6d977223c61..db6a806d09d 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTabRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTabRenderer.tsx @@ -40,7 +40,11 @@ export default function AzureTabRenderer(props: AzureTabRendererProps) { const { definitions, editedDefinition, loading } = props; return ( <> - + - + - + ; + definitionCount: number; onCreate: () => void; } -export default function TabHeader(props: TabHeaderProps) { - const { alm } = props; +export function TabHeader(props: TabHeaderProps) { + const { + alm, + appState: { multipleAlmEnabled }, + definitionCount + } = props; + const showButton = multipleAlmEnabled || definitionCount === 0; return ( <> @@ -50,10 +58,14 @@ export default function TabHeader(props: TabHeaderProps) {

{translate('settings.pr_decoration.table.title')}

- + {showButton && ( + + )}
); } + +export default withAppState(TabHeader); diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/TabHeader-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/TabHeader-test.tsx index 23d743d17cd..d97e88eee6c 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/TabHeader-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/TabHeader-test.tsx @@ -19,14 +19,37 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; +import { Button } from 'sonar-ui-common/components/controls/buttons'; import { ALM_KEYS } from '../../../../../types/alm-settings'; -import TabHeader, { TabHeaderProps } from '../TabHeader'; +import { TabHeader, TabHeaderProps } from '../TabHeader'; it('should render correctly', () => { expect(shallowRender(ALM_KEYS.AZURE)).toMatchSnapshot(); expect(shallowRender(ALM_KEYS.GITHUB)).toMatchSnapshot(); }); +it('should only show the create button if certain conditions are met', () => { + expect( + shallowRender(ALM_KEYS.GITHUB, { appState: { multipleAlmEnabled: false }, definitionCount: 1 }) + .find(Button) + .exists() + ).toBe(false); + + expect( + shallowRender(ALM_KEYS.GITHUB, { appState: { multipleAlmEnabled: false }, definitionCount: 0 }) + .find(Button) + .exists() + ).toBe(true); + + expect( + shallowRender(ALM_KEYS.GITHUB, { appState: { multipleAlmEnabled: true }, definitionCount: 5 }) + .find(Button) + .exists() + ).toBe(true); +}); + function shallowRender(alm: ALM_KEYS, props: Partial = {}) { - return shallow(); + return shallow( + + ); } diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/AzureTabRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/AzureTabRenderer-test.tsx.snap index 2318d371dac..0e6a491e86a 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/AzureTabRenderer-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/AzureTabRenderer-test.tsx.snap @@ -2,8 +2,9 @@ exports[`should render correctly 1`] = ` - - - - - - - - -