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';
24 import { Step } from '../utils';
26 const personalOrg = { key: 'personalorg', name: 'Personal Org' };
27 const almOrganization = {
28 avatar: 'http://example.com/avatar',
29 description: 'description-foo',
33 url: 'http://example.com/foo'
36 it('should render correctly', async () => {
37 const updateOrganization = jest.fn().mockResolvedValue({ key: personalOrg.key });
38 const handleOrgDetailsFinish = jest.fn();
39 const wrapper = shallowRender({
40 almInstallId: 'id-foo',
41 importPersonalOrg: personalOrg,
42 handleOrgDetailsFinish,
46 expect(wrapper).toMatchSnapshot();
48 wrapper.find('OrganizationDetailsForm').prop<Function>('onContinue')(personalOrg);
49 await waitAndUpdate(wrapper);
50 expect(handleOrgDetailsFinish).toBeCalled();
52 wrapper.setProps({ organization: personalOrg });
53 wrapper.find('PlanStep').prop<Function>('createOrganization')();
54 expect(updateOrganization).toBeCalledWith({ ...personalOrg, installationId: 'id-foo' });
57 it('should allow to cancel org import', () => {
58 const handleCancelImport = jest.fn();
59 const wrapper = shallowRender({
60 almInstallId: 'id-foo',
61 importPersonalOrg: personalOrg,
65 click(wrapper.find('DeleteButton'));
66 expect(handleCancelImport).toBeCalled();
69 function shallowRender(props: Partial<AutoPersonalOrganizationBind['props']> = {}) {
71 <AutoPersonalOrganizationBind
73 backgroundColor: '#0052CC',
74 iconPath: '"/static/authbitbucket/bitbucket.svg"',
75 installationUrl: 'https://bitbucket.org/install/app',
79 almOrganization={almOrganization}
80 handleCancelImport={jest.fn()}
81 handleOrgDetailsFinish={jest.fn()}
82 handleOrgDetailsStepOpen={jest.fn()}
83 importPersonalOrg={{ key: 'personalorg', name: 'Personal Org' }}
85 step={Step.OrganizationDetails}
86 subscriptionPlans={[{ maxNcloc: 100000, price: 10 }, { maxNcloc: 250000, price: 75 }]}
87 updateOrganization={jest.fn()}