Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/pn-4727
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaCimini90 committed Apr 24, 2024
2 parents 6ca28cc + 4f40971 commit e24f231
Show file tree
Hide file tree
Showing 17 changed files with 120 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/pn-commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@mui/material": "^5.14.5",
"@mui/system": "^5.14.5",
"@mui/x-date-pickers": "^6.10.1",
"@pagopa/mui-italia": "^1.3.0",
"@pagopa/mui-italia": "^1.4.1",
"@reduxjs/toolkit": "^1.9.5",
"@types/node": "^17.0.8",
"@types/react": "^18.2.24",
Expand Down
2 changes: 1 addition & 1 deletion packages/pn-pa-webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@mui/material": "^5.14.5",
"@mui/system": "^5.14.5",
"@mui/x-date-pickers": "^6.10.1",
"@pagopa/mui-italia": "^1.3.0",
"@pagopa/mui-italia": "^1.4.1",
"@reduxjs/toolkit": "^1.9.5",
"@types/lodash": "^4.14.172",
"@types/node": "^17.0.8",
Expand Down
1 change: 1 addition & 0 deletions packages/pn-pa-webapp/public/locales/it/notifiche.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@
"title": "Informazioni preliminari",
"protocol-number": "Numero di protocollo",
"subject": "Oggetto della notifica",
"sender-denomination": "Ente mittente",
"abstract": "Descrizione",
"group": "Gruppo",
"no-groups": "Non ci sono gruppi per questo prodotto",
Expand Down
21 changes: 21 additions & 0 deletions packages/pn-pa-webapp/src/__mocks__/Auth.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,24 @@ 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(),
};
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export const newNotificationEmpty: NewNotification = {
group: '',
taxonomyCode: '',
notificationFeePolicy: '' as NotificationFeePolicy,
senderDenomination: userResponse.organization.name,
};

export const newNotificationDTO: NewNotificationDTO = newNotificationMapper(newNotification);
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => {
(state: RootState) => state.userState.user.organization.hasGroups
);

const senderDenomination = useAppSelector((state: RootState) =>
state.userState.user.organization.rootParent?.description
? state.userState.user.organization.rootParent?.description +
' - ' +
state.userState.user.organization.name
: state.userState.user.organization.name
);

const { t } = useTranslation(['notifiche'], {
keyPrefix: 'new-notification.steps.preliminary-informations',
});
Expand All @@ -64,6 +72,7 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => {
() => ({
paProtocolNumber: notification.paProtocolNumber || '',
subject: notification.subject || '',
senderDenomination,
abstract: notification.abstract ?? '',
group: notification.group ?? '',
taxonomyCode: notification.taxonomyCode || '',
Expand All @@ -76,6 +85,10 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => {
const validationSchema = yup.object({
paProtocolNumber: requiredStringFieldValidation(tc, 256),
subject: requiredStringFieldValidation(tc, 134, 10),
senderDenomination: yup
.string()
.required(`${t('sender-denomination')} ${tc('required')}`)
.max(80, tc('too-long-field-error', { maxLength: 80 })),
abstract: yup
.string()
.max(1024, tc('too-long-field-error', { maxLength: 1024 }))
Expand Down Expand Up @@ -125,6 +138,7 @@ 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 @@ -158,6 +172,26 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => {
size="small"
margin="normal"
/>
<TextField
id="senderDenomination"
label={`${t('sender-denomination')}*`}
fullWidth
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)
}
size="small"
margin="normal"
/>
<TextField
id="abstract"
label={t('abstract')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
testSelect,
} from '@pagopa-pn/pn-commons/src/test-utils';

import { longOrganizationNameUserResponse, userResponse } from '../../../__mocks__/Auth.mock';
import {
newNotification,
newNotificationEmpty,
Expand Down Expand Up @@ -54,10 +55,15 @@ vi.mock('../../../services/configuration.service', async () => {
};
});

const populateForm = async (form: HTMLFormElement, hasPayment: boolean) => {
const populateForm = async (
form: HTMLFormElement,
hasPayment: boolean,
organizationName: string = userResponse.organization.name
) => {
await testInput(form, 'paProtocolNumber', newNotification.paProtocolNumber);
await testInput(form, 'subject', newNotification.subject);
await testInput(form, 'taxonomyCode', newNotification.taxonomyCode);
await testInput(form, 'senderDenomination', organizationName);
await testSelect(
form,
'group',
Expand Down Expand Up @@ -118,6 +124,7 @@ describe('PreliminaryInformations component with payment enabled', async () => {
testFormElements(form, 'abstract', 'abstract');
testFormElements(form, 'group', 'group');
testFormElements(form, 'taxonomyCode', 'taxonomy-id*');
testFormElements(form, 'senderDenomination', 'sender-denomination*');
testRadio(form, 'comunicationTypeRadio', ['registered-letter-890', 'simple-registered-letter']);
testRadio(form, 'paymentMethodRadio', [
'pagopa-notice',
Expand Down Expand Up @@ -195,6 +202,7 @@ describe('PreliminaryInformations component with payment enabled', async () => {
recipients: [],
physicalCommunicationType: PhysicalCommunicationType.AR_REGISTERED_LETTER,
paymentMode: PaymentModel.PAGO_PA_NOTICE_F24_FLATRATE,
senderDenomination: newNotification.senderDenomination,
});
});
expect(confirmHandlerMk).toBeCalledTimes(1);
Expand Down Expand Up @@ -226,12 +234,12 @@ describe('PreliminaryInformations component with payment enabled', async () => {
// set invalid values
// paProtocolNumber
await testInput(form, 'paProtocolNumber', '');
const potrocolNumberError = form.querySelector('#paProtocolNumber-helper-text');
expect(potrocolNumberError).toHaveTextContent('required-field');
const protocolNumberError = form.querySelector('#paProtocolNumber-helper-text');
expect(protocolNumberError).toHaveTextContent('required-field');
await testInput(form, 'paProtocolNumber', ' text-with-spaces ');
expect(potrocolNumberError).toHaveTextContent('no-spaces-at-edges');
expect(protocolNumberError).toHaveTextContent('no-spaces-at-edges');
await testInput(form, 'paProtocolNumber', randomString(257));
expect(potrocolNumberError).toHaveTextContent('too-long-field-error');
expect(protocolNumberError).toHaveTextContent('too-long-field-error');
// subject
await testInput(form, 'subject', '');
const subjectError = form.querySelector('#subject-helper-text');
Expand All @@ -254,6 +262,16 @@ describe('PreliminaryInformations component with payment enabled', async () => {
expect(taxonomyCodeError).toHaveTextContent('taxonomy-id required');
await testInput(form, 'taxonomyCode', randomString(4));
expect(taxonomyCodeError).toHaveTextContent('taxonomy-id invalid');
// senderDenomination
await testInput(form, 'senderDenomination', '');
const senderDenominationError = form.querySelector('#senderDenomination-helper-text');
expect(senderDenominationError).toHaveTextContent('sender-denomination required');
await testInput(
form,
'senderDenomination',
'Comune di Palermo - Commissario Straordinario del Governo ZES Sicilia Occidentale'
);
expect(senderDenominationError).toHaveTextContent('too-long-field-error');
// check submit button state
const button = within(form).getByTestId('step-submit');
expect(button).toBeDisabled();
Expand All @@ -270,6 +288,7 @@ describe('PreliminaryInformations component with payment enabled', async () => {
user: {
organization: {
hasGroup: true,
name: 'Comune di Palermo',
},
},
},
Expand All @@ -288,6 +307,12 @@ describe('PreliminaryInformations component with payment enabled', async () => {
testFormElements(form, 'abstract', 'abstract', newNotification.abstract);
testFormElements(form, 'group', 'group', newNotification.group);
testFormElements(form, 'taxonomyCode', 'taxonomy-id*', newNotification.taxonomyCode);
testFormElements(
form,
'senderDenomination',
'sender-denomination*',
userResponse.organization.name
);
const physicalCommunicationType = form.querySelector(
`input[name="physicalCommunicationType"][value="${newNotification.physicalCommunicationType}"]`
);
Expand Down Expand Up @@ -419,8 +444,25 @@ describe('PreliminaryInformations Component with payment disabled', async () =>
recipients: [],
physicalCommunicationType: PhysicalCommunicationType.AR_REGISTERED_LETTER,
paymentMode: PaymentModel.NOTHING,
senderDenomination: newNotification.senderDenomination,
});
});
expect(confirmHandlerMk).toBeCalledTimes(1);
});

it('set senderDenomination longer than 80 characters', async () => {
mock.onGet(GET_USER_GROUPS(GroupStatus.ACTIVE)).reply(200, newNotificationGroups);
await act(async () => {
result = render(
<PreliminaryInformations notification={newNotificationEmpty} onConfirm={confirmHandlerMk} />
);
});
const form = result.getByTestId('preliminaryInformationsForm') as HTMLFormElement;
await testInput(form, 'senderDenomination', longOrganizationNameUserResponse.organization.name);
const senderDenominationError = form.querySelector('#senderDenomination-helper-text');
expect(senderDenominationError).toHaveTextContent('too-long-field-error');
const button = within(form).getByTestId('step-submit');
// check submit button state
expect(button).toBeDisabled();
});
});
2 changes: 1 addition & 1 deletion packages/pn-pa-webapp/src/models/NewNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface BaseNewNotification {
abstract?: string;
cancelledIun?: string;
physicalCommunicationType: PhysicalCommunicationType;
senderDenomination?: string;
senderDenomination: string;
senderTaxId?: string;
group?: string;
taxonomyCode: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/pn-pa-webapp/src/pages/NewNotification.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ const NewNotification = () => {
useEffect(() => {
dispatch(
setSenderInfos({
senderDenomination: organization.parentDescription
? organization.parentDescription + ' - ' + organization.name
senderDenomination: organization.rootParent?.description
? organization.rootParent?.description + ' - ' + organization.name
: organization.name,
senderTaxId: organization.fiscal_code,
})
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 @@ -33,7 +33,6 @@ const organizationMatcher: yup.SchemaOf<Organization> = yup.object({
groups: yup.array().of(yup.string()).notRequired(),
name: yup.string().required(),
hasGroups: yup.boolean(),
parentDescription: yup.string().notRequired(),
aooParent: yup.string().notRequired(),
subUnitCode: yup.string().notRequired(),
subUnitType: yup.string().notRequired(),
Expand All @@ -43,6 +42,7 @@ const organizationMatcher: yup.SchemaOf<Organization> = yup.object({
description: yup.string().notRequired(),
})
.notRequired(),
ipaCode: yup.string().notRequired()
});

const userDataMatcher = yup
Expand Down
2 changes: 1 addition & 1 deletion packages/pn-pa-webapp/src/redux/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface User extends BasicUser {
}

export interface Organization {
parentDescription?: string;
id: string;
roles: Array<Role>;
fiscal_code: string; // organization fiscal code
Expand All @@ -18,6 +17,7 @@ export interface Organization {
subUnitCode?: string;
subUnitType?: string;
aooParent?: string;
ipaCode?: string;
rootParent?: {
id?: string;
description?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const initialState = {
group: '',
taxonomyCode: '',
notificationFeePolicy: '',
senderDenomination: '',
},
groups: [],
isCompleted: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const initialState = {
taxonomyCode: '',
paymentMode: '' as PaymentModel,
notificationFeePolicy: '' as NotificationFeePolicy,
senderDenomination: '',
} as NewNotification,
groups: [] as Array<UserGroup>,
isCompleted: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/pn-personafisica-login/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@mui/icons-material": "^5.14.3",
"@mui/material": "^5.14.5",
"@mui/system": "^5.14.5",
"@pagopa/mui-italia": "^1.3.0",
"@pagopa/mui-italia": "^1.4.1",
"@types/node": "^17.0.8",
"@types/react": "^18.2.24",
"@types/react-dom": "^18.2.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/pn-personafisica-webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@mui/material": "^5.14.5",
"@mui/system": "^5.14.5",
"@mui/x-date-pickers": "^6.10.1",
"@pagopa/mui-italia": "^1.3.0",
"@pagopa/mui-italia": "^1.4.1",
"@reduxjs/toolkit": "^1.9.5",
"@types/lodash": "^4.14.172",
"@types/node": "^17.0.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/pn-personagiuridica-webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@mui/material": "^5.14.5",
"@mui/system": "^5.14.5",
"@mui/x-date-pickers": "^6.10.1",
"@pagopa/mui-italia": "^1.3.0",
"@pagopa/mui-italia": "^1.4.1",
"@reduxjs/toolkit": "^1.9.5",
"@types/lodash": "^4.14.172",
"@types/node": "^17.0.8",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2650,10 +2650,10 @@
rxjs "7.8.1"
tslib "2.6.2"

"@pagopa/mui-italia@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@pagopa/mui-italia/-/mui-italia-1.3.0.tgz#d34541b0e25fc9de3ec62e28a9dec5b6944fb2d7"
integrity sha512-9pFW3d+FeLzVTHOwa9bpe0oU1VtTN4SFsAAKwL4kGNzhTsqMLq9LcpkP2Qs1aiXorjUheW0kpBgGbEL4SAdV9g==
@pagopa/mui-italia@^1.4.1":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@pagopa/mui-italia/-/mui-italia-1.4.1.tgz#3c7406bd6407532e4b44cbac4e30eb8763118895"
integrity sha512-lRqg8qgaacihuCBecW2+P5mmTPtq5snvNfnRu2xIwgyrD1JSpmrIR2XQJkyYSHWyaB9IxQuI4IoDRQpBVos/7Q==
dependencies:
"@fontsource/dm-mono" "^4.5.10"
"@fontsource/titillium-web" "^4.5.9"
Expand Down

0 comments on commit e24f231

Please sign in to comment.