3 * Copyright (C) 2009-2022 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 { mockComponent } from '../../../../../../helpers/mocks/component';
23 import { mockAppState } from '../../../../../../helpers/testMocks';
25 ProjectInformationRenderer,
26 ProjectInformationRendererProps
27 } from '../ProjectInformationRenderer';
29 jest.mock('react', () => {
31 ...jest.requireActual('react'),
32 useEffect: jest.fn().mockImplementation(f => f()),
33 useRef: jest.fn().mockReturnValue(document.createElement('h2'))
37 it('should render correctly', () => {
38 expect(shallowRender()).toMatchSnapshot('default');
39 expect(shallowRender({ canConfigureNotifications: false })).toMatchSnapshot('with notifications');
40 expect(shallowRender({ canUseBadges: false })).toMatchSnapshot('no badges');
41 expect(shallowRender({ canConfigureNotifications: false, canUseBadges: false })).toMatchSnapshot(
42 'no badges, no notifications'
46 it('should render a private project correctly', () => {
47 expect(shallowRender({ component: mockComponent({ visibility: 'private' }) })).toMatchSnapshot();
50 it('should render an app correctly', () => {
51 const component = mockComponent({ qualifier: 'APP' });
52 expect(shallowRender({ component })).toMatchSnapshot('default');
55 it('should render with description', () => {
56 const component = mockComponent({ description: 'Lorem ipsum' });
57 expect(shallowRender({ component })).toMatchSnapshot();
60 it('should handle missing quality profiles and quality gates', () => {
63 component: mockComponent({ qualityGate: undefined, qualityProfiles: undefined })
68 it('should render app correctly when regulatoryReportFeatureEnabled is false', () => {
71 appState: mockAppState({
72 regulatoryReportFeatureEnabled: false
78 it('should set focus on the heading when rendered', () => {
79 const fakeElement = document.createElement('h2');
80 const focus = jest.fn();
81 (React.useRef as jest.Mock).mockReturnValueOnce({ current: { ...fakeElement, focus } });
84 expect(focus).toHaveBeenCalled();
87 function shallowRender(props: Partial<ProjectInformationRendererProps> = {}) {
89 <ProjectInformationRenderer
90 appState={mockAppState({
91 regulatoryReportFeatureEnabled: true
93 canConfigureNotifications={true}
95 component={mockComponent({ qualifier: 'TRK', visibility: 'public' })}
96 onComponentChange={jest.fn()}
97 onPageChange={jest.fn()}