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 ComponentNavLicenseNotif from '../ComponentNavLicenseNotif';
23 import { isValidLicense } from '../../../../../api/marketplace';
24 import { waitAndUpdate } from '../../../../../helpers/testUtils';
26 jest.mock('../../../../../helpers/l10n', () => {
27 const l10n = require.requireActual('../../../../../helpers/l10n');
28 l10n.hasMessage = jest.fn(() => true);
32 jest.mock('../../../../../api/marketplace', () => ({
33 isValidLicense: jest.fn().mockResolvedValue({ isValidLicense: false })
37 (isValidLicense as jest.Mock<any>).mockClear();
40 it('renders background task license info correctly', async () => {
41 let wrapper = getWrapper({
42 currentTask: { status: 'FAILED', errorType: 'LICENSING', errorMessage: 'Foo' }
44 await waitAndUpdate(wrapper);
45 expect(wrapper).toMatchSnapshot();
48 { currentTask: { status: 'FAILED', errorType: 'LICENSING', errorMessage: 'Foo' } },
51 await waitAndUpdate(wrapper);
52 expect(wrapper).toMatchSnapshot();
55 it('renders a different message if the license is valid', async () => {
56 (isValidLicense as jest.Mock<any>).mockResolvedValueOnce({ isValidLicense: true });
57 const wrapper = getWrapper({
58 currentTask: { status: 'FAILED', errorType: 'LICENSING', errorMessage: 'Foo' }
60 await waitAndUpdate(wrapper);
61 expect(wrapper).toMatchSnapshot();
64 it('renders correctly for LICENSING_LOC error', async () => {
65 (isValidLicense as jest.Mock<any>).mockResolvedValueOnce({ isValidLicense: true });
66 const wrapper = getWrapper({
67 currentTask: { status: 'FAILED', errorType: 'LICENSING_LOC', errorMessage: 'Foo' }
69 await waitAndUpdate(wrapper);
70 expect(wrapper).toMatchSnapshot();
73 function getWrapper(props = {}, context = {}) {
75 <ComponentNavLicenseNotif
76 currentTask={{ errorMessage: 'Foo', errorType: 'LICENSING' } as T.Task}
79 { context: { canAdmin: true, ...context } }