From 2114158616c522b3cdff8b816d9469bac4047aab Mon Sep 17 00:00:00 2001 From: Philippe Perrin Date: Wed, 27 Jan 2021 15:56:38 +0100 Subject: [PATCH] SONAR-14403 Add monorepo checkbox for Bitbucket server bindings --- .../AlmSpecificForm.tsx | 63 +++-- .../PRDecorationBinding.tsx | 9 +- .../__tests__/AlmSpecificForm-test.tsx | 5 +- .../__tests__/PRDecorationBinding-test.tsx | 37 ++- .../AlmSpecificForm-test.tsx.snap | 261 +++++++++++++++++- .../TutorialSelectionRenderer-test.tsx.snap | 1 + .../JenkinsTutorial-test.tsx.snap | 2 + .../__snapshots__/WebhookStep-test.tsx.snap | 1 + .../src/main/js/helpers/mocks/alm-settings.ts | 1 + .../src/main/js/types/alm-settings.ts | 2 + .../resources/org/sonar/l10n/core.properties | 6 +- 11 files changed, 348 insertions(+), 40 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/AlmSpecificForm.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/AlmSpecificForm.tsx index dc766d34715..67de027591a 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/AlmSpecificForm.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/AlmSpecificForm.tsx @@ -113,6 +113,37 @@ function renderField( ); } +function renderMonoRepoField(props: { + monorepoEnabled: boolean; + value?: boolean; + docLink: string; + onFieldChange: (id: keyof ProjectAlmBindingResponse, value: string | boolean) => void; +}) { + if (!props.monorepoEnabled) { + return null; + } + + return renderBooleanField({ + help: true, + helpParams: { + doc_link: ( + + {translate('learn_more')} + + ) + }, + id: 'monorepo', + onFieldChange: props.onFieldChange, + propKey: 'monorepo', + value: props.value ?? false, + inputExtra: props.value && ( + + {translate('settings.pr_decoration.binding.form.monorepo.warning')} + + ) + }); +} + export default function AlmSpecificForm(props: AlmSpecificFormProps) { const { alm, @@ -138,26 +169,12 @@ export default function AlmSpecificForm(props: AlmSpecificFormProps) { propKey: 'repository', value: repository || '' })} - {monorepoEnabled && - renderBooleanField({ - help: true, - helpParams: { - doc_link: ( - - {translate('learn_more')} - - ) - }, - id: 'azure.monorepo', - onFieldChange: props.onFieldChange, - propKey: 'monorepo', - value: monorepo ?? false, - inputExtra: monorepo && ( - - {translate('settings.pr_decoration.binding.form.azure.monorepo.warning')} - - ) - })} + {renderMonoRepoField({ + monorepoEnabled, + value: monorepo, + docLink: '/documentation/analysis/azuredevops-integration/', + onFieldChange: props.onFieldChange + })} ); case AlmKeys.Bitbucket: @@ -195,6 +212,12 @@ export default function AlmSpecificForm(props: AlmSpecificFormProps) { propKey: 'slug', value: slug || '' })} + {renderMonoRepoField({ + monorepoEnabled, + value: monorepo, + docLink: '/documentation/analysis/bitbucket-integration/', + onFieldChange: props.onFieldChange + })} ); case AlmKeys.GitHub: diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/PRDecorationBinding.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/PRDecorationBinding.tsx index 0749c3ad204..f351c4d487a 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/PRDecorationBinding.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/PRDecorationBinding.tsx @@ -181,15 +181,18 @@ export class PRDecorationBinding extends React.PureComponent { expect(shallowRender(alm, { monorepoEnabled })).toMatchSnapshot(); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-test.tsx index fd5ea3e18c6..1e52df759ce 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-test.tsx @@ -146,7 +146,8 @@ describe('handleSubmit', () => { const bitbucketKey = 'bitbucket'; const repository = 'repoKey'; const slug = 'repoSlug'; - wrapper.setState({ formData: { key: bitbucketKey, repository, slug }, instances }); + const monorepo = true; + wrapper.setState({ formData: { key: bitbucketKey, repository, slug, monorepo }, instances }); wrapper.instance().handleSubmit(); await waitAndUpdate(wrapper); @@ -154,7 +155,8 @@ describe('handleSubmit', () => { almSetting: bitbucketKey, project: PROJECT_KEY, repository, - slug + slug, + monorepo }); expect(wrapper.state().success).toBe(true); }); @@ -258,6 +260,37 @@ it('should accept submit azure settings', async () => { }); }); +it('should reject submitted bbs settings', async () => { + const wrapper = shallowRender(); + + expect.assertions(2); + await expect( + wrapper + .instance() + .submitProjectAlmBinding(AlmKeys.Bitbucket, 'bbs-binding', { slug: 'project' }) + ).rejects.toBeUndefined(); + await expect( + wrapper + .instance() + .submitProjectAlmBinding(AlmKeys.Bitbucket, 'bbs-binding', { repository: 'repo' }) + ).rejects.toBeUndefined(); +}); + +it('should accept submit bbs settings', async () => { + const wrapper = shallowRender(); + await wrapper.instance().submitProjectAlmBinding(AlmKeys.Bitbucket, 'bbs', { + repository: 'bbs-repo', + slug: 'bbs-project' + }); + expect(setProjectBitbucketBinding).toHaveBeenCalledWith({ + almSetting: 'bbs', + project: PROJECT_KEY, + repository: 'bbs-repo', + slug: 'bbs-project', + monorepo: false + }); +}); + it('should reject submit github settings', async () => { const wrapper = shallowRender(); diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/__snapshots__/AlmSpecificForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/__snapshots__/AlmSpecificForm-test.tsx.snap index a1856461bb7..3a91ce2c977 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/__snapshots__/AlmSpecificForm-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/__snapshots__/AlmSpecificForm-test.tsx.snap @@ -152,15 +152,15 @@ exports[`it should render correctly for azure and monorepo=true 1`] = ` >