]> source.dussan.org Git - sonarqube.git/blob
7607277012039b6e17ebe9cf984e24ad877dfaf9
[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
44   const branchSelect = screen.getByRole('combobox', { name: 'regulatory_page.select_branch' });
45   expect(branchSelect).toBeInTheDocument();
46
47   await user.click(branchSelect);
48   await user.keyboard('[ArrowDown][Enter]');
49
50   const downloadButton = screen.getByText('download_verb');
51   expect(downloadButton).toBeInTheDocument();
52
53   expect(screen.queryByText('regulatory_page.download_start.sentence')).not.toBeInTheDocument();
54   await user.click(downloadButton);
55   expect(screen.getByText('regulatory_page.download_start.sentence')).toBeInTheDocument();
56 });
57
58 function renderRegulatoryReportApp() {
59   renderComponent(<RegulatoryReport component={{ key: '', name: '' }} onClose={() => {}} />);
60 }