3 * Copyright (C) 2009-2021 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 mockGithubBindingDefinition
25 } from '../../../../../helpers/mocks/alm-settings';
29 AzureBindingDefinition
30 } from '../../../../../types/alm-settings';
31 import AlmTabRenderer, { AlmTabRendererProps } from '../AlmTabRenderer';
33 it('should render correctly for multi-ALM binding', () => {
34 expect(shallowRenderAzure({ loadingAlmDefinitions: true })).toMatchSnapshot(
35 'loading ALM definitions'
37 expect(shallowRenderAzure({ loadingProjectCount: true })).toMatchSnapshot(
38 'loading project count'
40 expect(shallowRenderAzure({ submitting: true })).toMatchSnapshot('submitting');
41 expect(shallowRenderAzure()).toMatchSnapshot('loaded');
42 expect(shallowRenderAzure({ editedDefinition: mockAzureBindingDefinition() })).toMatchSnapshot(
43 'editing a definition'
47 it('should render correctly for single-ALM binding', () => {
49 shallowRenderAzure({ loadingAlmDefinitions: true, multipleAlmEnabled: false })
51 expect(shallowRenderAzure({ multipleAlmEnabled: false })).toMatchSnapshot();
53 shallowRenderAzure({ definitions: [mockAzureBindingDefinition()], multipleAlmEnabled: false })
57 it('should render correctly with validation', () => {
60 defaultBinding: mockGithubBindingDefinition(),
61 definitions: [mockGithubBindingDefinition()]
63 expect(shallowRender(githubProps)).toMatchSnapshot();
64 expect(shallowRender({ ...githubProps, definitions: [] })).toMatchSnapshot('empty');
69 editedDefinition: mockGithubBindingDefinition()
71 ).toMatchSnapshot('create a second');
77 editedDefinition: mockGithubBindingDefinition()
79 ).toMatchSnapshot('create a first');
82 function shallowRenderAzure(props: Partial<AlmTabRendererProps<AzureBindingDefinition>> = {}) {
83 return shallowRender({
84 defaultBinding: mockAzureBindingDefinition(),
85 definitions: [mockAzureBindingDefinition()],
90 function shallowRender<B extends AlmBindingDefinition>(
91 props: Partial<AlmTabRendererProps<B>> = {}
96 defaultBinding={{} as any}
101 loadingAlmDefinitions={false}
102 loadingProjectCount={false}
103 multipleAlmEnabled={true}