3 * Copyright (C) 2009-2021 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 { mockTask } from '../../../../../helpers/mocks/tasks';
23 import { mockComponent, mockLocation } from '../../../../../helpers/testMocks';
24 import { TaskStatuses } from '../../../../../types/tasks';
25 import { ComponentNavBgTaskNotif } from '../ComponentNavBgTaskNotif';
27 jest.mock('sonar-ui-common/helpers/l10n', () => ({
28 ...jest.requireActual('sonar-ui-common/helpers/l10n'),
29 hasMessage: jest.fn().mockReturnValue(true)
32 it('renders correctly', () => {
33 expect(shallowRender()).toMatchSnapshot('default');
34 expect(shallowRender({ isPending: true })).toMatchSnapshot('pending');
37 component: mockComponent({ configuration: { showBackgroundTasks: true } }),
40 ).toMatchSnapshot('pending for admins');
41 expect(shallowRender({ isInProgress: true, isPending: true })).toMatchSnapshot('in progress');
44 currentTask: mockTask({
45 status: TaskStatuses.Failed,
46 errorType: 'LICENSING',
50 ).toMatchSnapshot('license issue');
53 currentTask: mockTask({ branch: 'my/branch', status: TaskStatuses.Failed }),
54 currentTaskOnSameBranch: false
56 ).toMatchSnapshot('branch');
59 currentTask: mockTask({ branch: 'my/branch', status: TaskStatuses.Failed }),
60 currentTaskOnSameBranch: false
62 ).toMatchSnapshot('branch for admins');
65 component: mockComponent({ configuration: { showBackgroundTasks: true } }),
66 currentTask: mockTask({
68 pullRequestTitle: 'feature/my_pr',
69 status: TaskStatuses.Failed
71 currentTaskOnSameBranch: false
73 ).toMatchSnapshot('pull request');
76 component: mockComponent({ configuration: { showBackgroundTasks: true } }),
77 currentTask: mockTask({
79 pullRequestTitle: 'feature/my_pr',
80 status: TaskStatuses.Failed
82 currentTaskOnSameBranch: false
84 ).toMatchSnapshot('pull request for admins');
87 component: mockComponent({ configuration: { showBackgroundTasks: true } }),
88 location: mockLocation({ pathname: '/project/background_tasks' })
90 ).toMatchSnapshot('on background task page');
93 component: mockComponent({ configuration: { showBackgroundTasks: true } }),
94 currentTask: mockTask({ branch: 'my/branch', status: TaskStatuses.Failed }),
95 currentTaskOnSameBranch: false,
96 location: mockLocation({ pathname: '/project/background_tasks' })
98 ).toMatchSnapshot('on background task page for branch');
99 expect(shallowRender({ currentTask: undefined })).toMatchSnapshot('no current task');
102 function shallowRender(props: Partial<ComponentNavBgTaskNotif['props']> = {}) {
103 return shallow<ComponentNavBgTaskNotif>(
104 <ComponentNavBgTaskNotif
105 component={mockComponent()}
106 currentTask={mockTask({ status: TaskStatuses.Failed })}
107 location={mockLocation()}