3 * Copyright (C) 2009-2020 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';
22 import { waitAndUpdate } from 'sonar-ui-common/helpers/testUtils';
27 } from '../../../../../api/alm-settings';
28 import { AlmKeys } from '../../../../../types/alm-settings';
29 import { AlmIntegration } from '../AlmIntegration';
31 jest.mock('../../../../../api/alm-settings', () => ({
32 countBindedProjects: jest.fn().mockResolvedValue(0),
33 deleteConfiguration: jest.fn().mockResolvedValue(undefined),
34 getAlmDefinitions: jest.fn().mockResolvedValue({ github: [] })
41 it('should render correctly', () => {
42 expect(shallowRender()).toMatchSnapshot();
45 it('should handle alm selection', async () => {
46 const wrapper = shallowRender();
48 wrapper.setState({ currentAlm: AlmKeys.Azure });
50 wrapper.instance().handleSelectAlm(AlmKeys.GitHub);
52 await waitAndUpdate(wrapper);
54 expect(wrapper.state().currentAlm).toBe(AlmKeys.GitHub);
57 it('should handle delete', async () => {
58 const toBeDeleted = '45672';
59 (countBindedProjects as jest.Mock).mockResolvedValueOnce(7);
60 const wrapper = shallowRender();
62 wrapper.instance().handleDelete(toBeDeleted);
63 await waitAndUpdate(wrapper);
65 expect(wrapper.state().projectCount).toBe(7);
66 expect(wrapper.state().definitionKeyForDeletion).toBe(toBeDeleted);
69 it('should delete configuration', async () => {
70 (deleteConfiguration as jest.Mock).mockResolvedValueOnce(undefined);
71 const wrapper = shallowRender();
72 wrapper.instance().deleteConfiguration('8345678');
74 await waitAndUpdate(wrapper);
75 expect(wrapper.state().projectCount).toBeUndefined();
76 expect(wrapper.state().definitionKeyForDeletion).toBeUndefined();
79 it('should fetch settings', async () => {
80 const wrapper = shallowRender();
84 .fetchPullRequestDecorationSetting()
86 expect(getAlmDefinitions).toBeCalled();
87 expect(wrapper.state().definitions).toEqual({ github: [] });
88 expect(wrapper.state().loading).toBe(false);
92 function shallowRender() {
93 return shallow<AlmIntegration>(<AlmIntegration appState={{ branchesEnabled: true }} />);