Skip to content

Commit

Permalink
fix(pn-10623): Create notification with sender denomination greater t…
Browse files Browse the repository at this point in the history
…han 80 characters (#1197)
  • Loading branch information
AndreaCimini90 authored Apr 29, 2024
1 parent 4f40971 commit 44dff14
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 67 deletions.
21 changes: 0 additions & 21 deletions packages/pn-pa-webapp/src/__mocks__/Auth.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
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(),
};
21 changes: 20 additions & 1 deletion packages/pn-pa-webapp/src/__mocks__/NotificationDetail.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand All @@ -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 || '',
Expand Down Expand Up @@ -108,6 +109,7 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => {
initialValues: initialValues(),
validateOnMount: true,
validationSchema,
enableReinitialize: true,
/** onSubmit validate */
onSubmit: (values) => {
if (formik.isValid) {
Expand Down Expand Up @@ -138,7 +140,6 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => {
fetchGroups();
}, [fetchGroups]);

const isLessThan80Chars = (field: string): boolean => (field ? field.length < 80 : false);
return (
<ApiErrorWrapper
apiId={NEW_NOTIFICATION_ACTIONS.GET_USER_GROUPS}
Expand Down Expand Up @@ -179,16 +180,9 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => {
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"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
<PreliminaryInformations notification={newNotificationEmpty} onConfirm={confirmHandlerMk} />
<PreliminaryInformations
notification={newNotificationEmpty}
onConfirm={confirmHandlerMk}
/>,
{
preloadedState: {
userState: {
user: {
organization: {
name: 'Comune di Palermo',
},
},
},
},
}
);
});
expect(result.container).toHaveTextContent(/title/i);
Expand Down Expand Up @@ -150,6 +164,7 @@ describe('PreliminaryInformations component with payment enabled', async () => {
userState: {
user: {
organization: {
name: 'Comune di Palermo',
hasGroup: true,
},
},
Expand All @@ -174,9 +189,7 @@ describe('PreliminaryInformations component with payment enabled', async () => {
preloadedState: {
userState: {
user: {
organization: {
hasGroup: true,
},
organization: { name: 'Comune di Palermo', hasGroup: true },
},
},
},
Expand Down Expand Up @@ -221,9 +234,7 @@ describe('PreliminaryInformations component with payment enabled', async () => {
preloadedState: {
userState: {
user: {
organization: {
hasGroup: true,
},
organization: { name: 'Comune di Palermo', hasGroup: true },
},
},
},
Expand Down Expand Up @@ -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 },
},
},
},
Expand Down Expand Up @@ -337,9 +345,7 @@ describe('PreliminaryInformations component with payment enabled', async () => {
preloadedState: {
userState: {
user: {
organization: {
hasGroup: true,
},
organization: { name: 'Comune di Palermo', hasGroup: true },
},
},
},
Expand Down Expand Up @@ -387,9 +393,7 @@ describe('PreliminaryInformations Component with payment disabled', async () =>
preloadedState: {
userState: {
user: {
organization: {
hasGroup: true,
},
organization: { name: 'Comune di Palermo', hasGroup: true },
},
},
},
Expand All @@ -416,9 +420,7 @@ describe('PreliminaryInformations Component with payment disabled', async () =>
preloadedState: {
userState: {
user: {
organization: {
hasGroup: true,
},
organization: { name: 'Comune di Palermo', hasGroup: true },
},
},
},
Expand Down Expand Up @@ -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(
<PreliminaryInformations notification={newNotificationEmpty} onConfirm={confirmHandlerMk} />
<PreliminaryInformations
notification={{
...newNotificationEmpty,
senderDenomination:
'Comune di Palermo - Commissario Straordinario del Governo ZES Sicilia Occidentale',
}}
onConfirm={confirmHandlerMk}
/>,
{
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(<NotificationDetail />);
});
Expand All @@ -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(<NotificationDetail />);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/pn-pa-webapp/src/redux/auth/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const organizationMatcher: yup.SchemaOf<Organization> = yup.object({
description: yup.string().notRequired(),
})
.notRequired(),
ipaCode: yup.string().notRequired()
ipaCode: yup.string().notRequired(),
});

const userDataMatcher = yup
Expand Down

0 comments on commit 44dff14

Please sign in to comment.