diff --git a/.github/workflows/ci_integration_test.yml b/.github/workflows/ci_integration_test.yml index 6d01512eb..b7edd683a 100644 --- a/.github/workflows/ci_integration_test.yml +++ b/.github/workflows/ci_integration_test.yml @@ -2,7 +2,7 @@ name: Integration Tests on: schedule: - - cron: '00 09 * * *' + - cron: '00 09 * * 1,2,3,4,5' workflow_call: inputs: diff --git a/e2e/tests/delegations.spec.ts b/e2e/tests/delegations.spec.ts new file mode 100644 index 000000000..ab139b7dc --- /dev/null +++ b/e2e/tests/delegations.spec.ts @@ -0,0 +1,62 @@ +import { Page, test } from '@playwright/test'; +import { changeToEcUser, checkReturnHomepage } from './utils/e2eUtils'; + +const STATION_ID = '99999000013_02'; +const ecName = 'EC Signed Direct'; +const segregationCode = '40'; + +test.setTimeout(100000); +test.describe('Delegations flow', () => { + // eslint-disable-next-line functional/no-let + let page: Page; + + test.beforeAll(async ({ browser }) => { + page = await browser.newPage({ storageState: undefined }); + await changeToEcUser(page); + }); + + test.afterAll(async () => { + await page.close(); + }); + + test('Associate station to EC', async () => { + await page.getByTestId('stations-test').click(); + await page.getByTestId('search-input').click(); + await page.getByTestId('search-input').fill(STATION_ID); + await page.waitForTimeout(2000); + await page.getByLabel('more').click(); + await page.getByRole('link', { name: 'Gestisci EC' }).click(); + await page.getByRole('link', { name: 'Associa EC' }).click(); + await page.getByLabel('Cerca EC').click(); + await page.getByTestId('ec-selection-id-test').getByLabel('Cerca EC').fill('EC'); + await page.getByRole('option', { name: ecName }).click(); + await page.getByRole('combobox', { name: '​', exact: true }).click(); + await page.getByRole('option', { name: segregationCode }).click(); + await page.getByTestId('confirm-btn-test').click(); + await checkReturnHomepage(page); + }); + + test('Test delegations page & details', async () => { + await page.getByTestId('delegations-test').click(); + await page.getByTestId('search-input').click(); + await page.getByTestId('search-input').fill(ecName); + await page.getByTestId('button-search').click(); + await page.waitForTimeout(2000); + await page.getByTestId('column-go-to-delegation-detail').click(); + }); + + test('Disassociate station', async () => { + await page.getByTestId('search-input').click(); + await page.getByTestId('search-input').fill(STATION_ID); + await page.getByTestId('button-search').click(); + await page.waitForTimeout(2000); + await page.getByTestId('column-station-detail-button').click(); + await page.getByTestId('station-detail-disassociate-station-button').click(); + await page.getByTestId('cancel-button-test').click(); + await page.getByTestId('column-station-detail-button').click(); + await page.getByTestId('station-detail-disassociate-station-button').click(); + await page.getByTestId('confirm-button-test').click(); + await page.getByTestId('exit-btn-test').click(); + await checkReturnHomepage(page); + }); +}); diff --git a/package.json b/package.json index 15d290c85..c203b3af0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pagopa-selfcare-backoffice-frontend", - "version": "1.30.3", + "version": "1.30.3-6-next", "homepage": "ui", "private": true, "scripts": { @@ -28,7 +28,7 @@ "clean:api-portal": "rimraf src/api/generated/portal && rimraf openApi/generated", "generate:api-portal": "wget https://raw.githubusercontent.com/pagopa/pagopa-selfcare-ms-backoffice-backend/main/openapi/openapi.json -O ./openApi/portal-api-docs.json && npm run generate:client", "generate:api-portal-next": "wget https://raw.githubusercontent.com/pagopa/pagopa-selfcare-ms-backoffice-backend/next/openapi/openapi.json -O ./openApi/portal-api-docs.json && npm run generate:client", - "generate:api-portal-pr": "wget https://raw.githubusercontent.com/pagopa/pagopa-selfcare-ms-backoffice-backend/PPANTT-48-add-finish-maintenance-api/openapi/openapi.json -O ./openApi/portal-api-docs.json && npm run generate:client", + "generate:api-portal-pr": "wget https://raw.githubusercontent.com/pagopa/pagopa-selfcare-ms-backoffice-backend/PPANTT-93-new-api-key-aca/openapi/openapi.json -O ./openApi/portal-api-docs.json && npm run generate:client", "generate:api-portal-local": "npm run generate:client", "generate:client": "jq 'walk(if type == \"object\" and has(\"parameters\") then .parameters |= map(select(.name != \"X-Request-Id\")) else . end)' ./openApi/portal-api-docs.json > ./openApi/portal-api-docs.json.temp && mv ./openApi/portal-api-docs.json.temp ./openApi/portal-api-docs.json && yarn run clean:api-portal && mkdirp openApi/generated && gen-api-models --api-spec openApi/portal-api-docs.json --out-dir src/api/generated/portal --no-strict --request-types --response-decoders --client && node openApi/scripts/api-portal_fixPostGen.js" }, diff --git a/src/api/BackofficeClient.ts b/src/api/BackofficeClient.ts index a38ff26b3..7e9a0f851 100644 --- a/src/api/BackofficeClient.ts +++ b/src/api/BackofficeClient.ts @@ -399,7 +399,7 @@ export const BackofficeApi = { const result = await backofficeClient.getChannels({ status: String(status), brokerCode, - channelCode, + ...(channelCode ? {channelCode} : {}), limit, page, }); diff --git a/src/locale/it.json b/src/locale/it.json index 3799db66f..abe9abb14 100644 --- a/src/locale/it.json +++ b/src/locale/it.json @@ -253,7 +253,8 @@ "FDR_PSP": "FdR - Flussi di Rendicontazione (PSP)", "BO_EXT_EC": "Backoffice External (EC)", "BO_EXT_PSP": "Backoffice External (PSP)", - "PRINT_NOTICE": "Stampa Avvisi" + "PRINT_NOTICE": "Stampa Avvisi", + "ACA": "ACA - paCreatePosition" } }, "channelsPage": { diff --git a/src/model/ApiKey.tsx b/src/model/ApiKey.tsx index 78015b250..11c041646 100644 --- a/src/model/ApiKey.tsx +++ b/src/model/ApiKey.tsx @@ -29,6 +29,7 @@ export const API_KEY_PRODUCTS = { BO_EXT_EC: { id: 'BO_EXT_EC', key: 'selfcareboexternalec-' }, BO_EXT_PSP: { id: 'BO_EXT_PSP', key: 'selfcareboexternalpsp-' }, PRINT_NOTICE: { id: 'PRINT_NOTICE', key: 'printnotice-' }, + ACA: {id: "ACA", key:"aca-"} }; export const getApiKeyProducts = ( @@ -44,6 +45,7 @@ export const getApiKeyProducts = ( API_KEY_PRODUCTS.GPD_REP, API_KEY_PRODUCTS.BIZ, API_KEY_PRODUCTS.BO_EXT_EC, + API_KEY_PRODUCTS.ACA ]; if (ENV.FEATURES.FDR.ENABLED) { diff --git a/src/model/__tests__/ApiKey.test.tsx b/src/model/__tests__/ApiKey.test.tsx index 9d2437247..2794f4da2 100644 --- a/src/model/__tests__/ApiKey.test.tsx +++ b/src/model/__tests__/ApiKey.test.tsx @@ -12,7 +12,8 @@ describe("Test ApiKey model methods", ()=> { API_KEY_PRODUCTS.BIZ, API_KEY_PRODUCTS.BO_EXT_EC, API_KEY_PRODUCTS.FDR_ORG, - API_KEY_PRODUCTS.PRINT_NOTICE + API_KEY_PRODUCTS.PRINT_NOTICE, + API_KEY_PRODUCTS.ACA ]) }) }) \ No newline at end of file diff --git a/src/pages/commisionalBundles/addEditCommissionBundle/components/AddEditCommissionBundleForm.tsx b/src/pages/commisionalBundles/addEditCommissionBundle/components/AddEditCommissionBundleForm.tsx index 86c425bb1..a68eb94f8 100644 --- a/src/pages/commisionalBundles/addEditCommissionBundle/components/AddEditCommissionBundleForm.tsx +++ b/src/pages/commisionalBundles/addEditCommissionBundle/components/AddEditCommissionBundleForm.tsx @@ -1,758 +1,788 @@ /* eslint-disable functional/no-let */ /* eslint-disable complexity */ /* eslint-disable sonarjs/cognitive-complexity */ -import {InfoOutlined, MenuBook} from '@mui/icons-material'; +import { InfoOutlined, MenuBook } from '@mui/icons-material'; import BookmarkAddIcon from '@mui/icons-material/BookmarkAdd'; import DateRangeIcon from '@mui/icons-material/DateRange'; import EuroIcon from '@mui/icons-material/Euro'; import { - Autocomplete, - Box, - FormControl, - FormControlLabel, - FormLabel, - Grid, - InputLabel, - MenuItem, - Paper, - Radio, - RadioGroup, - Select, - Switch, - TextField, - TextFieldProps, - Tooltip, - Typography, + Autocomplete, + Box, + FormControl, + FormControlLabel, + FormLabel, + Grid, + InputLabel, + MenuItem, + Paper, + Radio, + RadioGroup, + Select, + Switch, + TextField, + TextFieldProps, + Tooltip, + Typography, } from '@mui/material'; -import {DesktopDatePicker, LocalizationProvider} from '@mui/x-date-pickers'; -import {AdapterDateFns} from '@mui/x-date-pickers/AdapterDateFns'; -import {theme} from '@pagopa/mui-italia'; -import {useErrorDispatcher, useLoading} from '@pagopa/selfcare-common-frontend'; -import {FormikProps} from 'formik'; -import {add, isBefore} from "date-fns"; -import {useEffect, useState} from 'react'; -import {useTranslation} from 'react-i18next'; -import {NumericFormat} from 'react-number-format'; -import {BundleRequest} from '../../../../api/generated/portal/BundleRequest'; -import {Delegation} from '../../../../api/generated/portal/Delegation'; -import {TypeEnum} from '../../../../api/generated/portal/PSPBundleResource'; -import {PaymentTypes} from '../../../../api/generated/portal/PaymentTypes'; -import {Touchpoints} from '../../../../api/generated/portal/Touchpoints'; +import { DesktopDatePicker, LocalizationProvider } from '@mui/x-date-pickers'; +import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns'; +import { theme } from '@pagopa/mui-italia'; +import { useErrorDispatcher, useLoading } from '@pagopa/selfcare-common-frontend'; +import { FormikProps } from 'formik'; +import { add, isBefore } from 'date-fns'; +import { useEffect, useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { NumericFormat } from 'react-number-format'; +import { BundleRequest } from '../../../../api/generated/portal/BundleRequest'; +import { Delegation } from '../../../../api/generated/portal/Delegation'; +import { TypeEnum } from '../../../../api/generated/portal/PSPBundleResource'; +import { PaymentTypes } from '../../../../api/generated/portal/PaymentTypes'; +import { Touchpoints } from '../../../../api/generated/portal/Touchpoints'; import FormSectionTitle from '../../../../components/Form/FormSectionTitle'; -import {useFlagValue} from '../../../../hooks/useFeatureFlags'; -import {useOrganizationType} from '../../../../hooks/useOrganizationType'; -import {Party} from '../../../../model/Party'; -import {sortPaymentType} from '../../../../model/PaymentType'; -import {ConfigurationStatus} from '../../../../model/Station'; -import {useAppSelector} from '../../../../redux/hooks'; -import {partiesSelectors} from '../../../../redux/slices/partiesSlice'; -import {getTouchpoints} from '../../../../services/bundleService'; -import {getChannels} from '../../../../services/channelService'; -import {getPaymentTypes} from '../../../../services/configurationService'; -import {getBrokerDelegation} from '../../../../services/institutionService'; -import {addCurrentBroker} from '../../../../utils/channel-utils'; -import {LOADING_TASK_COMMISSION_BUNDLE_SELECT_DATAS, LOADING_TASK_GET_CHANNELS_IDS,} from '../../../../utils/constants'; -import {WrapperChannelResource} from '../../../../api/generated/portal/WrapperChannelResource'; +import { useFlagValue } from '../../../../hooks/useFeatureFlags'; +import { useOrganizationType } from '../../../../hooks/useOrganizationType'; +import { Party } from '../../../../model/Party'; +import { sortPaymentType } from '../../../../model/PaymentType'; +import { ConfigurationStatus } from '../../../../model/Station'; +import { useAppSelector } from '../../../../redux/hooks'; +import { partiesSelectors } from '../../../../redux/slices/partiesSlice'; +import { getTouchpoints } from '../../../../services/bundleService'; +import { getChannels } from '../../../../services/channelService'; +import { getPaymentTypes } from '../../../../services/configurationService'; +import { getBrokerDelegation } from '../../../../services/institutionService'; +import { addCurrentBroker } from '../../../../utils/channel-utils'; +import { + LOADING_TASK_COMMISSION_BUNDLE_SELECT_DATAS, + LOADING_TASK_GET_CHANNELS_IDS, +} from '../../../../utils/constants'; +import { WrapperChannelResource } from '../../../../api/generated/portal/WrapperChannelResource'; type Props = { - formik: FormikProps; - isEdit: boolean; - idBrokerPsp: string | undefined; + formik: FormikProps; + isEdit: boolean; + idBrokerPsp: string | undefined; }; -const AddEditCommissionBundleForm = ({isEdit, formik, idBrokerPsp}: Props) => { - const {t} = useTranslation(); - const {orgIsPspDirect} = useOrganizationType(); - const setLoading = useLoading(LOADING_TASK_COMMISSION_BUNDLE_SELECT_DATAS); - const setLoadingChannels = useLoading(LOADING_TASK_GET_CHANNELS_IDS); - const addError = useErrorDispatcher(); - const isPrivateEnabled = useFlagValue('commission-bundles-private'); - const isPublicEnabled = useFlagValue('commission-bundles-public'); - const selectedParty = useAppSelector(partiesSelectors.selectPartySelected); - - const [paymentOptions, setPaymentOptions] = useState(); - const [touchpointList, setTouchpointList] = useState(); - const [brokerDelegationList, setBrokerDelegationList] = useState>([]); - const [channels, setChannels] = useState>([]); - const [isChannelV2, setIsChannelV2] = useState(false); +const AddEditCommissionBundleForm = ({ isEdit, formik, idBrokerPsp }: Props) => { + const { t } = useTranslation(); + const { orgIsPspDirect } = useOrganizationType(); + const setLoading = useLoading(LOADING_TASK_COMMISSION_BUNDLE_SELECT_DATAS); + const setLoadingChannels = useLoading(LOADING_TASK_GET_CHANNELS_IDS); + const addError = useErrorDispatcher(); + const isPrivateEnabled = useFlagValue('commission-bundles-private'); + const isPublicEnabled = useFlagValue('commission-bundles-public'); + const selectedParty = useAppSelector(partiesSelectors.selectPartySelected); - const inputGroupStyle = { - borderRadius: 1, - border: 1, - borderColor: theme.palette.divider, - p: 3, - mb: 3, - }; + const [paymentOptions, setPaymentOptions] = useState(); + const [touchpointList, setTouchpointList] = useState(); + const [brokerDelegationList, setBrokerDelegationList] = useState>([]); + const [channels, setChannels] = useState>([]); + const [isChannelV2, setIsChannelV2] = useState(false); - const getChannelsByBrokerCode = (selectedBrokerCode: string) => { - setLoadingChannels(true); - getChannels({status: ConfigurationStatus.ACTIVE, brokerCode: selectedBrokerCode}) - .then((data) => { - if (data?.channels && data.channels.length > 0) { - setChannels([...data.channels]); - handleIsChannelV2(formik.values.idChannel, [...data.channels]); - } else { - setChannels([]); - addError({ - id: 'GET_BROKER_DELEGATIONS_DATA', - blocking: false, - error: new Error(`An error occurred while getting data`), - techDescription: `An error occurred while getting data`, - toNotify: true, - displayableTitle: t('general.errorTitle'), - displayableDescription: t( - 'commissionBundlesPage.addEditCommissionBundle.error.errorMessageNoBrokerDelegations' - ), - component: 'Toast', - }); - } - }) - .catch((error) => { - setChannels([]); - addError({ - id: 'GET_CHANNEL_IDS_DATA', - blocking: false, - error: error as Error, - techDescription: `An error occurred while getting data`, - toNotify: true, - displayableTitle: t('general.errorTitle'), - displayableDescription: t( - 'commissionBundlesPage.addEditCommissionBundle.error.errorMessageChannelIdsDataDesc' - ), - component: 'Toast', - }); - }) - .finally(() => setLoadingChannels(false)); - }; + const [filterChannelCode, setFilterChannelCode] = useState(null); - useEffect(() => { - setLoading(true); - Promise.all([ - getPaymentTypes(), - getTouchpoints(0, 50), - getBrokerDelegation(selectedParty?.partyId ?? '', undefined), - ]) - .then(([paymentTypes, touchpoints, brokerDelegation]) => { - if (paymentTypes) { - setPaymentOptions(paymentTypes); - } - if (touchpoints) { - setTouchpointList(touchpoints); - } - let listBroker = brokerDelegation?.delegation_list - ? [...brokerDelegation.delegation_list] - : []; - if (orgIsPspDirect) { - listBroker = addCurrentBroker(listBroker, selectedParty as Party); - } + const inputGroupStyle = { + borderRadius: 1, + border: 1, + borderColor: theme.palette.divider, + p: 3, + mb: 3, + }; - if (listBroker.length > 0) { - setBrokerDelegationList(listBroker); - if (isEdit && idBrokerPsp) { - const brokerTaxCode = listBroker?.find( - (el) => el.broker_tax_code === idBrokerPsp - )?.broker_tax_code; - if (brokerTaxCode) { - getChannelsByBrokerCode(brokerTaxCode); - } - } - } else { - addError({ - id: 'GET_BROKER_DATA', - blocking: false, - error: new Error(`An error occurred while getting data`), - techDescription: `An error occurred while getting data`, - toNotify: true, - displayableTitle: t('general.errorTitle'), - displayableDescription: t( - 'commissionBundlesPage.addEditCommissionBundle.error.errorMessageNoBroker' - ), - component: 'Toast', - }); - } - }) - .catch((reason) => { - addError({ - id: 'GET_ALL_DATA', - blocking: false, - error: reason as Error, - techDescription: `An error occurred while getting data`, - toNotify: true, - displayableTitle: t('general.errorTitle'), - displayableDescription: t( - 'commissionBundlesPage.addEditCommissionBundle.error.errorMessageAllDataDesc' - ), - component: 'Toast', - }); - }) - .finally(() => { - setLoading(false); + const getChannelsByBrokerCode = (selectedBrokerCode: string, filterByChannel?: string, fromAutocomplete?: boolean) => { + if (!fromAutocomplete) { + setLoadingChannels(true); + } + getChannels({ + status: ConfigurationStatus.ACTIVE, + brokerCode: selectedBrokerCode, + channelCode: filterByChannel, + limit: 25 + }) + .then((data) => { + if (data?.channels && data.channels.length > 0) { + setChannels([...data.channels]); + handleIsChannelV2(formik.values.idChannel, [...data.channels]); + } else { + setChannels([]); + if (!fromAutocomplete) { + addError({ + id: 'GET_BROKER_DELEGATIONS_DATA', + blocking: false, + error: new Error(`An error occurred while getting data`), + techDescription: `An error occurred while getting data`, + toNotify: true, + displayableTitle: t('general.errorTitle'), + displayableDescription: t( + 'commissionBundlesPage.addEditCommissionBundle.error.errorMessageNoBrokerDelegations' + ), + component: 'Toast', }); - }, [selectedParty]); + } + } + }) + .catch((error) => { + setChannels([]); + addError({ + id: 'GET_CHANNEL_IDS_DATA', + blocking: false, + error: error as Error, + techDescription: `An error occurred while getting data`, + toNotify: true, + displayableTitle: t('general.errorTitle'), + displayableDescription: t( + 'commissionBundlesPage.addEditCommissionBundle.error.errorMessageChannelIdsDataDesc' + ), + component: 'Toast', + }); + }) + .finally(() => setLoadingChannels(false)); + }; - function handleBrokerCodesSelection(value: string | null | undefined) { - formik.setFieldValue('idChannel', ''); - handleIsChannelV2(); - if (value === null || value === undefined) { - formik.setFieldValue('idBrokerPsp', ''); - setChannels([]); - } else { - const broker = brokerDelegationList?.find((el) => el.broker_name === value); - formik.handleChange('idBrokerPsp')(broker?.broker_tax_code ?? ''); - if (broker?.broker_tax_code) { - getChannelsByBrokerCode(broker?.broker_tax_code); + useEffect(() => { + setLoading(true); + Promise.all([ + getPaymentTypes(), + getTouchpoints(0, 50), + getBrokerDelegation(selectedParty?.partyId ?? '', undefined), + ]) + .then(([paymentTypes, touchpoints, brokerDelegation]) => { + if (paymentTypes) { + setPaymentOptions(paymentTypes); + } + if (touchpoints) { + setTouchpointList(touchpoints); + } + let listBroker = brokerDelegation?.delegation_list + ? [...brokerDelegation.delegation_list] + : []; + if (orgIsPspDirect) { + listBroker = addCurrentBroker(listBroker, selectedParty as Party); + } + + if (listBroker.length > 0) { + setBrokerDelegationList(listBroker); + if (isEdit && idBrokerPsp) { + const brokerTaxCode = listBroker?.find( + (el) => el.broker_tax_code === idBrokerPsp + )?.broker_tax_code; + if (brokerTaxCode) { + getChannelsByBrokerCode(brokerTaxCode); } + } + } else { + addError({ + id: 'GET_BROKER_DATA', + blocking: false, + error: new Error(`An error occurred while getting data`), + techDescription: `An error occurred while getting data`, + toNotify: true, + displayableTitle: t('general.errorTitle'), + displayableDescription: t( + 'commissionBundlesPage.addEditCommissionBundle.error.errorMessageNoBroker' + ), + component: 'Toast', + }); } + }) + .catch((reason) => { + addError({ + id: 'GET_ALL_DATA', + blocking: false, + error: reason as Error, + techDescription: `An error occurred while getting data`, + toNotify: true, + displayableTitle: t('general.errorTitle'), + displayableDescription: t( + 'commissionBundlesPage.addEditCommissionBundle.error.errorMessageAllDataDesc' + ), + component: 'Toast', + }); + }) + .finally(() => { + setLoading(false); + }); + }, [selectedParty]); + + function handleBrokerCodesSelection(value: string | null | undefined) { + formik.setFieldValue('idChannel', ''); + handleIsChannelV2(); + if (value === null || value === undefined) { + formik.setFieldValue('idBrokerPsp', ''); + setChannels([]); + } else { + const broker = brokerDelegationList?.find((el) => el.broker_name === value); + formik.handleChange('idBrokerPsp')(broker?.broker_tax_code ?? ''); + if (broker?.broker_tax_code) { + getChannelsByBrokerCode(broker?.broker_tax_code); + } } + } - const handleIsChannelV2 = ( - channelCode?: string | null, - channelList?: Array - ) => { - let bool = false; - if (channelCode) { - const arrayChannel = channelList ?? channels; - bool = arrayChannel.find((el) => el.channel_code === channelCode)?.primitive_version === 2; - } + const handleIsChannelV2 = ( + channelCode?: string | null, + channelList?: Array + ) => { + let bool = false; + if (channelCode) { + const arrayChannel = channelList ?? channels; + bool = arrayChannel.find((el) => el.channel_code === channelCode)?.primitive_version === 2; + } - setIsChannelV2(bool); - if (!bool) { - formik.setFieldValue('cart', false); - } - }; + setIsChannelV2(bool); + if (!bool) { + formik.setFieldValue('cart', false); + } + }; - const handleChangeChannel = (value: string | null) => { - formik.handleChange('idChannel')(value ?? ''); - handleIsChannelV2(value); - }; + const handleChangeChannel = (value: string | null) => { + formik.handleChange('idChannel')(value ?? ''); + handleIsChannelV2(value); + }; - return ( - <> - - - {t('commissionBundlesPage.addEditCommissionBundle.form.bundleType')} - + useEffect(() => { + const timeout = setTimeout(() => { + if (formik.values.idBrokerPsp && filterChannelCode !== null) { + getChannelsByBrokerCode(formik.values.idBrokerPsp, filterChannelCode, true); + } + }, 300); + return () => clearTimeout(timeout); + }, [filterChannelCode]); - - formik.setFieldValue('type', e.target.value)} - data-testid="bundle-type-test" - value={`${formik.values.type}`} - > - } - label={t('commissionBundlesPage.globalBundles')} - sx={{pr: 8}} - disabled={isEdit} - /> - } - label={t('commissionBundlesPage.publicBundles')} - sx={{pr: 8}} - disabled={isEdit || !isPublicEnabled} - /> - } - label={t('commissionBundlesPage.privateBundles')} - disabled={isEdit || !isPrivateEnabled} - /> - - - - - - {t('commissionBundlesPage.addEditCommissionBundle.form.bundleConfiguration')} - + return ( + <> + + + {t('commissionBundlesPage.addEditCommissionBundle.form.bundleType')} + + + + formik.setFieldValue('type', e.target.value)} + data-testid="bundle-type-test" + value={`${formik.values.type}`} + > + } + label={t('commissionBundlesPage.globalBundles')} + sx={{ pr: 8 }} + disabled={isEdit} + /> + } + label={t('commissionBundlesPage.publicBundles')} + sx={{ pr: 8 }} + disabled={isEdit || !isPublicEnabled} + /> + } + label={t('commissionBundlesPage.privateBundles')} + disabled={isEdit || !isPrivateEnabled} + /> + + + + + + {t('commissionBundlesPage.addEditCommissionBundle.form.bundleConfiguration')} + - - - } - /> - - - formik.handleChange(e)} - error={formik.touched.name && Boolean(formik.errors.name)} - helperText={formik.touched.name && formik.errors.name} - inputProps={{ - 'data-testid': 'name-test', - }} - /> - + + + } + /> + + + formik.handleChange(e)} + error={formik.touched.name && Boolean(formik.errors.name)} + helperText={formik.touched.name && formik.errors.name} + inputProps={{ + 'data-testid': 'name-test', + }} + /> + - - formik.handleChange(e)} - error={formik.touched.description && Boolean(formik.errors.description)} - helperText={formik.touched.description && formik.errors.description} - inputProps={{ - 'data-testid': 'description-test', - }} - /> - - - - - {t('commissionBundlesPage.addEditCommissionBundle.form.paymentType')} - - - - - - - - {t('commissionBundlesPage.addEditCommissionBundle.form.touchpoint')} - - - - - + + formik.handleChange(e)} + error={formik.touched.description && Boolean(formik.errors.description)} + helperText={formik.touched.description && formik.errors.description} + inputProps={{ + 'data-testid': 'description-test', + }} + /> + + + + + {t('commissionBundlesPage.addEditCommissionBundle.form.paymentType')} + + + + + + + + {t('commissionBundlesPage.addEditCommissionBundle.form.touchpoint')} + + + + + - - } - /> - - - { - const numericValue = parseFloat(value.replace(',', '.')); - formik.setFieldValue('minPaymentAmount', numericValue * 100); - }} - thousandSeparator="" - decimalSeparator="," - allowNegative={false} - decimalScale={2} - fixedDecimalScale={false} - error={ - formik.touched.minPaymentAmount && Boolean(formik.errors.minPaymentAmount) - } - helperText={formik.touched.minPaymentAmount && formik.errors.minPaymentAmount} - InputProps={{ - endAdornment: , - }} - inputProps={{'data-testid': 'min-import-test'}} - /> - + + } + /> + + + { + const numericValue = parseFloat(value.replace(',', '.')); + formik.setFieldValue('minPaymentAmount', numericValue * 100); + }} + thousandSeparator="" + decimalSeparator="," + allowNegative={false} + decimalScale={2} + fixedDecimalScale={false} + error={ + formik.touched.minPaymentAmount && Boolean(formik.errors.minPaymentAmount) + } + helperText={formik.touched.minPaymentAmount && formik.errors.minPaymentAmount} + InputProps={{ + endAdornment: , + }} + inputProps={{ 'data-testid': 'min-import-test' }} + /> + - - { - const numericValue = parseFloat(value.replace(',', '.')); - formik.setFieldValue('maxPaymentAmount', numericValue * 100); - }} - thousandSeparator="" - decimalSeparator="," - allowNegative={false} - decimalScale={2} - fixedDecimalScale={false} - error={ - formik.touched.maxPaymentAmount && Boolean(formik.errors.maxPaymentAmount) - } - helperText={formik.touched.maxPaymentAmount && formik.errors.maxPaymentAmount} - InputProps={{ - endAdornment: , - }} - inputProps={{'data-testid': 'max-import-test'}} - /> - - - + + { + const numericValue = parseFloat(value.replace(',', '.')); + formik.setFieldValue('maxPaymentAmount', numericValue * 100); + }} + thousandSeparator="" + decimalSeparator="," + allowNegative={false} + decimalScale={2} + fixedDecimalScale={false} + error={ + formik.touched.maxPaymentAmount && Boolean(formik.errors.maxPaymentAmount) + } + helperText={formik.touched.maxPaymentAmount && formik.errors.maxPaymentAmount} + InputProps={{ + endAdornment: , + }} + inputProps={{ 'data-testid': 'max-import-test' }} + /> + + + - - } - /> - - - { - const numericValue = parseFloat(value.replace(',', '.')); - formik.setFieldValue('paymentAmount', numericValue * 100); - }} - thousandSeparator="" - decimalSeparator="," - allowNegative={false} - decimalScale={2} - fixedDecimalScale={false} - error={formik.touched.paymentAmount && Boolean(formik.errors.paymentAmount)} - helperText={formik.touched.paymentAmount && formik.errors.paymentAmount} - InputProps={{ - endAdornment: , - }} - inputProps={{'data-testid': 'payment-amount-test'}} - /> - - - - - - } - /> - - - el?.broker_name ?? '') - ?.sort((a, b) => a.localeCompare(b))} - disabled={!(brokerDelegationList && brokerDelegationList.length > 0)} - value={ - brokerDelegationList?.find( - (el) => el.broker_tax_code === formik.values.idBrokerPsp - )?.broker_name ?? '' - } - onChange={(_, value) => { - handleBrokerCodesSelection(value); - }} - fullWidth - renderInput={(params) => ( - - )} - PaperComponent={({children}) => ( - {children} - )} - noOptionsText={t( - 'commissionBundlesPage.addEditCommissionBundle.form.noBrokersOption' - )} - data-testid="broker-code-test" - /> - - - el.channel_code).sort((a, b) => a.localeCompare(b))} - disabled={!(channels && channels.length > 0)} - onChange={(_event, value) => handleChangeChannel(value)} - value={formik.values.idChannel} - fullWidth - renderInput={(params) => ( - - )} - PaperComponent={({children}) => ( - {children} - )} - noOptionsText={t( - 'commissionBundlesPage.addEditCommissionBundle.form.noChannelsOption' - )} - data-testid="channels-id-test" - /> - - - formik.setFieldValue('cart', e.target.checked)} - checked={formik.values.cart ?? false} - disabled={!isChannelV2} - data-testid="bundle-cart" - /> - } - label={ -
- {t('commissionBundlesPage.addEditCommissionBundle.form.cart')} - - - -
- } - /> -
-
-
- - } - /> - - - - - {t( - 'commissionBundlesPage.addEditCommissionBundle.form.paymentWithDigitalStamp' - )} - - - formik.setFieldValue('digitalStamp', e.target.value === 'true') - } - row - data-testid="digital-stamp-test" - value={formik.values.digitalStamp ? `${formik.values.digitalStamp}` : 'false'} - > - } - label={t('general.no')} - sx={{pr: 3}} - /> - } - disabled={formik.values.digitalStampRestriction} - label={t('general.yes')} - /> - - - - - - - {t( - 'commissionBundlesPage.addEditCommissionBundle.form.paymentOnlyDigitalStamp' - )} - - - formik.setFieldValue('digitalStampRestriction', e.target.value === 'true') - } - row - data-testid="digital-stamp-restriction-test" - value={ - formik.values.digitalStampRestriction - ? `${formik.values.digitalStampRestriction}` - : 'false' - } - > - } - label={t('general.no')} - sx={{pr: 3}} - /> - } - disabled={formik.values.digitalStamp} - label={t('general.yes')} - /> - - - - - - - } - /> - - - - { - formik.setFieldValue('validityDateFrom', value); - if (formik.values.validityDateTo && value - && isBefore(formik.values.validityDateTo, value)) { - formik.setFieldValue('validityDateTo', null); - } - }} - renderInput={(params: TextFieldProps) => ( - - )} - shouldDisableDate={(date: Date) => { - let limit = new Date(); - limit = add(limit, {days: 2}); - return date < limit; - }} - disabled={isEdit} - /> - - - - - formik.setFieldValue('validityDateTo', value)} - renderInput={(params: TextFieldProps) => ( - - )} - shouldDisableDate={(date: Date) => isBefore(date, formik.values.validityDateFrom ?? new Date())} - /> - - - - -
-
- - ); + + } + /> + + + { + const numericValue = parseFloat(value.replace(',', '.')); + formik.setFieldValue('paymentAmount', numericValue * 100); + }} + thousandSeparator="" + decimalSeparator="," + allowNegative={false} + decimalScale={2} + fixedDecimalScale={false} + error={formik.touched.paymentAmount && Boolean(formik.errors.paymentAmount)} + helperText={formik.touched.paymentAmount && formik.errors.paymentAmount} + InputProps={{ + endAdornment: , + }} + inputProps={{ 'data-testid': 'payment-amount-test' }} + /> + + + + + + } + /> + + + el?.broker_name ?? '') + ?.sort((a, b) => a.localeCompare(b))} + disabled={!(brokerDelegationList && brokerDelegationList.length > 0)} + value={ + brokerDelegationList?.find( + (el) => el.broker_tax_code === formik.values.idBrokerPsp + )?.broker_name ?? '' + } + onChange={(_, value) => { + handleBrokerCodesSelection(value); + }} + fullWidth + renderInput={(params) => ( + + )} + PaperComponent={({ children }) => ( + {children} + )} + noOptionsText={t( + 'commissionBundlesPage.addEditCommissionBundle.form.noBrokersOption' + )} + data-testid="broker-code-test" + /> + + + el.channel_code).sort((a, b) => a.localeCompare(b))} + disabled={!formik.values.idBrokerPsp} + onChange={(_event, value) => handleChangeChannel(value)} + value={formik.values.idChannel} + fullWidth + filterOptions={(x) => x} + onInputChange={(_, value) => setFilterChannelCode(value)} + renderInput={(params) => ( + + )} + PaperComponent={({ children }) => ( + {children} + )} + noOptionsText={t( + 'commissionBundlesPage.addEditCommissionBundle.form.noChannelsOption' + )} + data-testid="channels-id-test" + /> + + + formik.setFieldValue('cart', e.target.checked)} + checked={formik.values.cart ?? false} + disabled={!isChannelV2} + data-testid="bundle-cart" + /> + } + label={ +
+ {t('commissionBundlesPage.addEditCommissionBundle.form.cart')} + + + +
+ } + /> +
+
+
+ + } + /> + + + + + {t( + 'commissionBundlesPage.addEditCommissionBundle.form.paymentWithDigitalStamp' + )} + + + formik.setFieldValue('digitalStamp', e.target.value === 'true') + } + row + data-testid="digital-stamp-test" + value={formik.values.digitalStamp ? `${formik.values.digitalStamp}` : 'false'} + > + } + label={t('general.no')} + sx={{ pr: 3 }} + /> + } + disabled={formik.values.digitalStampRestriction} + label={t('general.yes')} + /> + + + + + + + {t( + 'commissionBundlesPage.addEditCommissionBundle.form.paymentOnlyDigitalStamp' + )} + + + formik.setFieldValue('digitalStampRestriction', e.target.value === 'true') + } + row + data-testid="digital-stamp-restriction-test" + value={ + formik.values.digitalStampRestriction + ? `${formik.values.digitalStampRestriction}` + : 'false' + } + > + } + label={t('general.no')} + sx={{ pr: 3 }} + /> + } + disabled={formik.values.digitalStamp} + label={t('general.yes')} + /> + + + + + + + } + /> + + + + { + formik.setFieldValue('validityDateFrom', value); + if ( + formik.values.validityDateTo && + value && + isBefore(formik.values.validityDateTo, value) + ) { + formik.setFieldValue('validityDateTo', null); + } + }} + renderInput={(params: TextFieldProps) => ( + + )} + shouldDisableDate={(date: Date) => { + let limit = new Date(); + limit = add(limit, { days: 2 }); + return date < limit; + }} + disabled={isEdit} + /> + + + + + formik.setFieldValue('validityDateTo', value)} + renderInput={(params: TextFieldProps) => ( + + )} + shouldDisableDate={(date: Date) => + isBefore(date, formik.values.validityDateFrom ?? new Date()) + } + /> + + + + + +
+ + ); }; export default AddEditCommissionBundleForm; diff --git a/src/pages/commisionalBundles/addEditCommissionBundle/components/__tests__/AddEditCommissionBundleForm.test.tsx b/src/pages/commisionalBundles/addEditCommissionBundle/components/__tests__/AddEditCommissionBundleForm.test.tsx index b42bbad4f..c3e16ee26 100644 --- a/src/pages/commisionalBundles/addEditCommissionBundle/components/__tests__/AddEditCommissionBundleForm.test.tsx +++ b/src/pages/commisionalBundles/addEditCommissionBundle/components/__tests__/AddEditCommissionBundleForm.test.tsx @@ -7,8 +7,7 @@ import { Provider } from 'react-redux'; import React from 'react'; import { mockedBundleRequest, - mockedBundleRequestForEdit, - mockedChannelsIdList, + mockedBundleRequestForEdit } from '../../../../../services/__mocks__/bundleService'; import { partiesActions } from '../../../../../redux/slices/partiesSlice'; import { pspOperatorSignedDirect } from '../../../../../services/__mocks__/partyService'; @@ -24,6 +23,7 @@ import * as useUserRole from '../../../../../hooks/useUserRole'; import { ROLE } from '../../../../../model/RolePermission'; import { TypeEnum } from '../../../../../api/generated/portal/PSPBundleResource'; import * as useOrganizationType from '../../../../../hooks/useOrganizationType'; +import { mockedChannels, channelCode } from '../../../../../services/__mocks__/channelService'; let spyOnGetPaymentTypes: jest.SpyInstance; let spyOnGetTouchpoint: jest.SpyInstance; @@ -306,16 +306,16 @@ describe('', () => { // Change channel id fireEvent.change(input.channelList, { - target: { value: mockedChannelsIdList[0] }, + target: { value: mockedChannels.channels[4].channel_code }, }); input.channelList.focus(); fireEvent.change(document.activeElement as Element, { - target: { value: mockedChannelsIdList[0] }, + target: { value: mockedChannels.channels[4].channel_code }, }); fireEvent.keyDown(document.activeElement as Element, { key: 'ArrowDown' }); fireEvent.keyDown(document.activeElement as Element, { key: 'Enter' }); - expect(input.channelList.value).toEqual(mockedChannelsIdList[0]); + expect(input.channelList.value).toEqual(mockedChannels.channels[4].channel_code); //Change radio buttons digitalStamp expect(input.digitalStampYes.checked).toBe(false);