3 * Copyright (C) 2009-2019 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 { waitAndUpdate } from 'sonar-ui-common/helpers/testUtils';
23 import { mockAnalysisEvent, mockParsedAnalysis } from '../../../../helpers/testMocks';
24 import ProjectActivityAnalysis from '../ProjectActivityAnalysis';
26 jest.mock('sonar-ui-common/helpers/dates', () => ({
28 valueOf: () => 1546333200000,
29 toISOString: () => '2019-01-01T09:00:00.000Z'
33 it('should render correctly', () => {
34 expect(shallowRender()).toMatchSnapshot();
36 shallowRender({ analysis: mockParsedAnalysis({ events: [mockAnalysisEvent()] }) })
39 shallowRender({ analysis: mockParsedAnalysis({ buildString: '1.0.234' }) })
41 expect(shallowRender({ isBaseline: true })).toMatchSnapshot();
44 it('should show the correct admin options', () => {
45 const wrapper = shallowRender({
47 canCreateVersion: true,
48 canDeleteAnalyses: true
50 const instance = wrapper.instance();
52 expect(wrapper).toMatchSnapshot();
54 instance.setState({ addEventForm: true });
55 waitAndUpdate(wrapper);
56 expect(wrapper).toMatchSnapshot();
57 instance.setState({ addEventForm: false });
59 instance.setState({ removeAnalysisForm: true });
60 waitAndUpdate(wrapper);
61 expect(wrapper).toMatchSnapshot();
62 instance.setState({ removeAnalysisForm: false });
64 instance.setState({ addVersionForm: true });
65 waitAndUpdate(wrapper);
66 expect(wrapper).toMatchSnapshot();
67 instance.setState({ addVersionForm: false });
70 it('should not allow the first item to be deleted', () => {
74 canCreateVersion: true,
75 canDeleteAnalyses: true,
81 function shallowRender(props: Partial<ProjectActivityAnalysis['props']> = {}) {
83 <ProjectActivityAnalysis
84 addCustomEvent={jest.fn()}
85 addVersion={jest.fn()}
86 analysis={mockParsedAnalysis()}
87 canCreateVersion={false}
88 changeEvent={jest.fn()}
89 deleteAnalysis={jest.fn()}
90 deleteEvent={jest.fn()}
94 updateSelectedDate={jest.fn()}