From 81e54cbf0f288a2d4f9a4e398abf2883e15473e8 Mon Sep 17 00:00:00 2001 From: stanislavh Date: Thu, 22 Feb 2024 11:19:01 +0100 Subject: [PATCH] SONAR-21692 Fix testing warnings for ProjectActivity + NewCodeDefinition --- .../components/forms/AddEventForm.tsx | 3 +- .../components/forms/ChangeEventForm.tsx | 3 +- .../__tests__/NewCodeDefinition-it.tsx | 32 ++++++++++++------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/AddEventForm.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/AddEventForm.tsx index f5f78d2f464..45ce9e2d0d4 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/AddEventForm.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/AddEventForm.tsx @@ -40,7 +40,8 @@ export default class AddEventForm extends React.PureComponent { this.setState({ name: event.target.value }); }; - handleSubmit = () => { + handleSubmit = (e: React.MouseEvent) => { + e.preventDefault(); this.props.addEvent(this.props.analysis.key, this.state.name); this.props.onClose(); }; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/ChangeEventForm.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/ChangeEventForm.tsx index a4c19991c75..7c2041260c4 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/ChangeEventForm.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/ChangeEventForm.tsx @@ -43,7 +43,8 @@ export default class ChangeEventForm extends React.PureComponent { this.setState({ name: event.target.value }); }; - handleSubmit = () => { + handleSubmit = (e: React.MouseEvent) => { + e.preventDefault(); this.props.changeEvent(this.props.event.key, this.state.name); this.props.onClose(); }; diff --git a/server/sonar-web/src/main/js/apps/settings/components/__tests__/NewCodeDefinition-it.tsx b/server/sonar-web/src/main/js/apps/settings/components/__tests__/NewCodeDefinition-it.tsx index 57910c31867..0b390c18361 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/__tests__/NewCodeDefinition-it.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/__tests__/NewCodeDefinition-it.tsx @@ -99,19 +99,9 @@ it('renders and behaves as expected', async () => { expect(ui.saveButton.get()).toBeDisabled(); }); -it('displays information message when NCD is automatically updated', async () => { - newCodeMock.setNewCodePeriod({ - type: NewCodeDefinitionType.NumberOfDays, - value: '90', - previousNonCompliantValue: '120', - updatedAt: 1692279521904, - }); - renderNewCodePeriod(); +it('displays & dismisses information message when NCD is automatically updated', async () => { + const assertError = spyOnLogError(); - expect(await ui.ncdAutoUpdateMessage.find()).toBeVisible(); -}); - -it('dismisses information message when NCD is automatically updated', async () => { newCodeMock.setNewCodePeriod({ type: NewCodeDefinitionType.NumberOfDays, value: '90', @@ -126,6 +116,8 @@ it('dismisses information message when NCD is automatically updated', async () = await user.click(ui.ncdAutoUpdateMessageDismiss.get()); expect(ui.ncdAutoUpdateMessage.query()).not.toBeInTheDocument(); + + assertError(); }); it('does not display information message when NCD is automatically updated if message is already dismissed', () => { @@ -141,6 +133,22 @@ it('does not display information message when NCD is automatically updated if me expect(ui.ncdAutoUpdateMessage.query()).not.toBeInTheDocument(); }); +function spyOnLogError() { + const errorSpy = jest.spyOn(console, 'error').mockImplementationOnce(() => {}); + + return () => { + // There is an issue with the design of NewCodeDefinitionDaysOption that causes a domNesting error + // this is valid and has to be fixed, but this is not the purpose of this test + expect(errorSpy).toHaveBeenCalledTimes(1); + expect(errorSpy.mock.calls[0][0]).toBe( + 'Warning: validateDOMNesting(...): %s cannot appear as a descendant of <%s>.%s', + ); + expect(errorSpy.mock.calls[0][1]).toBe('