3 * Copyright (C) 2009-2021 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 { getSystemUpgrades } from '../../../../../api/system';
23 import { click, waitAndUpdate } from '../../../../../helpers/testUtils';
24 import SystemUpgradeNotif from '../SystemUpgradeNotif';
26 jest.mock('../../../../../api/system', () => ({
27 getSystemUpgrades: jest.fn(() =>
29 updateCenterRefresh: '',
33 description: 'Version 5.6.7 description',
34 releaseDate: '2017-03-01',
35 changeLogUrl: 'changelogurl',
36 downloadUrl: 'downloadurl',
41 description: 'Version 5.6.5 description',
42 releaseDate: '2017-03-01',
43 changeLogUrl: 'changelogurl',
44 downloadUrl: 'downloadurl',
49 description: 'Version 6.3 description',
50 releaseDate: '2017-05-02',
51 changeLogUrl: 'changelogurl',
52 downloadUrl: 'downloadurl',
57 description: 'Version 5.6.6 description',
58 releaseDate: '2017-04-02',
59 changeLogUrl: 'changelogurl',
60 downloadUrl: 'downloadurl',
65 description: 'Version 6.4 description',
66 releaseDate: '2017-06-02',
67 changeLogUrl: 'changelogurl',
68 downloadUrl: 'downloadurl',
80 it('should render correctly', async () => {
81 const wrapper = shallowRender();
82 await waitAndUpdate(wrapper);
83 expect(getSystemUpgrades).toHaveBeenCalled();
85 expect(wrapper).toMatchSnapshot();
87 click(wrapper.find('Button'));
88 expect(wrapper).toMatchSnapshot();
91 it('should display nothing', async () => {
92 (getSystemUpgrades as jest.Mock).mockImplementationOnce(() => {
93 return Promise.resolve({ updateCenterRefresh: '', upgrades: [] });
95 const wrapper = shallowRender();
96 await waitAndUpdate(wrapper);
98 expect(wrapper.type()).toBeNull();
101 function shallowRender() {
102 return shallow<SystemUpgradeNotif>(<SystemUpgradeNotif />);