]> source.dussan.org Git - sonarqube.git/blob
1f28a742198dce5d104c9aed89c6e153b0a7fd55
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2021 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
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';
26
27 jest.mock('sonar-ui-common/helpers/l10n', () => ({
28   ...jest.requireActual('sonar-ui-common/helpers/l10n'),
29   hasMessage: jest.fn().mockReturnValue(true)
30 }));
31
32 it('renders correctly', () => {
33   expect(shallowRender()).toMatchSnapshot('default');
34   expect(shallowRender({ isPending: true })).toMatchSnapshot('pending');
35   expect(
36     shallowRender({
37       component: mockComponent({ configuration: { showBackgroundTasks: true } }),
38       isPending: true
39     })
40   ).toMatchSnapshot('pending for admins');
41   expect(shallowRender({ isInProgress: true, isPending: true })).toMatchSnapshot('in progress');
42   expect(
43     shallowRender({
44       currentTask: mockTask({
45         status: TaskStatuses.Failed,
46         errorType: 'LICENSING',
47         errorMessage: 'Foo'
48       })
49     })
50   ).toMatchSnapshot('license issue');
51   expect(
52     shallowRender({
53       currentTask: mockTask({ branch: 'my/branch', status: TaskStatuses.Failed }),
54       currentTaskOnSameBranch: false
55     })
56   ).toMatchSnapshot('branch');
57   expect(
58     shallowRender({
59       currentTask: mockTask({ branch: 'my/branch', status: TaskStatuses.Failed }),
60       currentTaskOnSameBranch: false
61     })
62   ).toMatchSnapshot('branch for admins');
63   expect(
64     shallowRender({
65       component: mockComponent({ configuration: { showBackgroundTasks: true } }),
66       currentTask: mockTask({
67         pullRequest: '650',
68         pullRequestTitle: 'feature/my_pr',
69         status: TaskStatuses.Failed
70       }),
71       currentTaskOnSameBranch: false
72     })
73   ).toMatchSnapshot('pull request');
74   expect(
75     shallowRender({
76       component: mockComponent({ configuration: { showBackgroundTasks: true } }),
77       currentTask: mockTask({
78         pullRequest: '650',
79         pullRequestTitle: 'feature/my_pr',
80         status: TaskStatuses.Failed
81       }),
82       currentTaskOnSameBranch: false
83     })
84   ).toMatchSnapshot('pull request for admins');
85   expect(
86     shallowRender({
87       component: mockComponent({ configuration: { showBackgroundTasks: true } }),
88       location: mockLocation({ pathname: '/project/background_tasks' })
89     })
90   ).toMatchSnapshot('on background task page');
91   expect(
92     shallowRender({
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' })
97     })
98   ).toMatchSnapshot('on background task page for branch');
99   expect(shallowRender({ currentTask: undefined })).toMatchSnapshot('no current task');
100 });
101
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()}
108       {...props}
109     />
110   );
111 }