From 44dff14e44be442a42cdee3b0249d662b8a40724 Mon Sep 17 00:00:00 2001 From: AndreaCimini90 <99173401+AndreaCimini90@users.noreply.github.com> Date: Mon, 29 Apr 2024 15:59:29 +0200 Subject: [PATCH] fix(pn-10623): Create notification with sender denomination greater than 80 characters (#1197) --- .../pn-pa-webapp/src/__mocks__/Auth.mock.ts | 21 ------ .../src/__mocks__/NotificationDetail.mock.ts | 21 +++++- .../PreliminaryInformations.tsx | 18 ++--- .../__test__/PreliminaryInformations.test.tsx | 69 ++++++++++++------- .../__test__/NotificationDetail.page.test.tsx | 13 ++-- .../pn-pa-webapp/src/redux/auth/reducers.ts | 2 +- 6 files changed, 77 insertions(+), 67 deletions(-) diff --git a/packages/pn-pa-webapp/src/__mocks__/Auth.mock.ts b/packages/pn-pa-webapp/src/__mocks__/Auth.mock.ts index 9381f01fea..9cf6f3973c 100644 --- a/packages/pn-pa-webapp/src/__mocks__/Auth.mock.ts +++ b/packages/pn-pa-webapp/src/__mocks__/Auth.mock.ts @@ -68,24 +68,3 @@ export const userResponse: User = { }, desired_exp: calcExpirationDate(), }; -export const longOrganizationNameUserResponse: User = { - sessionToken: 'mocked-session-token', - name: 'giuseppe', - family_name: 'rossini', - fiscal_number: 'RSSGPP80B02G273H', - email: 'giuseppe.rossini@gmail.com', - uid: '00000000-0000-0000-0000-000000000000', - organization: { - id: '5b994d4a-0fa8-47ac-9c7b-354f1d44a1ce', - name: 'Comune di Palermo - Commissario Straordinario del Governo ZES Sicilia Occidentale', - roles: [ - { - partyRole: PartyRole.MANAGER, - role: PNRole.ADMIN, - }, - ], - fiscal_code: '80016350821', - hasGroups: false, - }, - desired_exp: calcExpirationDate(), -}; diff --git a/packages/pn-pa-webapp/src/__mocks__/NotificationDetail.mock.ts b/packages/pn-pa-webapp/src/__mocks__/NotificationDetail.mock.ts index 483f68b333..e9bebefb5c 100644 --- a/packages/pn-pa-webapp/src/__mocks__/NotificationDetail.mock.ts +++ b/packages/pn-pa-webapp/src/__mocks__/NotificationDetail.mock.ts @@ -663,7 +663,26 @@ export const raddNotificationDTO: NotificationDetail = { legalFactsIds: [], category: TimelineCategory.NOTIFICATION_RADD_RETRIEVED, details: { - recIndex: 1, + recIndex: 0, + eventTimestamp: '2022-06-21T11:44:28Z', + raddType: 'ALT', + raddTransactionId: '6', + }, + }, + ], +}; + +export const raddNotificationMultiRecipientDTO: NotificationDetail = { + ...notificationDTOMultiRecipient, + timeline: [ + ...notificationDTOMultiRecipient.timeline, + { + elementId: 'NOTIFICATION_RADD_RETRIEVED_mock', + timestamp: '2022-06-21T11:44:28Z', + legalFactsIds: [], + category: TimelineCategory.NOTIFICATION_RADD_RETRIEVED, + details: { + recIndex: 0, eventTimestamp: '2022-06-21T11:44:28Z', raddType: 'ALT', raddTransactionId: '6', diff --git a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx index 275cbd666f..6fa04c4963 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx @@ -54,6 +54,7 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { (state: RootState) => state.userState.user.organization.hasGroups ); + // this is the initial value of the sender denomination. it used to show the error const senderDenomination = useAppSelector((state: RootState) => state.userState.user.organization.rootParent?.description ? state.userState.user.organization.rootParent?.description + @@ -72,7 +73,7 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { () => ({ paProtocolNumber: notification.paProtocolNumber || '', subject: notification.subject || '', - senderDenomination, + senderDenomination: notification.senderDenomination ?? '', abstract: notification.abstract ?? '', group: notification.group ?? '', taxonomyCode: notification.taxonomyCode || '', @@ -108,6 +109,7 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { initialValues: initialValues(), validateOnMount: true, validationSchema, + enableReinitialize: true, /** onSubmit validate */ onSubmit: (values) => { if (formik.isValid) { @@ -138,7 +140,6 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { fetchGroups(); }, [fetchGroups]); - const isLessThan80Chars = (field: string): boolean => (field ? field.length < 80 : false); return ( { name="senderDenomination" value={formik.values.senderDenomination} onChange={handleChangeTouched} - error={ - !isLessThan80Chars(formik.values.senderDenomination) && - Boolean(formik.errors.senderDenomination) - } - disabled={isLessThan80Chars(senderDenomination)} - helperText={ - (!isLessThan80Chars(formik.values.senderDenomination) && - formik.errors.senderDenomination) || - (formik.touched.senderDenomination && formik.errors.senderDenomination) - } + error={Boolean(formik.errors.senderDenomination)} + disabled={senderDenomination.length < 80} + helperText={formik.errors.senderDenomination} size="small" margin="normal" /> diff --git a/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx b/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx index 7620ed4356..cb6e7cbc88 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx @@ -14,7 +14,7 @@ import { testSelect, } from '@pagopa-pn/pn-commons/src/test-utils'; -import { longOrganizationNameUserResponse, userResponse } from '../../../__mocks__/Auth.mock'; +import { userResponse } from '../../../__mocks__/Auth.mock'; import { newNotification, newNotificationEmpty, @@ -115,7 +115,21 @@ describe('PreliminaryInformations component with payment enabled', async () => { mock.onGet(GET_USER_GROUPS(GroupStatus.ACTIVE)).reply(200, newNotificationGroups); await act(async () => { result = render( - + , + { + preloadedState: { + userState: { + user: { + organization: { + name: 'Comune di Palermo', + }, + }, + }, + }, + } ); }); expect(result.container).toHaveTextContent(/title/i); @@ -150,6 +164,7 @@ describe('PreliminaryInformations component with payment enabled', async () => { userState: { user: { organization: { + name: 'Comune di Palermo', hasGroup: true, }, }, @@ -174,9 +189,7 @@ describe('PreliminaryInformations component with payment enabled', async () => { preloadedState: { userState: { user: { - organization: { - hasGroup: true, - }, + organization: { name: 'Comune di Palermo', hasGroup: true }, }, }, }, @@ -221,9 +234,7 @@ describe('PreliminaryInformations component with payment enabled', async () => { preloadedState: { userState: { user: { - organization: { - hasGroup: true, - }, + organization: { name: 'Comune di Palermo', hasGroup: true }, }, }, }, @@ -287,10 +298,7 @@ describe('PreliminaryInformations component with payment enabled', async () => { preloadedState: { userState: { user: { - organization: { - hasGroup: true, - name: 'Comune di Palermo', - }, + organization: { name: 'Comune di Palermo', hasGroup: true }, }, }, }, @@ -337,9 +345,7 @@ describe('PreliminaryInformations component with payment enabled', async () => { preloadedState: { userState: { user: { - organization: { - hasGroup: true, - }, + organization: { name: 'Comune di Palermo', hasGroup: true }, }, }, }, @@ -387,9 +393,7 @@ describe('PreliminaryInformations Component with payment disabled', async () => preloadedState: { userState: { user: { - organization: { - hasGroup: true, - }, + organization: { name: 'Comune di Palermo', hasGroup: true }, }, }, }, @@ -416,9 +420,7 @@ describe('PreliminaryInformations Component with payment disabled', async () => preloadedState: { userState: { user: { - organization: { - hasGroup: true, - }, + organization: { name: 'Comune di Palermo', hasGroup: true }, }, }, }, @@ -455,12 +457,31 @@ describe('PreliminaryInformations Component with payment disabled', async () => mock.onGet(GET_USER_GROUPS(GroupStatus.ACTIVE)).reply(200, newNotificationGroups); await act(async () => { result = render( - + , + { + preloadedState: { + userState: { + user: { + organization: { + name: 'Comune di Palermo - Commissario Straordinario del Governo ZES Sicilia Occidentale', + }, + }, + }, + }, + } ); }); const form = result.getByTestId('preliminaryInformationsForm') as HTMLFormElement; - await testInput(form, 'senderDenomination', longOrganizationNameUserResponse.organization.name); - const senderDenominationError = form.querySelector('#senderDenomination-helper-text'); + const senderDenominationError = await waitFor(() => + form.querySelector('#senderDenomination-helper-text') + ); expect(senderDenominationError).toHaveTextContent('too-long-field-error'); const button = within(form).getByTestId('step-submit'); // check submit button state diff --git a/packages/pn-pa-webapp/src/pages/__test__/NotificationDetail.page.test.tsx b/packages/pn-pa-webapp/src/pages/__test__/NotificationDetail.page.test.tsx index 4b2021fe4b..37a79609d1 100644 --- a/packages/pn-pa-webapp/src/pages/__test__/NotificationDetail.page.test.tsx +++ b/packages/pn-pa-webapp/src/pages/__test__/NotificationDetail.page.test.tsx @@ -25,6 +25,7 @@ import { notificationDTOMultiRecipient, notificationToFe, raddNotificationDTO, + raddNotificationMultiRecipientDTO, } from '../../__mocks__/NotificationDetail.mock'; import { RenderResult, act, fireEvent, render, waitFor, within } from '../../__test__/test-utils'; import { apiClient } from '../../api/apiClients'; @@ -564,9 +565,7 @@ describe('NotificationDetail Page', async () => { }); it('render success alert when documents have been picked up - monorecipient', async () => { - mock - .onGet(NOTIFICATION_DETAIL(raddNotificationDTO.iun)) - .reply(200, { ...raddNotificationDTO, radd: true }); + mock.onGet(NOTIFICATION_DETAIL(raddNotificationDTO.iun)).reply(200, raddNotificationDTO); await act(async () => { result = render(); }); @@ -578,11 +577,9 @@ describe('NotificationDetail Page', async () => { }); it('render success alert when documents have been picked up - multirecipient', async () => { - mock.onGet(NOTIFICATION_DETAIL(raddNotificationDTO.iun)).reply(200, { - ...raddNotificationDTO, - radd: true, - recipients: ['CLMCST42R12D969Z', '20517490320'], - }); + mock + .onGet(NOTIFICATION_DETAIL(raddNotificationMultiRecipientDTO.iun)) + .reply(200, raddNotificationMultiRecipientDTO); await act(async () => { result = render(); }); diff --git a/packages/pn-pa-webapp/src/redux/auth/reducers.ts b/packages/pn-pa-webapp/src/redux/auth/reducers.ts index 26dc1c8438..9e79a2877f 100644 --- a/packages/pn-pa-webapp/src/redux/auth/reducers.ts +++ b/packages/pn-pa-webapp/src/redux/auth/reducers.ts @@ -44,7 +44,7 @@ const organizationMatcher: yup.SchemaOf = yup.object({ description: yup.string().notRequired(), }) .notRequired(), - ipaCode: yup.string().notRequired() + ipaCode: yup.string().notRequired(), }); const userDataMatcher = yup