3 * Copyright (C) 2009-2023 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';
23 mockProjectGithubBindingResponse,
24 mockProjectGitLabBindingResponse,
25 } from '../../../../../../helpers/mocks/alm-settings';
26 import { mockMainBranch } from '../../../../../../helpers/mocks/branch-like';
27 import { mockComponent } from '../../../../../../helpers/mocks/component';
28 import { ComponentQualifier } from '../../../../../../types/component';
29 import { CurrentBranchLike, CurrentBranchLikeProps } from '../CurrentBranchLike';
31 describe('applications', () => {
32 it('should render correctly when there is only one branch and the user can admin the application', () => {
33 const wrapper = shallowRender({
34 component: mockComponent({
35 configuration: { showSettings: true },
36 qualifier: ComponentQualifier.Application,
38 hasManyBranches: false,
40 expect(wrapper).toMatchSnapshot();
43 it("should render correctly when there is only one branch and the user CAN'T admin the application", () => {
44 const wrapper = shallowRender({
45 component: mockComponent({
46 configuration: { showSettings: false },
47 qualifier: ComponentQualifier.Application,
49 hasManyBranches: false,
51 expect(wrapper).toMatchSnapshot();
54 it('should render correctly when there are many branchlikes', () => {
55 const wrapper = shallowRender({
56 branchesEnabled: true,
57 component: mockComponent({
58 qualifier: ComponentQualifier.Application,
60 hasManyBranches: true,
62 expect(wrapper).toMatchSnapshot();
66 describe('projects', () => {
67 it('should render correctly when branches support is disabled', () => {
70 branchesEnabled: false,
71 component: mockComponent({
72 qualifier: ComponentQualifier.Project,
75 ).toMatchSnapshot('default');
78 branchesEnabled: false,
79 component: mockComponent({
80 qualifier: ComponentQualifier.Project,
82 projectBinding: mockProjectGithubBindingResponse(),
84 ).toMatchSnapshot('alm with prs');
87 branchesEnabled: false,
88 component: mockComponent({
89 qualifier: ComponentQualifier.Project,
91 projectBinding: mockProjectGitLabBindingResponse(),
93 ).toMatchSnapshot('alm with mrs');
96 it('should render correctly when there is only one branchlike', () => {
97 const wrapper = shallowRender({
98 branchesEnabled: true,
99 component: mockComponent({
100 qualifier: ComponentQualifier.Project,
102 hasManyBranches: false,
104 expect(wrapper).toMatchSnapshot();
107 it('should render correctly when there are many branchlikes', () => {
108 const wrapper = shallowRender({
109 branchesEnabled: true,
110 component: mockComponent({
111 qualifier: ComponentQualifier.Project,
113 hasManyBranches: true,
115 expect(wrapper).toMatchSnapshot();
119 function shallowRender(props?: Partial<CurrentBranchLikeProps>) {
122 branchesEnabled={false}
123 component={mockComponent()}
124 currentBranchLike={mockMainBranch()}
125 hasManyBranches={false}