3 * Copyright (C) 2009-2023 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 import { shallow } from 'enzyme';
21 import * as React from 'react';
23 mockAzureBindingDefinition,
24 mockBitbucketCloudBindingDefinition,
25 mockGithubBindingDefinition,
26 } from '../../../../../helpers/mocks/alm-settings';
27 import { AlmKeys } from '../../../../../types/alm-settings';
28 import AlmTabRenderer, { AlmTabRendererProps } from '../AlmTabRenderer';
30 it('should render correctly for multi-ALM binding', () => {
31 expect(shallowRenderAzure({ loadingAlmDefinitions: true })).toMatchSnapshot(
32 'loading ALM definitions'
34 expect(shallowRenderAzure({ loadingProjectCount: true })).toMatchSnapshot(
35 'loading project count'
37 expect(shallowRenderAzure({})).toMatchSnapshot('loaded');
38 expect(shallowRenderAzure({ editedDefinition: mockAzureBindingDefinition() })).toMatchSnapshot(
39 'editing a definition'
43 it('should render correctly for single-ALM binding', () => {
45 shallowRenderAzure({ loadingAlmDefinitions: true, multipleAlmEnabled: false })
47 expect(shallowRenderAzure({ multipleAlmEnabled: false })).toMatchSnapshot();
49 shallowRenderAzure({ definitions: [mockAzureBindingDefinition()], multipleAlmEnabled: false })
53 it('should render correctly with validation', () => {
56 definitions: [mockGithubBindingDefinition()],
58 expect(shallowRender(githubProps)).toMatchSnapshot('default');
59 expect(shallowRender({ ...githubProps, definitions: [] })).toMatchSnapshot('empty');
64 editedDefinition: mockGithubBindingDefinition(),
66 ).toMatchSnapshot('create a second');
72 editedDefinition: mockGithubBindingDefinition(),
74 ).toMatchSnapshot('create a first');
78 almTab: AlmKeys.BitbucketServer, // BitbucketServer will be passed for both Bitbucket variants.
79 definitions: [mockBitbucketCloudBindingDefinition()],
81 ).toMatchSnapshot('pass the correct key for bitbucket cloud');
84 function shallowRenderAzure(props: Partial<AlmTabRendererProps>) {
85 return shallowRender({
86 definitions: [mockAzureBindingDefinition()],
91 function shallowRender(props: Partial<AlmTabRendererProps> = {}) {
94 almTab={AlmKeys.Azure}
95 branchesEnabled={true}
98 loadingAlmDefinitions={false}
99 loadingProjectCount={false}
100 multipleAlmEnabled={true}
106 afterSubmit={jest.fn()}