3 * Copyright (C) 2009-2018 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 * as React from 'react';
21 import { shallow } from 'enzyme';
22 import AutoPersonalOrganizationBind from '../AutoPersonalOrganizationBind';
23 import { waitAndUpdate, click } from '../../../../helpers/testUtils';
25 const personalOrg = { key: 'personalorg', name: 'Personal Org' };
27 it('should render correctly', async () => {
28 const updateOrganization = jest.fn().mockResolvedValue({ key: personalOrg.key });
29 const onOrgCreated = jest.fn();
30 const wrapper = shallowRender({
31 almInstallId: 'id-foo',
32 importPersonalOrg: personalOrg,
37 expect(wrapper).toMatchSnapshot();
39 wrapper.find('OrganizationDetailsForm').prop<Function>('onContinue')(personalOrg);
40 await waitAndUpdate(wrapper);
42 expect(updateOrganization).toBeCalledWith({ ...personalOrg, installationId: 'id-foo' });
43 expect(onOrgCreated).toBeCalledWith(personalOrg.key);
46 it('should allow to cancel org import', () => {
47 const updateUrlQuery = jest.fn();
48 const wrapper = shallowRender({
49 almInstallId: 'id-foo',
50 importPersonalOrg: personalOrg,
54 click(wrapper.find('DeleteButton'));
55 expect(updateUrlQuery).toBeCalledWith({ almInstallId: undefined, almKey: undefined });
58 function shallowRender(props: Partial<AutoPersonalOrganizationBind['props']> = {}) {
60 <AutoPersonalOrganizationBind
62 backgroundColor: '#0052CC',
63 iconPath: '"/static/authbitbucket/bitbucket.svg"',
64 installationUrl: 'https://bitbucket.org/install/app',
69 avatar: 'http://example.com/avatar',
70 description: 'description-foo',
74 url: 'http://example.com/foo'
76 importPersonalOrg={{ key: 'personalorg', name: 'Personal Org' }}
77 onOrgCreated={jest.fn()}
78 updateOrganization={jest.fn()}
79 updateUrlQuery={jest.fn()}