-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
23 changed files
with
429 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/pn-personafisica-webapp/src/components/Contacts/ValidatingPecBanner.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { Alert, Typography } from '@mui/material'; | ||
|
||
import { contactsSelectors } from '../../redux/contact/reducers'; | ||
import { useAppSelector } from '../../redux/hooks'; | ||
|
||
const ValidatingPecBanner: React.FC = () => { | ||
const { t } = useTranslation(['recapiti']); | ||
const { | ||
defaultPECAddress, | ||
defaultSERCQ_SENDAddress, | ||
specialPECAddresses, | ||
specialSERCQ_SENDAddresses, | ||
} = useAppSelector(contactsSelectors.selectAddresses); | ||
|
||
const isValidatingDefaultPec = defaultPECAddress?.pecValid === false; | ||
|
||
const isDefaultSercqSendActive = !!defaultSERCQ_SENDAddress; | ||
|
||
const validatingSpecialPecList: Array<string> = specialPECAddresses | ||
.filter( | ||
(pecAddr) => | ||
pecAddr.pecValid === false && | ||
(isDefaultSercqSendActive || | ||
specialSERCQ_SENDAddresses.some((sercqAddr) => sercqAddr.senderId === pecAddr.senderId)) | ||
) | ||
.map((addr) => addr.senderName ?? addr.senderId); | ||
|
||
// eslint-disable-next-line functional/no-let | ||
let bannerMessage = ''; | ||
|
||
if (!isValidatingDefaultPec && validatingSpecialPecList.length === 0) { | ||
return <></>; | ||
} | ||
|
||
if (isValidatingDefaultPec) { | ||
if (isDefaultSercqSendActive) { | ||
bannerMessage = 'dod-enabled-message'; | ||
} else { | ||
bannerMessage = 'dod-disabled-message'; | ||
} | ||
} else { | ||
bannerMessage = 'parties-list'; | ||
} | ||
|
||
return ( | ||
<Alert data-testid="PecVerificationAlert" severity="warning" sx={{ my: { xs: 2, lg: 4 } }}> | ||
<Typography variant="inherit" sx={{ fontWeight: '600' }}> | ||
{t('legal-contacts.pec-validation-banner.title')} | ||
</Typography> | ||
<Typography variant="inherit"> | ||
{t(`legal-contacts.pec-validation-banner.${bannerMessage}`, { | ||
list: validatingSpecialPecList.join(', '), | ||
})} | ||
</Typography> | ||
</Alert> | ||
); | ||
}; | ||
|
||
export default ValidatingPecBanner; |
98 changes: 98 additions & 0 deletions
98
...ges/pn-personafisica-webapp/src/components/Contacts/__test__/ValidatingPecBanner.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { SERCQ_SEND_VALUE } from '@pagopa-pn/pn-commons'; | ||
|
||
import { digitalAddresses } from '../../../__mocks__/Contacts.mock'; | ||
import { render, within } from '../../../__test__/test-utils'; | ||
import { AddressType, ChannelType } from '../../../models/contacts'; | ||
import ValidatingPecBanner from '../ValidatingPecBanner'; | ||
|
||
const sercqAddr = { | ||
addressType: AddressType.LEGAL, | ||
senderId: 'default', | ||
channelType: ChannelType.SERCQ_SEND, | ||
value: SERCQ_SEND_VALUE, | ||
codeValid: true, | ||
}; | ||
|
||
const validatingDefaultPecNoSercq = digitalAddresses.map((addr) => | ||
addr.senderId === 'default' && addr.addressType === AddressType.LEGAL | ||
? { ...addr, pecValid: false } | ||
: addr | ||
); | ||
|
||
const validatingDefaultPecSercq = [...validatingDefaultPecNoSercq, sercqAddr]; | ||
|
||
const validatingPartyPecNoSercq = digitalAddresses.map((addr) => | ||
addr.senderId === 'comune-milano' ? { ...addr, pecValid: false } : addr | ||
); | ||
|
||
const validatingPartyPecSercq = [...validatingPartyPecNoSercq, sercqAddr]; | ||
|
||
const validatingDefaultAndPartyPecSercq = validatingPartyPecSercq.map((addr) => | ||
addr.senderId === 'default' && addr.channelType === ChannelType.PEC | ||
? { ...addr, pecValid: false } | ||
: addr | ||
); | ||
|
||
describe('ValidatingPecBanner component', () => { | ||
it('shows the component while validating default PEC - SERCQ SEND not enabled', () => { | ||
const { getByTestId, getByText } = render(<ValidatingPecBanner />, { | ||
preloadedState: { contactsState: { digitalAddresses: validatingDefaultPecNoSercq } }, | ||
}); | ||
|
||
const alert = getByTestId('PecVerificationAlert'); | ||
const icon = within(alert).getByTestId('ReportProblemOutlinedIcon'); | ||
expect(icon).toBeInTheDocument(); | ||
getByText('legal-contacts.pec-validation-banner.title'); | ||
getByText('legal-contacts.pec-validation-banner.dod-disabled-message'); | ||
}); | ||
|
||
it('shows the component while validating default PEC - SERCQ SEND previously enabled', () => { | ||
const { getByTestId, getByText } = render(<ValidatingPecBanner />, { | ||
preloadedState: { contactsState: { digitalAddresses: validatingDefaultPecSercq } }, | ||
}); | ||
|
||
const alert = getByTestId('PecVerificationAlert'); | ||
const icon = within(alert).getByTestId('ReportProblemOutlinedIcon'); | ||
expect(icon).toBeInTheDocument(); | ||
getByText('legal-contacts.pec-validation-banner.title'); | ||
getByText('legal-contacts.pec-validation-banner.dod-enabled-message'); | ||
}); | ||
|
||
it("shows the component while validating a party's PEC - default SERCQ SEND enabled", () => { | ||
const { getByTestId, getByText } = render(<ValidatingPecBanner />, { | ||
preloadedState: { contactsState: { digitalAddresses: validatingPartyPecSercq } }, | ||
}); | ||
|
||
const alert = getByTestId('PecVerificationAlert'); | ||
const icon = within(alert).getByTestId('ReportProblemOutlinedIcon'); | ||
expect(icon).toBeInTheDocument(); | ||
getByText('legal-contacts.pec-validation-banner.title'); | ||
getByText('legal-contacts.pec-validation-banner.parties-list'); | ||
}); | ||
|
||
it("shows the component while validating default and party's PEC - default SERCQ SEND enabled", () => { | ||
const { getByTestId, getByText } = render(<ValidatingPecBanner />, { | ||
preloadedState: { contactsState: { digitalAddresses: validatingDefaultAndPartyPecSercq } }, | ||
}); | ||
|
||
const alert = getByTestId('PecVerificationAlert'); | ||
const icon = within(alert).getByTestId('ReportProblemOutlinedIcon'); | ||
expect(icon).toBeInTheDocument(); | ||
getByText('legal-contacts.pec-validation-banner.title'); | ||
getByText('legal-contacts.pec-validation-banner.dod-enabled-message'); | ||
}); | ||
|
||
it("doesn't show the component if there is no validating PEC", () => { | ||
const { queryByTestId, queryByText } = render(<ValidatingPecBanner />, { | ||
preloadedState: { contactsState: { digitalAddresses } }, | ||
}); | ||
|
||
expect(queryByTestId('PecVerificationAlert')).not.toBeInTheDocument(); | ||
expect(queryByTestId('ReportProblemOutlinedIcon')).not.toBeInTheDocument(); | ||
const bannerTitle = queryByText('legal-contacts.pec-validation-banner.title'); | ||
const bannerMessage = queryByText('legal-contacts.pec-validation-banner.dod-enabled-message'); | ||
|
||
expect(bannerTitle).not.toBeInTheDocument(); | ||
expect(bannerMessage).not.toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.