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 * as React from 'react';
21 import { byRole, byText } from 'testing-library-selector';
22 import { mockMainBranch } from '../../../../helpers/mocks/branch-like';
23 import { mockSourceViewerFile } from '../../../../helpers/mocks/sources';
24 import { renderComponent } from '../../../../helpers/testReactTestingUtils';
25 import IssueSourceViewerHeader, { Props } from '../IssueSourceViewerHeader';
28 expandAllLines: byRole('button', { name: 'source_viewer.expand_all_lines' }),
29 projectLink: byRole('link', { name: 'MyProject' }),
30 projectName: byText('MyProject'),
31 viewAllIssues: byRole('link', { name: 'source_viewer.view_all_issues' }),
34 it('should render correctly', () => {
35 renderIssueSourceViewerHeader();
37 expect(ui.expandAllLines.get()).toBeInTheDocument();
38 expect(ui.projectLink.get()).toBeInTheDocument();
39 expect(ui.projectName.get()).toBeInTheDocument();
40 expect(ui.viewAllIssues.get()).toBeInTheDocument();
43 it('should not render expandable link', () => {
44 renderIssueSourceViewerHeader({ expandable: false });
46 expect(ui.expandAllLines.query()).not.toBeInTheDocument();
49 it('should not render link to project', () => {
50 renderIssueSourceViewerHeader({ linkToProject: false });
52 expect(ui.projectLink.query()).not.toBeInTheDocument();
53 expect(ui.projectName.get()).toBeInTheDocument();
56 it('should not render project name', () => {
57 renderIssueSourceViewerHeader({ displayProjectName: false });
59 expect(ui.projectLink.query()).not.toBeInTheDocument();
60 expect(ui.projectName.query()).not.toBeInTheDocument();
63 it('should render without issue expand all when no issue', () => {
64 renderIssueSourceViewerHeader({
65 sourceViewerFile: mockSourceViewerFile('foo/bar.ts', 'my-project', {
70 expect(ui.viewAllIssues.query()).not.toBeInTheDocument();
73 function renderIssueSourceViewerHeader(props: Partial<Props> = {}) {
74 return renderComponent(
75 <IssueSourceViewerHeader
76 branchLike={mockMainBranch()}
79 sourceViewerFile={mockSourceViewerFile('foo/bar.ts', 'my-project')}