From 5d533287777a3e2841a32b7b9a3e76aeb2bd5100 Mon Sep 17 00:00:00 2001 From: Viktor Vorona Date: Tue, 20 Feb 2024 16:30:04 +0100 Subject: [PATCH] SONAR-21692 Remove test warnings from QualityGate, CaycGuide, GitHub --- .../js/api/mocks/QualityGatesServiceMock.ts | 2 +- .../create/project/__tests__/GitHub-it.tsx | 15 +++--- .../CaYCConditionsSimplificationGuide.tsx | 1 - .../components/__tests__/QualityGate-it.tsx | 48 ++++++------------- 4 files changed, 25 insertions(+), 41 deletions(-) diff --git a/server/sonar-web/src/main/js/api/mocks/QualityGatesServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/QualityGatesServiceMock.ts index 6c4791aa396..bcc72982f3e 100644 --- a/server/sonar-web/src/main/js/api/mocks/QualityGatesServiceMock.ts +++ b/server/sonar-web/src/main/js/api/mocks/QualityGatesServiceMock.ts @@ -140,7 +140,7 @@ export class QualityGatesServiceMock { isCaycCondition: true, }, { id: 'AXJMbIUHPAOIsUIE3eNs', metric: 'new_security_rating', op: 'GT', error: '1' }, - { id: 'AXJMbIUHPAOIsUIE3eNs', metric: 'new_security_rating', op: 'GT', error: '0' }, + { id: 'AXJMbIUHPAOIsUIE3eNy', metric: 'new_security_rating', op: 'GT', error: '0' }, { id: 'deprecated', metric: 'function_complexity', op: 'LT', error: '1' }, ], isDefault: false, diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/GitHub-it.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/GitHub-it.tsx index b14cc0f66bb..a742d14d7ab 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/GitHub-it.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/GitHub-it.tsx @@ -67,6 +67,7 @@ const ui = { name: 'onboarding.create_project.new_code_definition.create_x_projects2', }), globalSettingRadio: byRole('radio', { name: 'new_code_definition.global_setting' }), + createErrorMessage: byText('onboarding.create_project.github.warning.message'), }; beforeAll(() => { @@ -109,7 +110,9 @@ it('should not redirect to github when url is malformated', async () => { expect(screen.getByText('alm.configuration.selector.placeholder')).toBeInTheDocument(); expect(ui.instanceSelector.get()).toBeInTheDocument(); - await selectEvent.select(ui.instanceSelector.get(), [/conf-github-3/]); + await waitFor(() => selectEvent.select(ui.instanceSelector.get(), [/conf-github-3/])); + + expect(await ui.createErrorMessage.find()).toBeInTheDocument(); expect(window.location.replace).not.toHaveBeenCalled(); }); @@ -121,7 +124,7 @@ it('should show import project feature when the authentication is successfull', expect(await ui.instanceSelector.find()).toBeInTheDocument(); - await selectEvent.select(ui.organizationSelector.get(), [/org-1/]); + await waitFor(() => selectEvent.select(ui.organizationSelector.get(), [/org-1/])); expect(await ui.project1.find()).toBeInTheDocument(); expect(ui.project2.get()).toBeInTheDocument(); @@ -173,7 +176,7 @@ it('should import several projects', async () => { expect(await ui.instanceSelector.find()).toBeInTheDocument(); - await selectEvent.select(ui.organizationSelector.get(), [/org-1/]); + await waitFor(() => selectEvent.select(ui.organizationSelector.get(), [/org-1/])); expect(await ui.project1.find()).toBeInTheDocument(); expect(ui.project1Checkbox.get()).not.toBeChecked(); @@ -238,7 +241,7 @@ it('should show search filter when the authentication is successful', async () = expect(await ui.instanceSelector.find()).toBeInTheDocument(); - await selectEvent.select(ui.organizationSelector.get(), [/org-1/]); + await waitFor(() => selectEvent.select(ui.organizationSelector.get(), [/org-1/])); const inputSearch = screen.getByRole('searchbox'); await user.click(inputSearch); @@ -261,7 +264,7 @@ it('should have load more', async () => { expect(await ui.instanceSelector.find()).toBeInTheDocument(); - await selectEvent.select(ui.organizationSelector.get(), [/org-1/]); + await waitFor(() => selectEvent.select(ui.organizationSelector.get(), [/org-1/])); const loadMore = await screen.findByRole('button', { name: 'show_more' }); expect(loadMore).toBeInTheDocument(); @@ -289,7 +292,7 @@ it('should show no result message when there are no projects', async () => { expect(await ui.instanceSelector.find()).toBeInTheDocument(); - await selectEvent.select(ui.organizationSelector.get(), [/org-1/]); + await waitFor(() => selectEvent.select(ui.organizationSelector.get(), [/org-1/])); expect(screen.getByText('no_results')).toBeInTheDocument(); }); diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/CaYCConditionsSimplificationGuide.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/CaYCConditionsSimplificationGuide.tsx index 80ce44fce6a..0ea24e58a14 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/CaYCConditionsSimplificationGuide.tsx +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/CaYCConditionsSimplificationGuide.tsx @@ -88,7 +88,6 @@ export default function CaYCConditionsSimplificationGuide({ qualityGate }: Props return ( { const builtInQualityGate = await screen.findByText('Sonar way'); - await act(async () => { - await user.click(builtInQualityGate); - }); + await user.click(builtInQualityGate); expect(await screen.findByText(/quality_gates.is_built_in.cayc.description/)).toBeInTheDocument(); expect(await screen.findByText(/quality_gates.is_built_in.description/)).toBeInTheDocument(); @@ -95,11 +93,9 @@ it('should be able to create a quality gate then delete it', async () => { // Using keyboard await user.click(createButton); - await act(async () => { - await user.click(screen.getByRole('textbox', { name: /name.*/ })); - await user.keyboard('testone'); - await user.click(screen.getByRole('button', { name: 'quality_gate.create' })); - }); + await user.click(screen.getByRole('textbox', { name: /name.*/ })); + await user.keyboard('testone'); + await user.click(screen.getByRole('button', { name: 'quality_gate.create' })); expect(await screen.findByRole('button', { name: 'testone' })).toBeInTheDocument(); // Using modal button @@ -109,11 +105,9 @@ it('should be able to create a quality gate then delete it', async () => { expect(saveButton).toBeDisabled(); const nameInput = screen.getByRole('textbox', { name: /name.*/ }); - await act(async () => { - await user.click(nameInput); - await user.keyboard('testtwo'); - await user.click(saveButton); - }); + await user.click(nameInput); + await user.keyboard('testtwo'); + await user.click(saveButton); const newQG = await screen.findByRole('button', { name: 'testtwo' }); @@ -147,10 +141,8 @@ it('should be able to copy a quality gate which is CaYC compliant', async () => await user.click(copyButton); const nameInput = screen.getByRole('textbox', { name: /name.*/ }); expect(nameInput).toBeInTheDocument(); - await act(async () => { - await user.click(nameInput); - await user.keyboard(' bis{Enter}'); - }); + await user.click(nameInput); + await user.keyboard(' bis{Enter}'); expect(await screen.findByRole('button', { name: /.* bis/ })).toBeInTheDocument(); }); @@ -498,9 +490,7 @@ it('should display CaYC condition simplification tour for users who didnt dismis const qualityGate = await screen.findByText('Sonar way'); - await act(async () => { - await user.click(qualityGate); - }); + await user.click(qualityGate); expect(await byRole('alertdialog').find()).toBeInTheDocument(); @@ -510,9 +500,7 @@ it('should display CaYC condition simplification tour for users who didnt dismis .get(), ).toBeInTheDocument(); - await act(async () => { - await user.click(byRole('alertdialog').byRole('button', { name: 'next' }).get()); - }); + await user.click(byRole('alertdialog').byRole('button', { name: 'next' }).get()); expect( byRole('alertdialog') @@ -520,9 +508,7 @@ it('should display CaYC condition simplification tour for users who didnt dismis .get(), ).toBeInTheDocument(); - await act(async () => { - await user.click(byRole('alertdialog').byRole('button', { name: 'next' }).get()); - }); + await user.click(byRole('alertdialog').byRole('button', { name: 'next' }).get()); expect( byRole('alertdialog') @@ -530,9 +516,7 @@ it('should display CaYC condition simplification tour for users who didnt dismis .get(), ).toBeInTheDocument(); - await act(async () => { - await user.click(byRole('alertdialog').byRole('button', { name: 'dismiss' }).get()); - }); + await user.click(byRole('alertdialog').byRole('button', { name: 'dismiss' }).get()); expect(byRole('alertdialog').query()).not.toBeInTheDocument(); expect(dismissNotice).toHaveBeenLastCalledWith(NoticeType.QG_CAYC_CONDITIONS_SIMPLIFICATION); @@ -549,9 +533,7 @@ it('should not display CaYC condition simplification tour for users who dismisse const qualityGate = await screen.findByText('Sonar way'); - await act(async () => { - await user.click(qualityGate); - }); + await user.click(qualityGate); expect(byRole('alertdialog').query()).not.toBeInTheDocument(); }); -- 2.39.5