aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDavid Cho-Lerat <david.cho-lerat@sonarsource.com>2023-11-21 11:31:11 +0100
committersonartech <sonartech@sonarsource.com>2023-11-24 20:02:45 +0000
commit08b47d3373654a510e2aacd245db5903ddb88510 (patch)
tree93e43a4676975b1e5da894a93b7fc2b20de0a016 /server
parent74ddec687767e7c35ce6a479a04627909891102e (diff)
downloadsonarqube-08b47d3373654a510e2aacd245db5903ddb88510.tar.gz
sonarqube-08b47d3373654a510e2aacd245db5903ddb88510.zip
SONAR-21017 Tests: click actions should use RTL's userEvent
Diffstat (limited to 'server')
-rw-r--r--server/sonar-web/src/main/js/components/controls/__tests__/clipboard-test.tsx9
-rw-r--r--server/sonar-web/src/main/js/components/facet/__tests__/Facet-it.tsx15
2 files changed, 14 insertions, 10 deletions
diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/clipboard-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/clipboard-test.tsx
index 38fafd1a42d..c6670938912 100644
--- a/server/sonar-web/src/main/js/components/controls/__tests__/clipboard-test.tsx
+++ b/server/sonar-web/src/main/js/components/controls/__tests__/clipboard-test.tsx
@@ -18,6 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
import * as React from 'react';
import { renderComponent } from '../../../helpers/testReactTestingUtils';
import {
@@ -43,12 +44,12 @@ describe('ClipboardBase', () => {
expect(screen.getByText('click to copy')).toBeInTheDocument();
});
- it('should allow its content to be copied', () => {
+ it('should allow its content to be copied', async () => {
+ const user = userEvent.setup();
renderClipboardBase();
- const button = screen.getByRole('button');
- button.click();
- expect(screen.getByText('copied')).toBeInTheDocument();
+ user.click(screen.getByRole('button'));
+ expect(await screen.findByText('copied')).toBeInTheDocument();
jest.runAllTimers();
diff --git a/server/sonar-web/src/main/js/components/facet/__tests__/Facet-it.tsx b/server/sonar-web/src/main/js/components/facet/__tests__/Facet-it.tsx
index e41d8894070..9c3c52fb54c 100644
--- a/server/sonar-web/src/main/js/components/facet/__tests__/Facet-it.tsx
+++ b/server/sonar-web/src/main/js/components/facet/__tests__/Facet-it.tsx
@@ -18,6 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
import * as React from 'react';
import { renderComponent } from '../../../helpers/testReactTestingUtils';
import FacetBox, { FacetBoxProps } from '../FacetBox';
@@ -25,7 +26,8 @@ import FacetHeader from '../FacetHeader';
import FacetItem from '../FacetItem';
import FacetItemsList from '../FacetItemsList';
-it('should render and function correctly', () => {
+it('should render and function correctly', async () => {
+ const user = userEvent.setup();
const onFacetClick = jest.fn();
renderFacet(undefined, undefined, { onClick: onFacetClick });
@@ -35,7 +37,7 @@ it('should render and function correctly', () => {
expect(screen.queryByText('Foo/Bar')).not.toBeInTheDocument();
// Expand.
- facetHeader.click();
+ await user.click(facetHeader);
facetHeader = screen.getByRole('button', { name: 'foo', expanded: true });
expect(facetHeader).toBeInTheDocument();
expect(screen.getByText('Foo/Bar')).toBeInTheDocument();
@@ -43,14 +45,14 @@ it('should render and function correctly', () => {
// Interact with facets.
const facet1 = screen.getByRole('checkbox', { name: 'Foo/Bar 10' });
expect(facet1).toHaveClass('active');
- facet1.click();
+ await user.click(facet1);
expect(onFacetClick).toHaveBeenCalledWith('bar', false);
const facet2 = screen.getByRole('checkbox', { name: 'Foo/Baz' });
expect(facet2).not.toHaveClass('active');
// Collapse again.
- facetHeader.click();
+ await user.click(facetHeader);
expect(screen.getByRole('button', { name: 'foo', expanded: false })).toBeInTheDocument();
expect(screen.queryByText('Foo/Bar')).not.toBeInTheDocument();
});
@@ -62,10 +64,11 @@ it('should correctly render a header with helper text', async () => {
);
});
-it('should correctly render a header with value data', () => {
+it('should correctly render a header with value data', async () => {
+ const user = userEvent.setup();
renderFacet(undefined, { values: ['value 1'] });
expect(screen.getByText('value 1')).toBeInTheDocument();
- screen.getByRole('button', { name: 'clear_x_filter.foo' }).click();
+ await user.click(screen.getByRole('button', { name: 'clear_x_filter.foo' }));
expect(screen.queryByText('value 1')).not.toBeInTheDocument();
});