]> source.dussan.org Git - sonarqube.git/blob
95eff79d2a15889fe953623e869a80bdb0b984aa
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2023 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
20 import { screen } from '@testing-library/react';
21 import userEvent from '@testing-library/user-event';
22 import * as React from 'react';
23 import BranchesServiceMock from '../../../../../../../api/mocks/BranchesServiceMock';
24 import { renderComponent } from '../../../../../../../helpers/testReactTestingUtils';
25 import RegulatoryReport from '../RegulatoryReport';
26
27 jest.mock('../../../../../../../api/branches');
28
29 let handler: BranchesServiceMock;
30
31 beforeAll(() => {
32   handler = new BranchesServiceMock();
33 });
34
35 afterEach(() => handler.resetBranches());
36
37 it('should open the regulatory report page', async () => {
38   const user = userEvent.setup();
39   renderRegulatoryReportApp();
40   expect(await screen.findByText('regulatory_report.page')).toBeInTheDocument();
41   expect(screen.getByText('regulatory_report.description1')).toBeInTheDocument();
42   expect(screen.getByText('regulatory_report.description2')).toBeInTheDocument();
43   expect(
44     screen.getByText('regulatory_page.available_branches_info.only_keep_when_inactive')
45   ).toBeInTheDocument();
46   expect(screen.getByText('regulatory_page.available_branches_info.more_info')).toBeInTheDocument();
47
48   const branchSelect = screen.getByRole('combobox', { name: 'regulatory_page.select_branch' });
49   expect(branchSelect).toBeInTheDocument();
50
51   await user.click(branchSelect);
52   await user.keyboard('[ArrowDown][Enter]');
53
54   const downloadButton = screen.getByText('download_verb');
55   expect(downloadButton).toBeInTheDocument();
56
57   expect(screen.queryByText('regulatory_page.download_start.sentence')).not.toBeInTheDocument();
58   await user.click(downloadButton);
59   expect(screen.getByText('regulatory_page.download_start.sentence')).toBeInTheDocument();
60 });
61
62 function renderRegulatoryReportApp() {
63   renderComponent(<RegulatoryReport component={{ key: '', name: '' }} onClose={() => {}} />);
64 }