3 * Copyright (C) 2009-2019 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 /* eslint-disable import/first, import/order */
21 jest.mock('../../../../api/quality-profiles', () => ({
22 addUser: jest.fn(() => Promise.resolve()),
23 addGroup: jest.fn(() => Promise.resolve())
26 import * as React from 'react';
27 import { shallow } from 'enzyme';
28 import ProfilePermissionsForm from '../ProfilePermissionsForm';
29 import { submit } from 'sonar-ui-common/helpers/testUtils';
31 const addUser = require('../../../../api/quality-profiles').addUser as jest.Mock<any>;
32 const addGroup = require('../../../../api/quality-profiles').addGroup as jest.Mock<any>;
34 const profile = { language: 'js', name: 'Sonar way' };
36 it('adds user', async () => {
37 const onUserAdd = jest.fn();
38 const wrapper = shallow(
39 <ProfilePermissionsForm
41 onGroupAdd={jest.fn()}
47 expect(wrapper).toMatchSnapshot();
49 wrapper.setState({ selected: { login: 'luke' } });
50 expect(wrapper).toMatchSnapshot();
52 submit(wrapper.find('form'));
53 expect(wrapper).toMatchSnapshot();
54 expect(addUser).toBeCalledWith({
58 qualityProfile: 'Sonar way'
61 await new Promise(setImmediate);
62 expect(onUserAdd).toBeCalledWith({ login: 'luke' });
65 it('adds group', async () => {
66 const onGroupAdd = jest.fn();
67 const wrapper = shallow(
68 <ProfilePermissionsForm
70 onGroupAdd={onGroupAdd}
76 expect(wrapper).toMatchSnapshot();
78 wrapper.setState({ selected: { name: 'lambda' } });
79 expect(wrapper).toMatchSnapshot();
81 submit(wrapper.find('form'));
82 expect(wrapper).toMatchSnapshot();
83 expect(addGroup).toBeCalledWith({
87 qualityProfile: 'Sonar way'
90 await new Promise(setImmediate);
91 expect(onGroupAdd).toBeCalledWith({ name: 'lambda' });