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 { mockAnalysisEvent, mockParsedAnalysis } from '../../../../helpers/testMocks';
23 import BranchAnalysisListRenderer, {
24 BranchAnalysisListRendererProps
25 } from '../BranchAnalysisListRenderer';
27 jest.mock('date-fns', () => {
28 const actual = jest.requireActual('date-fns');
31 startOfDay: (date: Date) => {
32 const startDay = new Date(date);
33 startDay.setUTCHours(0, 0, 0, 0);
39 jest.mock('../../../../helpers/dates', () => {
40 const actual = jest.requireActual('../../../../helpers/dates');
41 return { ...actual, toShortNotSoISOString: (date: string) => `ISO.${date}` };
47 date: new Date('2017-03-02T10:36:01Z'),
52 date: new Date('2017-03-02T09:36:01Z'),
53 events: [mockAnalysisEvent()],
58 date: new Date('2017-03-02T08:36:01Z'),
61 mockAnalysisEvent({ category: 'VERSION', qualityGate: undefined })
65 mockParsedAnalysis({ key: '1', projectVersion: '4.1' })
68 it('should render correctly', () => {
69 expect(shallowRender()).toMatchSnapshot('empty');
70 expect(shallowRender({ loading: true })).toMatchSnapshot('loading');
71 expect(shallowRender({ analyses, selectedAnalysisKey: '2' })).toMatchSnapshot('Analyses');
74 function shallowRender(props: Partial<BranchAnalysisListRendererProps> = {}) {
76 <BranchAnalysisListRenderer
78 handleRangeChange={jest.fn()}
79 handleScroll={jest.fn()}
81 onSelectAnalysis={jest.fn()}
83 registerBadgeNode={jest.fn()}
84 registerScrollableNode={jest.fn()}
85 selectedAnalysisKey=""
86 shouldStick={jest.fn()}