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 { parseDate } from 'sonar-ui-common/helpers/dates';
23 import { DEFAULT_GRAPH } from '../../utils';
24 import ProjectActivityAnalysesList from '../ProjectActivityAnalysesList';
26 jest.mock('date-fns/start_of_day', () => (date: Date) => {
27 const startDay = new Date(date);
28 startDay.setUTCHours(0, 0, 0, 0);
32 jest.mock('sonar-ui-common/helpers/dates', () => {
33 const actual = require.requireActual('sonar-ui-common/helpers/dates');
34 return { ...actual, toShortNotSoISOString: (date: string) => 'ISO.' + date };
37 const DATE = parseDate('2016-10-27T16:33:50+0000');
43 events: [{ key: 'E1', category: 'VERSION', name: '6.5-SNAPSHOT' }]
45 { key: 'A2', date: parseDate('2016-10-27T12:21:15+0000'), events: [] },
48 date: parseDate('2016-10-26T12:17:29+0000'),
50 { key: 'E2', category: 'VERSION', name: '6.4' },
51 { key: 'E3', category: 'OTHER', name: 'foo' }
56 date: parseDate('2016-10-24T16:33:50+0000'),
57 events: [{ key: 'E1', category: 'QUALITY_GATE', name: 'Quality gate changed to red...' }]
61 const DEFAULT_PROPS: ProjectActivityAnalysesList['props'] = {
62 addCustomEvent: jest.fn().mockResolvedValue(undefined),
63 addVersion: jest.fn().mockResolvedValue(undefined),
65 analysesLoading: false,
67 changeEvent: jest.fn().mockResolvedValue(undefined),
68 deleteAnalysis: jest.fn().mockResolvedValue(undefined),
69 deleteEvent: jest.fn().mockResolvedValue(undefined),
71 leakPeriodDate: parseDate('2016-10-27T12:21:15+0000'),
72 project: { qualifier: 'TRK' },
77 project: 'org.sonarsource.sonarqube:sonarqube'
82 it('should render correctly', () => {
83 expect(shallow(<ProjectActivityAnalysesList {...DEFAULT_PROPS} />)).toMatchSnapshot();
86 it('should correctly filter analyses by category', () => {
87 const wrapper = shallow(<ProjectActivityAnalysesList {...DEFAULT_PROPS} />);
88 wrapper.setProps({ query: { ...DEFAULT_PROPS.query, category: 'QUALITY_GATE' } });
89 expect(wrapper).toMatchSnapshot();
92 it('should correctly filter analyses by date range', () => {
93 const wrapper = shallow(<ProjectActivityAnalysesList {...DEFAULT_PROPS} />);
96 ...DEFAULT_PROPS.query,
101 expect(wrapper).toMatchSnapshot();