diff --git a/.env.development.local b/.env.development.local index f6e76fc3a..fc138af85 100644 --- a/.env.development.local +++ b/.env.development.local @@ -16,8 +16,8 @@ REACT_APP_URL_FE_TOKEN_EXCHANGE=https://dev.selfcare.pagopa.it/token-exchange REACT_APP_URL_INSTITUTION_LOGO_PREFIX=https://selcdcheckoutsa.z6.web.core.windows.net/institutions/ # Backends configuration -#REACT_APP_URL_BACKOFFICE=http://localhost:8080 -REACT_APP_URL_BACKOFFICE=https://api.dev.platform.pagopa.it/backoffice/v1 +REACT_APP_URL_BACKOFFICE=http://localhost:8080 +#REACT_APP_URL_BACKOFFICE=https://api.dev.platform.pagopa.it/backoffice/v1 REACT_APP_URL_API_TOKEN=https://api.dev.platform.pagopa.it/api/token/token REACT_APP_URL_BETA=false diff --git a/src/api/BackofficeClient.ts b/src/api/BackofficeClient.ts index 686699c2f..3d428b199 100644 --- a/src/api/BackofficeClient.ts +++ b/src/api/BackofficeClient.ts @@ -774,11 +774,20 @@ export const BackofficeApi = { return extractResponse(result, 200, onRedirectToLogin); }, - updateWrapperStationByOpt: async (station: StationDetailsDto): Promise => { - const result = await backofficeClient.updateWrapperStationDetailsByOpt({ + updateWrapperStationWithOperatorReview: async ({ + stationCode, + ciTaxCode, + note, + }: { + stationCode: string; + ciTaxCode: string; + note: string; + }): Promise => { + const result = await backofficeClient.updateWrapperStationWithOperatorReview({ + 'station-code': stationCode, + ciTaxCode, body: { - ...station, - status: StatusEnum.TO_CHECK_UPDATE, + note }, }); return extractResponse(result, 200, onRedirectToLogin); diff --git a/src/components/CommonHeader/MyHeaderProduct.tsx b/src/components/CommonHeader/MyHeaderProduct.tsx index af4959ad1..c52c076c6 100644 --- a/src/components/CommonHeader/MyHeaderProduct.tsx +++ b/src/components/CommonHeader/MyHeaderProduct.tsx @@ -66,7 +66,6 @@ const HeaderProduct = ({ useEffect(() => { - console.log('useEffect'); getOptions(); }, [organizations]); diff --git a/src/components/Form/GenericModal.tsx b/src/components/Form/GenericModal.tsx index 450c986b4..463e31437 100644 --- a/src/components/Form/GenericModal.tsx +++ b/src/components/Form/GenericModal.tsx @@ -2,13 +2,14 @@ import { Modal, Backdrop, Fade, Box, Typography, Button } from '@mui/material'; import { MouseEventHandler } from 'react'; type Props = { - title: string; - message: any; openModal: boolean; - onConfirmLabel: string; - onCloseLabel: string; - handleCloseModal: MouseEventHandler; - handleConfirm: MouseEventHandler; + + title?: string; + message?: any; + onConfirmLabel?: string; + onCloseLabel?: string; + handleCloseModal?: MouseEventHandler; + handleConfirm?: MouseEventHandler; renderContent?: () => any; }; diff --git a/src/components/StatusChip.tsx b/src/components/StatusChip.tsx index 5610ec151..3fb4d7ec7 100644 --- a/src/components/StatusChip.tsx +++ b/src/components/StatusChip.tsx @@ -1,5 +1,6 @@ import { Chip } from '@mui/material'; import { useTranslation } from 'react-i18next'; +import { useUserRole } from '../hooks/useUserRole'; import { WrapperStatusEnum } from '../api/generated/portal/WrapperStationResource'; type Props = { @@ -8,9 +9,10 @@ type Props = { }; export const StatusChip = ({ status, size = 'regular' }: Props) => { const { t } = useTranslation(); - const resolvedChip = resolveWrappedStatusToChipObj(status); + const { userIsPagopaOperator } = useUserRole(); + const resolvedChip = resolveWrappedStatusToChipObj(status, userIsPagopaOperator); - return ( + return status ? ( { backgroundColor: resolvedChip.backgroundColor, ...(size === 'small' && { fontSize: '14px', paddingBottom: '1px', height: '24px' }), }} - > - ); + /> + ) : null; }; -const resolveWrappedStatusToChipObj = (status: string) => { +const resolveWrappedStatusToChipObj = (status: string, userIsPagopaOperator: boolean) => { + const label = status + (userIsPagopaOperator ? '_OPERATOR' : ''); switch (status) { case WrapperStatusEnum.APPROVED: return { label: status, color: '#FFFFFF', backgroundColor: 'primary.main' }; case WrapperStatusEnum.TO_FIX: case WrapperStatusEnum.TO_FIX_UPDATE: - return { label: status, color: '#17324D', backgroundColor: 'warning.light' }; + return { + label: status, + color: '#17324D', + backgroundColor: userIsPagopaOperator ? 'grey.200' : 'warning.light', + }; case WrapperStatusEnum.TO_CHECK: case WrapperStatusEnum.TO_CHECK_UPDATE: - return { label: status, color: '#17324D', backgroundColor: 'grey.200' }; + return { + label: status, + color: '#17324D', + backgroundColor: userIsPagopaOperator ? 'warning.light' : 'grey.200', + }; default: - return { label: status, color: '#17324D', backgroundColor: 'grey.200' }; + return { label, color: '#17324D', backgroundColor: 'grey.200' }; } }; diff --git a/src/locale/it.json b/src/locale/it.json index 98d6737cf..5692b0aac 100644 --- a/src/locale/it.json +++ b/src/locale/it.json @@ -595,8 +595,9 @@ "duplicateStation": "Duplica", "editStation": "Modifica", "deleteRequired": "Richiedi eliminazione", - "correctionRequired": "Richiedi correzione", - "configureStation": "Configura" + "configureStation": "Configura", + "requestEdit": "Richiedi modifiche", + "approveAndValidate": "Approva e valida" } }, "stationECList": { @@ -651,8 +652,19 @@ } }, "stationDetailPageValidation": { - "alert": "Stazione in attesa di revisione da parte di un operatore PagoPA.", - "alertToFix": "Stazione in attesa di correzione da parte dell’ente.", + "subtitle": "Ecco i dettagli della stazione inviata in revisione.", + "alert": { + "toCheckMessage": "Verifica le informazioni inserite dall’ente e approva o richiedi modifiche alla stazione.", + "toFixTitle": "Modifiche richieste", + "toFixMessage": "Stazione in attesa di correzione da parte dell’ente." + }, + "modal": { + "title": "Cosa c'è che non va?", + "subtitle": "Il tuo commento sarà condiviso con l'ente", + "placeholder": "Descrivi l'anomalia", + "helperText": "Scrivi massimo 200 caratteri", + "error": "Si è verificato un problema nel salvataggio del commento." + }, "configuration": { "status": "Stato", "title": "Configurazione della stazione", @@ -660,7 +672,11 @@ "registry": "Anagrafica", "stationCode": "Codice stazione", "version": "Versione stazione", - "intermediaryCode": "Codice intermediario", + "connectionType": { + "label":"Tipo di connessione", + "sync": "Sincrona", + "async": "Asincrona" + }, "protocol": "Protocollo", "port": "Porta", "ip": "IP", @@ -1319,6 +1335,7 @@ "manage": "Gestisci", "activate": "Attiva", "deactivate": "Disattiva", + "confirmAndSend": "Conferma e invia", "channels": "canali", "Channels": "Canali", "dashboard": "Panoramica", @@ -1336,7 +1353,12 @@ "TO_FIX": "Da correggere", "TO_FIX_UPDATE": "Da correggere", "TO_CHECK": "In revisione", - "TO_CHECK_UPDATE": "In revisione" + "TO_CHECK_UPDATE": "In revisione", + "APPROVED_OPERATOR": "Attivo", + "TO_FIX_OPERATOR": "Da correggere", + "TO_FIX_UPDATE_OPERATOR": "Da correggere", + "TO_CHECK_OPERATOR": "Da validare", + "TO_CHECK_UPDATE_OPERATOR": "Da validare" }, "yes": "Sì", "no": "No", diff --git a/src/pages/channels/list/__tests__/ChannelsTableColumns.test.tsx b/src/pages/channels/list/__tests__/ChannelsTableColumns.test.tsx index 81d5ee2b5..e1dafeedd 100644 --- a/src/pages/channels/list/__tests__/ChannelsTableColumns.test.tsx +++ b/src/pages/channels/list/__tests__/ChannelsTableColumns.test.tsx @@ -3,6 +3,8 @@ import { cleanup, render } from '@testing-library/react'; import { buildColumnDefs, showStatus } from '../ChannelsTableColumns'; import { showCustomHeader } from '../../../../components/Table/TableUtils'; import React from 'react'; +import { store } from '../../../../redux/store'; +import { Provider } from 'react-redux'; beforeEach(() => { jest.spyOn(console, 'error').mockImplementation(() => {}); @@ -185,6 +187,6 @@ describe('', () => { const realColumns = buildColumnDefs(mockTFunction, () => jest.fn()) as Array; expect(realColumns).toEqual(ArrayBuildColumnDefs); - render(<>{showStatus(params)}); + render({showStatus(params)}); }); }); diff --git a/src/pages/commisionalBundles/addEditCommissionBundle/components/AddEditCommissionBundleForm.tsx b/src/pages/commisionalBundles/addEditCommissionBundle/components/AddEditCommissionBundleForm.tsx index 70439b4d2..b55d07f43 100644 --- a/src/pages/commisionalBundles/addEditCommissionBundle/components/AddEditCommissionBundleForm.tsx +++ b/src/pages/commisionalBundles/addEditCommissionBundle/components/AddEditCommissionBundleForm.tsx @@ -307,7 +307,7 @@ const AddEditCommissionBundleForm = ({isEdit, formik, idBrokerPsp}: Props) => { - + {t('commissionBundlesPage.addEditCommissionBundle.form.paymentType')} ; let spyOnGetTouchpoint: jest.SpyInstance; let spyOnGetInstitutionService: jest.SpyInstance; @@ -30,527 +32,524 @@ let spyOnErrorHook: jest.SpyInstance; let spyOnUseFlagValue: jest.SpyInstance; const TestAddEditCommissionBundleForm = ({ - formAction, - initialValues, - injectedStore, - }: { - formAction: string; - initialValues?: BundleRequest; - injectedStore?: ReturnType; + formAction, + initialValues, + injectedStore, +}: { + formAction: string; + initialValues?: BundleRequest; + injectedStore?: ReturnType; }) => { - const formik = useFormik>({ - initialValues: initialValues ?? {}, - onSubmit: async () => jest.fn(), - enableReinitialize: true, - validateOnBlur: true, - validateOnChange: true, - }); - return ( - - - - - - - - - - ); + const formik = useFormik>({ + initialValues: initialValues ?? {}, + onSubmit: async () => jest.fn(), + enableReinitialize: true, + validateOnBlur: true, + validateOnChange: true, + }); + return ( + + + + + + + + + + ); }; const bundleName = 'bundleName'; const bundleDescription = 'description'; describe('', () => { - beforeEach(() => { - spyOnGetPaymentTypes = jest.spyOn( - require('../../../../../services/configurationService'), - 'getPaymentTypes' - ); - spyOnGetTouchpoint = jest.spyOn( - require('../../../../../services/bundleService'), - 'getTouchpoints' - ); - spyOnGetInstitutionService = jest.spyOn( - require('../../../../../services/institutionService'), - 'getBrokerDelegation' - ); - spyOnCreateCommissionBundle = jest.spyOn( - require('../../../../../services/bundleService'), - 'createBundle' - ); - spyOnGetChannelService = jest.spyOn( - require('../../../../../services/channelService'), - 'getChannelsIdAssociatedToPSP' - ); - spyOnErrorHook = jest - .spyOn(useErrorDispatcher, 'useErrorDispatcher') - .mockReturnValue(jest.fn()); - spyOnUseFlagValue = jest.spyOn(useFeatureFlags, 'useFlagValue'); - jest.mock('../../../../../hooks/useUserRole'); - jest.spyOn(useUserRole, 'useUserRole').mockReturnValue({ - userRole: ROLE.PSP_ADMIN, - userIsPspAdmin: true, - userIsEcAdmin: false, - userIsPspDirectAdmin: false, - userIsPagopaOperator: false, - userIsAdmin: false, - }); - jest.spyOn(console, 'error').mockImplementation(() => { - }); - jest.spyOn(console, 'warn').mockImplementation(() => { - }); + beforeEach(() => { + spyOnGetPaymentTypes = jest.spyOn( + require('../../../../../services/configurationService'), + 'getPaymentTypes' + ); + spyOnGetTouchpoint = jest.spyOn( + require('../../../../../services/bundleService'), + 'getTouchpoints' + ); + spyOnGetInstitutionService = jest.spyOn( + require('../../../../../services/institutionService'), + 'getBrokerDelegation' + ); + spyOnCreateCommissionBundle = jest.spyOn( + require('../../../../../services/bundleService'), + 'createBundle' + ); + spyOnGetChannelService = jest.spyOn( + require('../../../../../services/channelService'), + 'getChannelsIdAssociatedToPSP' + ); + spyOnErrorHook = jest + .spyOn(useErrorDispatcher, 'useErrorDispatcher') + .mockReturnValue(jest.fn()); + spyOnUseFlagValue = jest.spyOn(useFeatureFlags, 'useFlagValue'); + jest.mock('../../../../../hooks/useUserRole'); + jest.spyOn(useUserRole, 'useUserRole').mockReturnValue({ + userRole: ROLE.PSP_ADMIN, + userIsPspAdmin: true, + userIsEcAdmin: false, + userIsPspDirectAdmin: false, + userIsPagopaOperator: false, + userIsAdmin: false, }); + jest.spyOn(console, 'error').mockImplementation(() => {}); + jest.spyOn(console, 'warn').mockImplementation(() => {}); + }); + + afterEach(() => { + cleanup(); + spyOnGetPaymentTypes.mockRestore(); + spyOnGetTouchpoint.mockRestore(); + spyOnGetInstitutionService.mockRestore(); + spyOnCreateCommissionBundle.mockRestore(); + spyOnGetChannelService.mockRestore(); + spyOnErrorHook.mockRestore(); + }); + + const componentRender = ( + formAction: string, + initialValues?: BundleRequest, + injectedStore?: ReturnType + ) => { + render( + + ); + + const input = { + public: screen + .getByTestId('bundle-type-test') + .querySelector(`[value=${TypeEnum.PUBLIC}]`) as HTMLInputElement, + global: screen + .getByTestId('bundle-type-test') + .querySelector(`[value=${TypeEnum.GLOBAL}]`) as HTMLInputElement, + private: screen + .getByTestId('bundle-type-test') + .querySelector(`[value=${TypeEnum.PRIVATE}]`) as HTMLInputElement, + name: screen.getByTestId('name-test') as HTMLInputElement, + description: screen.getByTestId('description-test') as HTMLInputElement, + paymentType: screen.getByTestId('payment-type-test') as HTMLInputElement, + touchpoint: screen.getByTestId('touchpoint-test') as HTMLInputElement, + minImport: screen.getByTestId('min-import-test') as HTMLInputElement, + maxImport: screen.getByTestId('max-import-test') as HTMLInputElement, + feeApplied: screen.getByTestId('payment-amount-test') as HTMLInputElement, + brokerCodeList: screen + .getByTestId('broker-code-test') + .querySelector('input') as HTMLInputElement, + channelList: screen + .getByTestId('channels-id-test') + .querySelector('input') as HTMLInputElement, + digitalStampYes: screen + .getByTestId('digital-stamp-test') + .querySelector('[value="true"]') as HTMLInputElement, + digitalStampNo: screen + .getByTestId('digital-stamp-test') + .querySelector('[value="false"]') as HTMLInputElement, + digitalStampResYes: screen + .getByTestId('digital-stamp-restriction-test') + .querySelector('[value="true"]') as HTMLInputElement, + digitalStampResNo: screen + .getByTestId('digital-stamp-restriction-test') + .querySelector('[value="false"]') as HTMLInputElement, + fromDate: screen.getByTestId('from-date-test') as HTMLInputElement, + ToDate: screen.getByTestId('to-date-test') as HTMLInputElement, + }; - afterEach(() => { - cleanup(); - spyOnGetPaymentTypes.mockRestore(); - spyOnGetTouchpoint.mockRestore(); - spyOnGetInstitutionService.mockRestore(); - spyOnCreateCommissionBundle.mockRestore(); - spyOnGetChannelService.mockRestore(); - spyOnErrorHook.mockRestore(); + return input; + }; + + test('Test AddEditCommissionBundleForm with all input change in CREATE', async () => { + jest.setTimeout(30000); + const injectStore = createStore(); + spyOnUseFlagValue.mockReturnValue(true); + await waitFor(() => + injectStore.dispatch(partiesActions.setPartySelected(pspOperatorSignedDirect)) + ); + const { ...input } = componentRender(FormAction.Create, undefined, injectStore); + await waitFor(() => { + expect(spyOnGetPaymentTypes).toHaveBeenCalled(); + expect(spyOnGetTouchpoint).toHaveBeenCalled(); + expect(spyOnGetInstitutionService).toHaveBeenCalled(); + expect(spyOnGetChannelService).not.toHaveBeenCalled(); }); - const componentRender = ( - formAction: string, - initialValues?: BundleRequest, - injectedStore?: ReturnType - ) => { - render( - - ); - - const input = { - public: screen - .getByTestId('bundle-type-test') - .querySelector(`[value=${TypeEnum.PUBLIC}]`) as HTMLInputElement, - global: screen - .getByTestId('bundle-type-test') - .querySelector(`[value=${TypeEnum.GLOBAL}]`) as HTMLInputElement, - private: screen - .getByTestId('bundle-type-test') - .querySelector(`[value=${TypeEnum.PRIVATE}]`) as HTMLInputElement, - name: screen.getByTestId('name-test') as HTMLInputElement, - description: screen.getByTestId('description-test') as HTMLInputElement, - paymentType: screen.getByTestId('payment-type-test') as HTMLInputElement, - touchpoint: screen.getByTestId('touchpoint-test') as HTMLInputElement, - minImport: screen.getByTestId('min-import-test') as HTMLInputElement, - maxImport: screen.getByTestId('max-import-test') as HTMLInputElement, - feeApplied: screen.getByTestId('payment-amount-test') as HTMLInputElement, - brokerCodeList: screen - .getByTestId('broker-code-test') - .querySelector('input') as HTMLInputElement, - channelList: screen - .getByTestId('channels-id-test') - .querySelector('input') as HTMLInputElement, - digitalStampYes: screen - .getByTestId('digital-stamp-test') - .querySelector('[value="true"]') as HTMLInputElement, - digitalStampNo: screen - .getByTestId('digital-stamp-test') - .querySelector('[value="false"]') as HTMLInputElement, - digitalStampResYes: screen - .getByTestId('digital-stamp-restriction-test') - .querySelector('[value="true"]') as HTMLInputElement, - digitalStampResNo: screen - .getByTestId('digital-stamp-restriction-test') - .querySelector('[value="false"]') as HTMLInputElement, - fromDate: screen.getByTestId('from-date-test') as HTMLInputElement, - ToDate: screen.getByTestId('to-date-test') as HTMLInputElement, - }; - - return input; - }; + //Change radio group bundle type + expect(input.public.checked).toBe(false); + expect(input.global.checked).toBe(false); + expect(input.private.checked).toBe(false); + + fireEvent.click(input.global); + expect(input.public.checked).toBe(false); + expect(input.global.checked).toBe(true); + expect(input.private.checked).toBe(false); + + fireEvent.click(input.public); + expect(input.public.checked).toBe(true); + expect(input.global.checked).toBe(false); + expect(input.private.checked).toBe(false); + + fireEvent.click(input.private); + expect(input.public.checked).toBe(false); + expect(input.global.checked).toBe(false); + expect(input.private.checked).toBe(true); + + // Change input name & description + fireEvent.change(input.name, { target: { value: bundleName } }); + expect(input.name.value).toBe(bundleName); + fireEvent.change(input.description, { target: { value: bundleDescription } }); + expect(input.description.value).toBe(bundleDescription); + + // Change paymentType + fireEvent.mouseDown( + screen.getByLabelText('commissionBundlesPage.addEditCommissionBundle.form.paymentType') + ); + fireEvent.click(screen.getByText(new RegExp('.*Bonifico - SEPA.*', 'i'))); + + expect(input.paymentType).toHaveTextContent('Bonifico - SEPA'); + + // Change touchpoint + fireEvent.mouseDown( + screen.getByLabelText('commissionBundlesPage.addEditCommissionBundle.form.touchpoint') + ); + fireEvent.click(screen.getByText(new RegExp('Tutti', 'i'))); + + expect(input.touchpoint).toHaveTextContent('Tutti'); + + // Change min import number + fireEvent.change(input.minImport, { target: { value: 10 } }); + expect(parseFloat(input.minImport.value)).toBe(10); + // Change max import number + fireEvent.change(input.maxImport, { target: { value: 10 } }); + expect(parseFloat(input.maxImport.value)).toBe(10); + + fireEvent.change(input.feeApplied, { target: { value: '10,8' } }); + expect(input.feeApplied.value).toBe('10,8'); + + fireEvent.change(input.feeApplied, { target: { value: 10.8 } }); + expect(input.feeApplied.value).toBe('10,8'); - test('Test AddEditCommissionBundleForm with all input change in CREATE', async () => { - jest.setTimeout(30000); - const injectStore = createStore(); - spyOnUseFlagValue.mockReturnValue(true); - await waitFor(() => - injectStore.dispatch(partiesActions.setPartySelected(pspOperatorSignedDirect)) - ); - const {...input} = componentRender(FormAction.Create, undefined, injectStore); - await waitFor(() => { - expect(spyOnGetPaymentTypes).toHaveBeenCalled(); - expect(spyOnGetTouchpoint).toHaveBeenCalled(); - expect(spyOnGetInstitutionService).toHaveBeenCalled(); - expect(spyOnGetChannelService).not.toHaveBeenCalled(); - }); - - //Change radio group bundle type - expect(input.public.checked).toBe(false); - expect(input.global.checked).toBe(false); - expect(input.private.checked).toBe(false); - - fireEvent.click(input.global); - expect(input.public.checked).toBe(false); - expect(input.global.checked).toBe(true); - expect(input.private.checked).toBe(false); - - fireEvent.click(input.public); - expect(input.public.checked).toBe(true); - expect(input.global.checked).toBe(false); - expect(input.private.checked).toBe(false); - - fireEvent.click(input.private); - expect(input.public.checked).toBe(false); - expect(input.global.checked).toBe(false); - expect(input.private.checked).toBe(true); - - // Change input name & description - fireEvent.change(input.name, {target: {value: bundleName}}); - expect(input.name.value).toBe(bundleName); - fireEvent.change(input.description, {target: {value: bundleDescription}}); - expect(input.description.value).toBe(bundleDescription); - - // Change paymentType - const selectPaymentTypeBtn = await within(input.paymentType).getByRole('button'); - await waitFor(() => { - fireEvent.mouseDown(selectPaymentTypeBtn); - screen.getByText(new RegExp('.*Bonifico - SEPA.*', 'i')); - fireEvent.click(screen.getByText(new RegExp('.*Bonifico - SEPA.*', 'i'))); - }); - expect(selectPaymentTypeBtn.textContent).toBe('Bonifico - SEPA'); - - // Change touchpoint - const selectTouchPointBtn = await within(input.touchpoint).getByRole('button'); - await waitFor(() => { - fireEvent.mouseDown(selectTouchPointBtn); - screen.getByText(new RegExp('Tutti', 'i')); - fireEvent.click(screen.getByText(new RegExp('Tutti', 'i'))); - }); - expect(selectTouchPointBtn.textContent).toBe('Tutti'); - - // Change min import number - fireEvent.change(input.minImport, {target: {value: 10}}); - expect(parseFloat(input.minImport.value)).toBe(10); - // Change max import number - fireEvent.change(input.maxImport, {target: {value: 10}}); - expect(parseFloat(input.maxImport.value)).toBe(10); - - fireEvent.change(input.feeApplied, {target: {value: '10,8'}}); - expect(input.feeApplied.value).toBe('10,8'); - - fireEvent.change(input.feeApplied, {target: {value: 10.8}}); - expect(input.feeApplied.value).toBe('10,8'); - - // Change broker code list - expect(input.channelList.disabled).toBe(true); - fireEvent.change(input.brokerCodeList, { - target: {value: mockedDelegatedPSP[1].institution_name}, - }); - input.brokerCodeList.focus(); - - fireEvent.change(document.activeElement as Element, { - target: {value: mockedDelegatedPSP[1].institution_name}, - }); - fireEvent.keyDown(document.activeElement as Element, {key: 'ArrowDown'}); - fireEvent.keyDown(document.activeElement as Element, {key: 'Enter'}); - expect(input.brokerCodeList.value).toEqual(mockedDelegatedPSP[1].institution_name); - await waitFor(() => { - expect(spyOnGetChannelService).toBeCalledTimes(1); - expect(input.channelList.disabled).toBe(false); - }); - - fireEvent.change(document.activeElement as Element, { - target: {value: ''}, - }); - fireEvent.keyDown(document.activeElement as Element, {key: 'ArrowDown'}); - fireEvent.keyDown(document.activeElement as Element, {key: 'Enter'}); - await waitFor(() => { - expect(input.channelList.disabled).toBe(true); - }); - - // Change channel id - fireEvent.mouseDown(input.channelList); - fireEvent.select(input.channelList, {target: {value: mockedChannelsIdList[0]}}); - expect(input.channelList.value).toBe(mockedChannelsIdList[0]); - - //Change radio buttons digitalStamp - expect(input.digitalStampYes.checked).toBe(false); - expect(input.digitalStampNo.checked).toBe(true); - expect(input.digitalStampResYes.disabled).toBe(false); - - fireEvent.click(input.digitalStampYes); - expect(input.digitalStampYes.checked).toBe(true); - expect(input.digitalStampNo.checked).toBe(false); - expect(input.digitalStampResYes.disabled).toBe(true); - - fireEvent.click(input.digitalStampNo); - expect(input.digitalStampYes.checked).toBe(false); - expect(input.digitalStampNo.checked).toBe(true); - expect(input.digitalStampResYes.disabled).toBe(false); - - //Change radio buttons digitalStampRes - expect(input.digitalStampResYes.checked).toBe(false); - expect(input.digitalStampResNo.checked).toBe(true); - expect(input.digitalStampYes.disabled).toBe(false); - - fireEvent.click(input.digitalStampResYes); - expect(input.digitalStampResYes.checked).toBe(true); - expect(input.digitalStampResNo.checked).toBe(false); - expect(input.digitalStampYes.disabled).toBe(true); - - fireEvent.click(input.digitalStampResNo); - expect(input.digitalStampResYes.checked).toBe(false); - expect(input.digitalStampResNo.checked).toBe(true); - expect(input.digitalStampYes.disabled).toBe(false); - - // Change dates - const formatDate = (date: Date) => { - const day = date.getDate().toString().padStart(2, '0'); - const month = (date.getMonth() + 1).toString().padStart(2, '0'); - const year = date.getFullYear(); - return `${day}/${month}/${year}`; - }; - - const fromDate = new Date(2028, 9, 27); - const toDate = new Date(2028, 9, 28); - - fireEvent.change(input.fromDate, {target: {value: formatDate(fromDate)}}); - expect(input.fromDate.value).toBe('27/10/2028'); - - fireEvent.change(input.ToDate, {target: {value: formatDate(toDate)}}); - expect(input.ToDate.value).toBe('28/10/2028'); + // Change broker code list + expect(input.channelList.disabled).toBe(true); + fireEvent.change(input.brokerCodeList, { + target: { value: mockedDelegatedPSP[1].institution_name }, }); + input.brokerCodeList.focus(); + + fireEvent.change(document.activeElement as Element, { + target: { value: mockedDelegatedPSP[1].institution_name }, + }); + fireEvent.keyDown(document.activeElement as Element, { key: 'ArrowDown' }); + fireEvent.keyDown(document.activeElement as Element, { key: 'Enter' }); + expect(input.brokerCodeList.value).toEqual(mockedDelegatedPSP[1].institution_name); + await waitFor(() => { + expect(spyOnGetChannelService).toBeCalledTimes(1); + expect(input.channelList.disabled).toBe(false); + }); + + fireEvent.change(document.activeElement as Element, { + target: { value: '' }, + }); + fireEvent.keyDown(document.activeElement as Element, { key: 'ArrowDown' }); + fireEvent.keyDown(document.activeElement as Element, { key: 'Enter' }); + await waitFor(() => { + expect(input.channelList.disabled).toBe(true); + }); + + // Change channel id + fireEvent.mouseDown(input.channelList); + fireEvent.select(input.channelList, { target: { value: mockedChannelsIdList[0] } }); + expect(input.channelList.value).toBe(mockedChannelsIdList[0]); + + //Change radio buttons digitalStamp + expect(input.digitalStampYes.checked).toBe(false); + expect(input.digitalStampNo.checked).toBe(true); + expect(input.digitalStampResYes.disabled).toBe(false); + + fireEvent.click(input.digitalStampYes); + expect(input.digitalStampYes.checked).toBe(true); + expect(input.digitalStampNo.checked).toBe(false); + expect(input.digitalStampResYes.disabled).toBe(true); + + fireEvent.click(input.digitalStampNo); + expect(input.digitalStampYes.checked).toBe(false); + expect(input.digitalStampNo.checked).toBe(true); + expect(input.digitalStampResYes.disabled).toBe(false); + + //Change radio buttons digitalStampRes + expect(input.digitalStampResYes.checked).toBe(false); + expect(input.digitalStampResNo.checked).toBe(true); + expect(input.digitalStampYes.disabled).toBe(false); + + fireEvent.click(input.digitalStampResYes); + expect(input.digitalStampResYes.checked).toBe(true); + expect(input.digitalStampResNo.checked).toBe(false); + expect(input.digitalStampYes.disabled).toBe(true); + + fireEvent.click(input.digitalStampResNo); + expect(input.digitalStampResYes.checked).toBe(false); + expect(input.digitalStampResNo.checked).toBe(true); + expect(input.digitalStampYes.disabled).toBe(false); + + // Change dates + const formatDate = (date: Date) => { + const day = date.getDate().toString().padStart(2, '0'); + const month = (date.getMonth() + 1).toString().padStart(2, '0'); + const year = date.getFullYear(); + return `${day}/${month}/${year}`; + }; - test('Test AddEditCommissionBundleForm with all input change in EDIT', async () => { - const injectStore = createStore(); - await waitFor(() => - injectStore.dispatch(partiesActions.setPartySelected(pspOperatorSignedDirect)) - ); - const {...input} = componentRender(FormAction.Edit, mockedBundleRequest, injectStore); - await waitFor(() => { - expect(spyOnGetPaymentTypes).toHaveBeenCalled(); - expect(spyOnGetTouchpoint).toHaveBeenCalled(); - expect(spyOnGetInstitutionService).toHaveBeenCalled(); - expect(spyOnGetChannelService).toHaveBeenCalled(); - }); - - //Check radio group bundle type - expect(input.public.disabled).toBe(true); - expect(input.global.disabled).toBe(true); - expect(input.private.disabled).toBe(true); - - expect(input.public.checked).toBe(false); - expect(input.global.checked).toBe(true); - expect(input.private.checked).toBe(false); - - // Check input name & description - expect(input.name.value).toBe(mockedBundleRequest.name); - expect(input.description.value).toBe(mockedBundleRequest.description); - - // Check paymentType - //TODO FIX DEFAULT LIST - // const selectPaymentTypeBtn = await within(input.paymentType).getByRole('button'); - // expect(selectPaymentTypeBtn.textContent).toBe(mockedBundleRequest.paymentType); - - // Check touchpoint - //TODO FIX DEFAULT LIST - // const selectTouchPointBtn = await within(input.touchpoint).getByRole('button'); - // expect(selectTouchPointBtn.textContent).toBe(mockedBundleRequest.paymentType); - - // Check min import number - expect(input.minImport.value).toBe( - (mockedBundleRequest.minPaymentAmount! / 100)?.toString().replace('.', ',') - ); - // Check max import number - expect(input.maxImport.value).toBe( - (mockedBundleRequest.maxPaymentAmount! / 100)?.toString().replace('.', ',') - ); - - expect(input.feeApplied.value).toBe( - (mockedBundleRequest.paymentAmount! / 100)?.toString().replace('.', ',') - ); - - // Check broker code list - expect(input.brokerCodeList.value).toBe(mockedDelegatedPSP.find(el => el.broker_id === mockedBundleRequest.idBrokerPsp)?.institution_name); - - // Check channel id - expect(input.channelList.value).toBe(mockedBundleRequest.idChannel); - - //Check radio buttons digitalStamp - expect(input.digitalStampYes.checked).toBe(false); - expect(input.digitalStampNo.checked).toBe(true); - - expect(input.digitalStampYes.disabled).toBe(true); - - //Check radio buttons digitalStampRes - expect(input.digitalStampResYes.checked).toBe(true); - expect(input.digitalStampResNo.checked).toBe(false); - - expect(input.digitalStampResYes.disabled).toBe(false); - - fireEvent.click(input.digitalStampResYes); - expect(input.digitalStampResYes.checked).toBe(true); - expect(input.digitalStampResNo.checked).toBe(false); - expect(input.digitalStampYes.disabled).toBe(true); - - // Check dates - expect(input.fromDate.disabled).toBe(true); - expect(input.fromDate.value).toBe(formatDateToDDMMYYYY(mockedBundleRequest.validityDateFrom)); - - expect(input.ToDate.value).toBe(formatDateToDDMMYYYY(mockedBundleRequest.validityDateTo)); + const fromDate = new Date(2028, 9, 27); + const toDate = new Date(2028, 9, 28); + + fireEvent.change(input.fromDate, { target: { value: formatDate(fromDate) } }); + expect(input.fromDate.value).toBe('27/10/2028'); + + fireEvent.change(input.ToDate, { target: { value: formatDate(toDate) } }); + expect(input.ToDate.value).toBe('28/10/2028'); + }); + + test('Test AddEditCommissionBundleForm with all input change in EDIT', async () => { + const injectStore = createStore(); + await waitFor(() => + injectStore.dispatch(partiesActions.setPartySelected(pspOperatorSignedDirect)) + ); + const { ...input } = componentRender(FormAction.Edit, mockedBundleRequest, injectStore); + await waitFor(() => { + expect(spyOnGetPaymentTypes).toHaveBeenCalled(); + expect(spyOnGetTouchpoint).toHaveBeenCalled(); + expect(spyOnGetInstitutionService).toHaveBeenCalled(); + expect(spyOnGetChannelService).toHaveBeenCalled(); }); - test('Test AddEditCommissionBundleForm feature flag only global types', async () => { - const injectStore = createStore(); - spyOnUseFlagValue.mockReturnValue(false); - await waitFor(() => - injectStore.dispatch(partiesActions.setPartySelected(pspOperatorSignedDirect)) - ); - const {...input} = componentRender(FormAction.Create, undefined, injectStore); - await waitFor(() => { - expect(spyOnGetPaymentTypes).toHaveBeenCalled(); - expect(spyOnGetTouchpoint).toHaveBeenCalled(); - expect(spyOnGetInstitutionService).toHaveBeenCalled(); - expect(spyOnGetChannelService).not.toHaveBeenCalled(); - }); - - //Check radio group bundle type - expect(input.public.disabled).toBe(true); - expect(input.global.disabled).toBe(false); - expect(input.private.disabled).toBe(true); - - expect(input.public.checked).toBe(false); - expect(input.global.checked).toBe(false); - expect(input.private.checked).toBe(false); + //Check radio group bundle type + expect(input.public.disabled).toBe(true); + expect(input.global.disabled).toBe(true); + expect(input.private.disabled).toBe(true); + + expect(input.public.checked).toBe(false); + expect(input.global.checked).toBe(true); + expect(input.private.checked).toBe(false); + + // Check input name & description + expect(input.name.value).toBe(mockedBundleRequest.name); + expect(input.description.value).toBe(mockedBundleRequest.description); + + // Check paymentType + //TODO FIX DEFAULT LIST + // const selectPaymentTypeBtn = await within(input.paymentType).getByRole('button'); + // expect(selectPaymentTypeBtn.textContent).toBe(mockedBundleRequest.paymentType); + + // Check touchpoint + //TODO FIX DEFAULT LIST + // const selectTouchPointBtn = await within(input.touchpoint).getByRole('button'); + // expect(selectTouchPointBtn.textContent).toBe(mockedBundleRequest.paymentType); + + // Check min import number + expect(input.minImport.value).toBe( + (mockedBundleRequest.minPaymentAmount! / 100)?.toString().replace('.', ',') + ); + // Check max import number + expect(input.maxImport.value).toBe( + (mockedBundleRequest.maxPaymentAmount! / 100)?.toString().replace('.', ',') + ); + + expect(input.feeApplied.value).toBe( + (mockedBundleRequest.paymentAmount! / 100)?.toString().replace('.', ',') + ); + + // Check broker code list + expect(input.brokerCodeList.value).toBe( + mockedDelegatedPSP.find((el) => el.broker_id === mockedBundleRequest.idBrokerPsp) + ?.institution_name + ); + + // Check channel id + expect(input.channelList.value).toBe(mockedBundleRequest.idChannel); + + //Check radio buttons digitalStamp + expect(input.digitalStampYes.checked).toBe(false); + expect(input.digitalStampNo.checked).toBe(true); + + expect(input.digitalStampYes.disabled).toBe(true); + + //Check radio buttons digitalStampRes + expect(input.digitalStampResYes.checked).toBe(true); + expect(input.digitalStampResNo.checked).toBe(false); + + expect(input.digitalStampResYes.disabled).toBe(false); + + fireEvent.click(input.digitalStampResYes); + expect(input.digitalStampResYes.checked).toBe(true); + expect(input.digitalStampResNo.checked).toBe(false); + expect(input.digitalStampYes.disabled).toBe(true); + + // Check dates + expect(input.fromDate.disabled).toBe(true); + expect(input.fromDate.value).toBe(formatDateToDDMMYYYY(mockedBundleRequest.validityDateFrom)); + + expect(input.ToDate.value).toBe(formatDateToDDMMYYYY(mockedBundleRequest.validityDateTo)); + }); + + test('Test AddEditCommissionBundleForm feature flag only global types', async () => { + const injectStore = createStore(); + spyOnUseFlagValue.mockReturnValue(false); + await waitFor(() => + injectStore.dispatch(partiesActions.setPartySelected(pspOperatorSignedDirect)) + ); + const { ...input } = componentRender(FormAction.Create, undefined, injectStore); + await waitFor(() => { + expect(spyOnGetPaymentTypes).toHaveBeenCalled(); + expect(spyOnGetTouchpoint).toHaveBeenCalled(); + expect(spyOnGetInstitutionService).toHaveBeenCalled(); + expect(spyOnGetChannelService).not.toHaveBeenCalled(); }); - test('Test AddEditCommissionBundleForm feature flag only global & private types', async () => { - const injectStore = createStore(); - spyOnUseFlagValue.mockImplementation((arg) => arg === "commission-bundles-private"); - await waitFor(() => - injectStore.dispatch(partiesActions.setPartySelected(pspOperatorSignedDirect)) - ); - const {...input} = componentRender(FormAction.Create, undefined, injectStore); - await waitFor(() => { - expect(spyOnGetPaymentTypes).toHaveBeenCalled(); - expect(spyOnGetTouchpoint).toHaveBeenCalled(); - expect(spyOnGetInstitutionService).toHaveBeenCalled(); - expect(spyOnGetChannelService).not.toHaveBeenCalled(); - }); - - - //Check radio group bundle type - expect(input.public.disabled).toBe(true); - expect(input.global.disabled).toBe(false); - expect(input.private.disabled).toBe(false); - - expect(input.public.checked).toBe(false); - expect(input.global.checked).toBe(false); - expect(input.private.checked).toBe(false); + //Check radio group bundle type + expect(input.public.disabled).toBe(true); + expect(input.global.disabled).toBe(false); + expect(input.private.disabled).toBe(true); + + expect(input.public.checked).toBe(false); + expect(input.global.checked).toBe(false); + expect(input.private.checked).toBe(false); + }); + + test('Test AddEditCommissionBundleForm feature flag only global & private types', async () => { + const injectStore = createStore(); + spyOnUseFlagValue.mockImplementation((arg) => arg === 'commission-bundles-private'); + await waitFor(() => + injectStore.dispatch(partiesActions.setPartySelected(pspOperatorSignedDirect)) + ); + const { ...input } = componentRender(FormAction.Create, undefined, injectStore); + await waitFor(() => { + expect(spyOnGetPaymentTypes).toHaveBeenCalled(); + expect(spyOnGetTouchpoint).toHaveBeenCalled(); + expect(spyOnGetInstitutionService).toHaveBeenCalled(); + expect(spyOnGetChannelService).not.toHaveBeenCalled(); }); - test('Test AddEditCommissionBundleForm feature flag only global & public types', async () => { - const injectStore = createStore(); - spyOnUseFlagValue.mockImplementation((arg) => arg === "commission-bundles-public"); - await waitFor(() => - injectStore.dispatch(partiesActions.setPartySelected(pspOperatorSignedDirect)) - ); - const {...input} = componentRender(FormAction.Create, undefined, injectStore); - await waitFor(() => { - expect(spyOnGetPaymentTypes).toHaveBeenCalled(); - expect(spyOnGetTouchpoint).toHaveBeenCalled(); - expect(spyOnGetInstitutionService).toHaveBeenCalled(); - expect(spyOnGetChannelService).not.toHaveBeenCalled(); - }); - - - //Check radio group bundle type - expect(input.public.disabled).toBe(false); - expect(input.global.disabled).toBe(false); - expect(input.private.disabled).toBe(true); - - expect(input.public.checked).toBe(false); - expect(input.global.checked).toBe(false); - expect(input.private.checked).toBe(false); + //Check radio group bundle type + expect(input.public.disabled).toBe(true); + expect(input.global.disabled).toBe(false); + expect(input.private.disabled).toBe(false); + + expect(input.public.checked).toBe(false); + expect(input.global.checked).toBe(false); + expect(input.private.checked).toBe(false); + }); + + test('Test AddEditCommissionBundleForm feature flag only global & public types', async () => { + const injectStore = createStore(); + spyOnUseFlagValue.mockImplementation((arg) => arg === 'commission-bundles-public'); + await waitFor(() => + injectStore.dispatch(partiesActions.setPartySelected(pspOperatorSignedDirect)) + ); + const { ...input } = componentRender(FormAction.Create, undefined, injectStore); + await waitFor(() => { + expect(spyOnGetPaymentTypes).toHaveBeenCalled(); + expect(spyOnGetTouchpoint).toHaveBeenCalled(); + expect(spyOnGetInstitutionService).toHaveBeenCalled(); + expect(spyOnGetChannelService).not.toHaveBeenCalled(); }); - test('Test fetch error getPaymentTypes', async () => { - const mockError = new Error('API error message getPaymentTypes'); - spyOnGetPaymentTypes.mockRejectedValue(mockError); + //Check radio group bundle type + expect(input.public.disabled).toBe(false); + expect(input.global.disabled).toBe(false); + expect(input.private.disabled).toBe(true); + + expect(input.public.checked).toBe(false); + expect(input.global.checked).toBe(false); + expect(input.private.checked).toBe(false); + }); - componentRender(FormAction.Create); + test('Test fetch error getPaymentTypes', async () => { + const mockError = new Error('API error message getPaymentTypes'); + spyOnGetPaymentTypes.mockRejectedValue(mockError); - await waitFor(() => { - expect(spyOnGetPaymentTypes).toHaveBeenCalled(); - expect(spyOnErrorHook).toHaveBeenCalled(); - }); + componentRender(FormAction.Create); + + await waitFor(() => { + expect(spyOnGetPaymentTypes).toHaveBeenCalled(); + expect(spyOnErrorHook).toHaveBeenCalled(); }); + }); - test('Test fetch error getTouchpoint', async () => { - const mockError = new Error('API error message GetTouchpoint'); - spyOnGetTouchpoint.mockRejectedValue(mockError); + test('Test fetch error getTouchpoint', async () => { + const mockError = new Error('API error message GetTouchpoint'); + spyOnGetTouchpoint.mockRejectedValue(mockError); - componentRender(FormAction.Create); + componentRender(FormAction.Create); - await waitFor(() => { - expect(spyOnGetTouchpoint).toHaveBeenCalled(); - expect(spyOnErrorHook).toHaveBeenCalled(); - }); + await waitFor(() => { + expect(spyOnGetTouchpoint).toHaveBeenCalled(); + expect(spyOnErrorHook).toHaveBeenCalled(); }); + }); - test('Test fetch error getBrokerDelegation', async () => { - const mockError = new Error('API error message getBrokerDelegation'); - spyOnGetInstitutionService.mockRejectedValue(mockError); + test('Test fetch error getBrokerDelegation', async () => { + const mockError = new Error('API error message getBrokerDelegation'); + spyOnGetInstitutionService.mockRejectedValue(mockError); - componentRender(FormAction.Create); + componentRender(FormAction.Create); - await waitFor(() => { - expect(spyOnGetInstitutionService).toHaveBeenCalled(); - expect(spyOnErrorHook).toHaveBeenCalled(); - expect(spyOnGetChannelService).not.toHaveBeenCalled(); - }); + await waitFor(() => { + expect(spyOnGetInstitutionService).toHaveBeenCalled(); + expect(spyOnErrorHook).toHaveBeenCalled(); + expect(spyOnGetChannelService).not.toHaveBeenCalled(); }); + }); - test('Test fetch getBrokerDelegation empty list', async () => { - spyOnGetInstitutionService.mockReturnValue(new Promise((resolve) => resolve([]))); + test('Test fetch getBrokerDelegation empty list', async () => { + spyOnGetInstitutionService.mockReturnValue(new Promise((resolve) => resolve([]))); - componentRender(FormAction.Create); + componentRender(FormAction.Create); - await waitFor(() => { - expect(spyOnGetInstitutionService).toHaveBeenCalled(); - expect(spyOnErrorHook).toHaveBeenCalled(); - expect(spyOnGetChannelService).not.toHaveBeenCalled(); - }); + await waitFor(() => { + expect(spyOnGetInstitutionService).toHaveBeenCalled(); + expect(spyOnErrorHook).toHaveBeenCalled(); + expect(spyOnGetChannelService).not.toHaveBeenCalled(); }); + }); + + test('Test fetch getChannels empty list', async () => { + spyOnGetChannelService.mockReturnValue(new Promise((resolve) => resolve([]))); + const injectStore = createStore(); + await waitFor(() => + injectStore.dispatch(partiesActions.setPartySelected(pspOperatorSignedDirect)) + ); + componentRender(FormAction.Edit, mockedBundleRequest, injectStore); - test('Test fetch getChannels empty list', async () => { - spyOnGetChannelService.mockReturnValue(new Promise((resolve) => resolve([]))); - const injectStore = createStore(); - await waitFor(() => - injectStore.dispatch(partiesActions.setPartySelected(pspOperatorSignedDirect)) - ); - componentRender(FormAction.Edit, mockedBundleRequest, injectStore); - - await waitFor(() => { - expect(spyOnGetChannelService).toHaveBeenCalled(); - expect(spyOnErrorHook).toHaveBeenCalled(); - }); + await waitFor(() => { + expect(spyOnGetChannelService).toHaveBeenCalled(); + expect(spyOnErrorHook).toHaveBeenCalled(); }); + }); + + test('Test fetch getChannels throw error', async () => { + const mockError = new Error('API error message getChannels'); + spyOnGetChannelService.mockRejectedValue(mockError); + const injectStore = createStore(); + await waitFor(() => + injectStore.dispatch(partiesActions.setPartySelected(pspOperatorSignedDirect)) + ); + componentRender(FormAction.Edit, mockedBundleRequest, injectStore); - test('Test fetch getChannels throw error', async () => { - const mockError = new Error('API error message getChannels'); - spyOnGetChannelService.mockRejectedValue(mockError); - const injectStore = createStore(); - await waitFor(() => - injectStore.dispatch(partiesActions.setPartySelected(pspOperatorSignedDirect)) - ); - componentRender(FormAction.Edit, mockedBundleRequest, injectStore); - - await waitFor(() => { - expect(spyOnErrorHook).toHaveBeenCalled(); - expect(spyOnGetChannelService).toHaveBeenCalled(); - }); + await waitFor(() => { + expect(spyOnErrorHook).toHaveBeenCalled(); + expect(spyOnGetChannelService).toHaveBeenCalled(); }); + }); }); diff --git a/src/pages/commisionalBundles/detail/components/CommissionBundleDetailConfiguration.tsx b/src/pages/commisionalBundles/detail/components/CommissionBundleDetailConfiguration.tsx index 63b3d3f18..38292f5e2 100644 --- a/src/pages/commisionalBundles/detail/components/CommissionBundleDetailConfiguration.tsx +++ b/src/pages/commisionalBundles/detail/components/CommissionBundleDetailConfiguration.tsx @@ -36,8 +36,7 @@ const bundleConfigurationFields = { ['validityDateFrom', 'commissionBundlesPage.list.headerFields.startDate'], ['validityDateTo', 'commissionBundlesPage.list.headerFields.endDate'], ['lastUpdatedDate', 'commissionBundlesPage.commissionBundleDetail.lastChange'], - ], - // TODO updatedBy/"Modificato da" (API doesn't retrieve this info) + ] }; const formatConfigValues = (value: any, t: TFunction<'translation'>) => { if (typeof value === 'string' && value) { diff --git a/src/pages/commisionalBundles/detail/components/subscriptions/__tests__/CommissionBundleSubscriptionsTable.test.tsx b/src/pages/commisionalBundles/detail/components/subscriptions/__tests__/CommissionBundleSubscriptionsTable.test.tsx index 4d7918c57..245c66e3b 100644 --- a/src/pages/commisionalBundles/detail/components/subscriptions/__tests__/CommissionBundleSubscriptionsTable.test.tsx +++ b/src/pages/commisionalBundles/detail/components/subscriptions/__tests__/CommissionBundleSubscriptionsTable.test.tsx @@ -49,10 +49,8 @@ describe('', () => { const selectSubscriptionStateFilter = screen.getByTestId( 'subscription-state' ) as HTMLInputElement; - const selectSubscriptionStateFilterBtn = await within(selectSubscriptionStateFilter).getByRole( - 'button' - ); - expect(selectSubscriptionStateFilterBtn.textContent).toBe( + const selectSubscriptionStateFilterBtn = screen.getByLabelText(`${componentPath}.state`); + expect(selectSubscriptionStateFilter).toHaveTextContent( `${componentPath}.stateChip.${SubscriptionStateType.Waiting}` ); @@ -104,9 +102,9 @@ describe('', () => { await waitFor(() => { expect(screen.queryByTestId('empty-state-table')).not.toBeInTheDocument(); expect(screen.queryByTestId('data-grid')).toBeInTheDocument(); - }) + }); - spyOnGetPublicBundleCISubscriptionsDetail.mockRejectedValueOnce(""); + spyOnGetPublicBundleCISubscriptionsDetail.mockRejectedValueOnce(''); const subscriptionDetailButton = screen.getByTestId('subscription-detail-button'); fireEvent.click(subscriptionDetailButton); @@ -116,8 +114,7 @@ describe('', () => { expect(screen.queryByTestId('subscription-delete-button')).not.toBeInTheDocument(); expect(screen.queryByTestId('subscription-reject-button')).not.toBeInTheDocument(); }); - }) - + }); }); test('render component CommissionBundleSubscriptionsTable and test delete accepted subscriptions', async () => { @@ -134,12 +131,7 @@ describe('', () => { ); - const selectSubscriptionStateFilter = screen.getByTestId( - 'subscription-state' - ) as HTMLInputElement; - const selectSubscriptionStateFilterBtn = await within(selectSubscriptionStateFilter).getByRole( - 'button' - ); + const selectSubscriptionStateFilterBtn = screen.getByLabelText(`${componentPath}.state`); await waitFor(() => { fireEvent.mouseDown(selectSubscriptionStateFilterBtn); fireEvent.click( @@ -175,25 +167,24 @@ describe('', () => { expect(screen.queryByTestId('subscription-reject-button')).not.toBeInTheDocument(); expect(screen.queryByTestId('subscription-accept-button')).not.toBeInTheDocument(); }); - + fireEvent.click(deleteButton); - + await waitFor(() => { expect(screen.getByTestId('fade-test')).toBeInTheDocument(); }); - + const modalConfirmButton = screen.getByTestId('confirm-button-test'); spyOnDeleteSubscription.mockReturnValue(Promise.resolve()); fireEvent.click(modalConfirmButton); - + await waitFor(() => { expect(spyOnDeleteSubscription).toBeCalled(); expect(spyOnGetPublicBundleCISubscriptions).toBeCalledTimes(3); }); - expect(screen.getByTestId("success-alert")).toBeInTheDocument(); - }) - + expect(screen.getByTestId('success-alert')).toBeInTheDocument(); + }); }); test('render component CommissionBundleSubscriptionsTable and test reject waiting requests', async () => { @@ -213,7 +204,7 @@ describe('', () => { await waitFor(() => { expect(screen.queryByTestId('empty-state-table')).not.toBeInTheDocument(); expect(screen.queryByTestId('data-grid')).toBeInTheDocument(); - }) + }); spyOnGetPublicBundleCISubscriptionsDetail.mockReturnValue( Promise.resolve(mockedCiSubscriptionDetail) @@ -228,25 +219,24 @@ describe('', () => { expect(screen.queryByTestId('subscription-delete-button')).not.toBeInTheDocument(); expect(screen.queryByTestId('subscription-accept-button')).toBeInTheDocument(); }); - + fireEvent.click(rejectButton); - + await waitFor(() => { expect(screen.getByTestId('fade-test')).toBeInTheDocument(); }); - + const modalConfirmButton = screen.getByTestId('confirm-button-test'); spyOnRejectSubcriptionRequest.mockReturnValue(Promise.resolve()); fireEvent.click(modalConfirmButton); - + await waitFor(() => { expect(spyOnRejectSubcriptionRequest).toBeCalled(); expect(spyOnGetPublicBundleCISubscriptions).toBeCalledTimes(2); }); - expect(screen.getByTestId("success-alert")).toBeInTheDocument(); - }) - + expect(screen.getByTestId('success-alert')).toBeInTheDocument(); + }); }); test('render component CommissionBundleSubscriptionsTable and test accept waiting requests', async () => { @@ -266,7 +256,7 @@ describe('', () => { await waitFor(() => { expect(screen.queryByTestId('empty-state-table')).not.toBeInTheDocument(); expect(screen.queryByTestId('data-grid')).toBeInTheDocument(); - }) + }); spyOnGetPublicBundleCISubscriptionsDetail.mockReturnValue( Promise.resolve(mockedCiSubscriptionDetail) @@ -281,25 +271,24 @@ describe('', () => { expect(screen.queryByTestId('subscription-delete-button')).not.toBeInTheDocument(); expect(screen.queryByTestId('subscription-reject-button')).toBeInTheDocument(); }); - + fireEvent.click(acceptButton); - + await waitFor(() => { expect(screen.getByTestId('fade-test')).toBeInTheDocument(); }); - + const modalConfirmButton = screen.getByTestId('confirm-button-test'); spyOnAcceptSubcriptionRequest.mockReturnValue(Promise.resolve()); fireEvent.click(modalConfirmButton); - + await waitFor(() => { expect(spyOnAcceptSubcriptionRequest).toBeCalled(); expect(spyOnGetPublicBundleCISubscriptions).toBeCalledTimes(2); }); - expect(screen.getByTestId("success-alert")).toBeInTheDocument(); - }) - + expect(screen.getByTestId('success-alert')).toBeInTheDocument(); + }); }); test('render component CommissionBundleSubscriptionsTable and test error action on waiting requests', async () => { @@ -319,7 +308,7 @@ describe('', () => { await waitFor(() => { expect(screen.queryByTestId('empty-state-table')).not.toBeInTheDocument(); expect(screen.queryByTestId('data-grid')).toBeInTheDocument(); - }) + }); spyOnGetPublicBundleCISubscriptionsDetail.mockReturnValue( Promise.resolve(mockedCiSubscriptionDetail) @@ -334,29 +323,28 @@ describe('', () => { expect(screen.queryByTestId('subscription-delete-button')).not.toBeInTheDocument(); expect(screen.queryByTestId('subscription-reject-button')).toBeInTheDocument(); }); - + fireEvent.click(acceptButton); - + await waitFor(() => { expect(screen.getByTestId('fade-test')).toBeInTheDocument(); }); - + const modalConfirmButton = screen.getByTestId('confirm-button-test'); - spyOnAcceptSubcriptionRequest.mockRejectedValue("error"); + spyOnAcceptSubcriptionRequest.mockRejectedValue('error'); fireEvent.click(modalConfirmButton); - + await waitFor(() => { expect(spyOnAcceptSubcriptionRequest).toBeCalled(); expect(spyOnGetPublicBundleCISubscriptions).toBeCalledTimes(1); }); - expect(screen.queryByTestId("success-alert")).not.toBeInTheDocument(); - }) - + expect(screen.queryByTestId('success-alert')).not.toBeInTheDocument(); + }); }); test('render component CommissionBundleSubscriptionsTable and test error on retrieve subscription list', async () => { - spyOnGetPublicBundleCISubscriptions.mockRejectedValue("error"); + spyOnGetPublicBundleCISubscriptions.mockRejectedValue('error'); render( @@ -372,5 +360,5 @@ describe('', () => { expect(spyOnGetPublicBundleCISubscriptions).toBeCalledTimes(1); expect(screen.queryByTestId('empty-state-table')).toBeInTheDocument(); expect(screen.queryByTestId('data-grid')).not.toBeInTheDocument(); - }) + }); }); diff --git a/src/pages/dashboard/nodeSignIn/components/CommonRadioGroup.tsx b/src/pages/dashboard/nodeSignIn/components/CommonRadioGroup.tsx index 93ba5aab7..afb0b0804 100644 --- a/src/pages/dashboard/nodeSignIn/components/CommonRadioGroup.tsx +++ b/src/pages/dashboard/nodeSignIn/components/CommonRadioGroup.tsx @@ -22,7 +22,6 @@ const CommonRadioGroup = ({ labelTrue, labelFalse, value, setIntermediaryAvailab const handleRadioChange = (event: React.ChangeEvent) => { const radioNewValue = (event.target as HTMLInputElement).value === "true"; - console.log(radioNewValue); if (radioNewValue) { setShowAlert(true); } diff --git a/src/pages/iban/StandInAndCupForm/StandInAndCupForm.tsx b/src/pages/iban/StandInAndCupForm/StandInAndCupForm.tsx index 39499b6e4..ca77ba77b 100644 --- a/src/pages/iban/StandInAndCupForm/StandInAndCupForm.tsx +++ b/src/pages/iban/StandInAndCupForm/StandInAndCupForm.tsx @@ -272,10 +272,11 @@ const StandInAndCupForm = ({ ibanList, error, loading }: Props) => { ) : ( - {t('ibanPage.selectIban')} + {t('ibanPage.selectIban')} { expect(manageChip).toBeInTheDocument(); //Stand in - const selectStandInBtn = await within(screen.getByTestId('stand-in-test-ext')).getByRole( - 'button' - ); + const selectStandInBtn = screen.getAllByLabelText('ibanPage.selectIban')[0]; await waitFor(() => { fireEvent.mouseDown(selectStandInBtn); fireEvent.click(screen.getByText(new RegExp(`${ibanListMocked.ibans_enhanced[0].iban}`, 'i'))); }); - expect(selectStandInBtn.textContent).toBe(ibanListMocked.ibans_enhanced[0].iban); + expect(selectStandInBtn).toHaveTextContent(ibanListMocked.ibans_enhanced[0].iban); await new Promise((r) => setTimeout(r, 1000)); //Cup - const selectCupBtn = await within(screen.getByTestId('cup-test-ext')).getByRole('button'); + const selectCupBtn = screen.getAllByLabelText('ibanPage.selectIban')[1]; await waitFor(() => { fireEvent.mouseDown(selectCupBtn); fireEvent.click(screen.getByText(new RegExp(`${ibanListMocked.ibans_enhanced[1].iban}`, 'i'))); @@ -107,9 +105,7 @@ describe('StandInAndCupForm', () => { expect(manageChip).toBeInTheDocument(); //Stand in - const selectStandInBtn = await within(screen.getByTestId('stand-in-test-ext')).getByRole( - 'button' - ); + const selectStandInBtn = screen.getAllByLabelText('ibanPage.selectIban')[0]; await waitFor(() => { fireEvent.mouseDown(selectStandInBtn); fireEvent.click(screen.getByText(new RegExp(`${ibanList.ibans_enhanced[3].iban}`, 'i'))); @@ -118,7 +114,7 @@ describe('StandInAndCupForm', () => { await new Promise((r) => setTimeout(r, 1000)); //Cup - const selectCupBtn = await within(screen.getByTestId('cup-test-ext')).getByRole('button'); + const selectCupBtn = screen.getAllByLabelText('ibanPage.selectIban')[1]; await waitFor(() => { fireEvent.mouseDown(selectCupBtn); fireEvent.click(screen.getByText(new RegExp(`${ibanList.ibans_enhanced[2].iban}`, 'i'))); @@ -144,9 +140,7 @@ describe('StandInAndCupForm', () => { expect(manageChip).toBeInTheDocument(); //Stand in - const selectStandInBtn = await within(screen.getByTestId('stand-in-test-ext')).getByRole( - 'button' - ); + const selectStandInBtn = screen.getAllByLabelText('ibanPage.selectIban')[0]; await waitFor(() => { fireEvent.mouseDown(selectStandInBtn); fireEvent.click(screen.getByText(new RegExp(`${ibanList.ibans_enhanced[2].iban}`, 'i'))); @@ -155,7 +149,7 @@ describe('StandInAndCupForm', () => { await new Promise((r) => setTimeout(r, 1000)); //Cup - const selectCupBtn = await within(screen.getByTestId('cup-test-ext')).getByRole('button'); + const selectCupBtn = screen.getAllByLabelText('ibanPage.selectIban')[1]; await waitFor(() => { fireEvent.mouseDown(selectCupBtn); fireEvent.click( @@ -216,9 +210,7 @@ describe('StandInAndCupForm', () => { expect(manageChip).toBeInTheDocument(); //Stand in - const selectStandInBtn = await within(screen.getByTestId('stand-in-test-ext')).getByRole( - 'button' - ); + const selectStandInBtn = screen.getAllByLabelText('ibanPage.selectIban')[0]; await waitFor(() => { fireEvent.mouseDown(selectStandInBtn); fireEvent.click(screen.getByText(new RegExp(`${ibanList.ibans_enhanced[3].iban}`, 'i'))); @@ -227,7 +219,7 @@ describe('StandInAndCupForm', () => { await new Promise((r) => setTimeout(r, 1000)); //Cup - const selectCupBtn = await within(screen.getByTestId('cup-test-ext')).getByRole('button'); + const selectCupBtn = screen.getAllByLabelText('ibanPage.selectIban')[1]; await waitFor(() => { fireEvent.mouseDown(selectCupBtn); fireEvent.click(screen.getByText(new RegExp(`${ibanList.ibans_enhanced[2].iban}`, 'i'))); diff --git a/src/pages/stations/addEditStation/AddEditStationForm.tsx b/src/pages/stations/addEditStation/AddEditStationForm.tsx index 9f6ff03ee..62d6ee10c 100644 --- a/src/pages/stations/addEditStation/AddEditStationForm.tsx +++ b/src/pages/stations/addEditStation/AddEditStationForm.tsx @@ -82,7 +82,6 @@ import { TestStationTypeEnum } from '../../../api/generated/portal/StationTestDt import AddEditStationFormValidation from './components/AddEditStationFormValidation'; type Props = { - goBack: () => void; stationDetail?: StationDetailResource; formAction: string; }; @@ -107,7 +106,7 @@ const getDefaultConnectionType = (stationDetail?: StationDetailResource) => { }; const componentPath = 'addEditStationPage.addForm'; -const AddEditStationForm = ({ goBack, stationDetail, formAction }: Props) => { +const AddEditStationForm = ({ stationDetail, formAction }: Props) => { const { t } = useTranslation(); const history = useHistory(); const [showConfirmModal, setShowConfirmModal] = useState(false); @@ -578,9 +577,7 @@ const AddEditStationForm = ({ goBack, stationDetail, formAction }: Props) => { useEffect(() => { if (stationDetail) { - setConnectionType( - getDefaultConnectionType(stationDetail) - ); + setConnectionType(getDefaultConnectionType(stationDetail)); const category = getStationCategoryFromDetail(stationDetail, env); if (category === StationCategory.AsyncGPD) { setGDP(true); @@ -1072,7 +1069,7 @@ const AddEditStationForm = ({ goBack, stationDetail, formAction }: Props) => { - + {t(`${componentPath}.fields.primitiveVersion`)} { - + {t('addEditStationPage.addFormValidation.fields.select')} { }, [selectedParty]); return userIsPagopaOperator ? ( - + ) : ( ', () => { isPsp: false, isEcBroker: true, isPspBroker: false, - } + }, }, orgIsBrokerSigned: true, orgIsEcBrokerSigned: false, @@ -72,8 +72,7 @@ describe('', () => { orgIsEcSigned: true, orgIsPspBrokerSigned: false, orgIsPspDirect: false, - orgIsPspSigned: false - + orgIsPspSigned: false, }); const { store } = renderApp(stationId); @@ -85,6 +84,7 @@ describe('', () => { ); expect(screen.getByText('stationDetailPage.associates')).toBeInTheDocument(); + expect(screen.queryByTestId('station-detail-op')).not.toBeInTheDocument(); }); test('Test Render station detail with role operator', async () => { @@ -104,8 +104,6 @@ describe('', () => { payload: ecAdminSignedDirect, }) ); - expect( - screen.getByText('stationDetailPageValidation.infoToComplete.timeoutC') - ).toBeInTheDocument(); + expect(screen.getByTestId('station-detail-op')).toBeInTheDocument(); }); }); diff --git a/src/pages/stations/detail/components/DetailButtonsStation.tsx b/src/pages/stations/detail/components/DetailButtonsStation.tsx index 89a6eb28d..a6ba5389f 100644 --- a/src/pages/stations/detail/components/DetailButtonsStation.tsx +++ b/src/pages/stations/detail/components/DetailButtonsStation.tsx @@ -14,55 +14,10 @@ type Props = { const DetailButtonsStation = ({ status, stationCode }: Props) => { const { t } = useTranslation(); - const {userIsPagopaOperator} = useUserRole(); return ( - {userIsPagopaOperator && status === WrapperStatusEnum.APPROVED ? ( - <> - - - ) : userIsPagopaOperator && status !== WrapperStatusEnum.APPROVED ? ( - <> - - - - ) : status === WrapperStatusEnum.APPROVED ? ( + {status === WrapperStatusEnum.APPROVED ? ( <> + + + + ); +}; type Props = { stationDetail?: StationDetailResource; + setStationDetail: (value: any) => void; }; // eslint-disable-next-line complexity, sonarjs/cognitive-complexity const StationDetailsValidation = ({ stationDetail, + setStationDetail, }: // eslint-disable-next-line sonarjs/cognitive-complexity Props) => { const { t } = useTranslation(); const history = useHistory(); - const { userIsPagopaOperator } = useUserRole(); const { stationId } = useParams<{ stationId: string }>(); + const [showPassword, setShowPassword] = useState(false); + const [showModal, setShowModal] = useState(false); + const hidePassword = 'XXXXXXXXXXXXXX'; const proxyAddresses = ProxyConfigs[ENV.ENV as keyof IProxyConfig]; - const forwarderAddresses = NewConnConfigs[ENV.ENV as keyof INewConnConfig]; - const gpdAddresses = GPDConfigs[ENV.ENV as keyof IGPDConfig]; - - const [isGDP, setIsGDP] = useState(false); - const [isNewConn, setIsNewConn] = useState(false); - - const endpoint = - stationDetail?.targetHost === undefined || stationDetail?.targetHost === '' - ? '-' - : `${stationDetail?.targetHost === undefined ? '-' : stationDetail?.targetHost}${ - stationDetail?.targetPort && stationDetail?.targetPort > 0 - ? `:${stationDetail.targetPort}` - : '' - }${stationDetail?.targetPath}`; - - useEffect(() => { - if (stationDetail) { - setIsNewConn( - Object.entries(forwarderAddresses) - .map(([key, value]) => value) - .some((d) => - stationDetail.pofService && - stationDetail.pofService !== '/' && - stationDetail.pofService !== '' - ? d.includes(stationDetail.pofService) - : false - ) - ); - setIsGDP( - Object.entries(gpdAddresses) - .map(([key, value]) => value) - .some((gpd) => - stationDetail.pofService && - stationDetail.pofService !== '/' && - stationDetail.pofService !== '' - ? gpd.includes(stationDetail.pofService) - : false - ) - ); - } - }, [stationDetail]); const showOrHidePassword = (password?: string) => { if (showPassword) { @@ -93,84 +163,46 @@ Props) => { }; return ( - - - history.push(ROUTES.STATIONS)} - startIcon={} - sx={{ color: 'primary.main', mr: '20px' }} - weight="default" - data-testid="back-btn-test" - > - {t('general.back')} - - - - - - {t('channelDetailPage.createdOn')}{' '} - - {`${stationDetail?.createdAt?.toLocaleDateString('en-GB')} da ${ - stationDetail?.createdBy - }`} - +
+ + + history.push(ROUTES.STATIONS)} + startIcon={} + sx={{ color: 'primary.main', mr: '20px' }} + weight="default" + data-testid="back-btn-test" + > + {t('general.back')} + + + + {stationId} - - - - - {userIsPagopaOperator && stationDetail?.wrapperStatus === WrapperStatusEnum.TO_CHECK ? ( - - - {t('stationDetailPageValidation.alert')} - - - ) : userIsPagopaOperator && stationDetail?.wrapperStatus === WrapperStatusEnum.TO_FIX ? ( - - - - {t('stationDetailPageValidation.alertToFix')} - - - - ) : null} - - - - - - - {t('stationDetailPageValidation.configuration.status')} - - - - - + + + {t('stationDetailPageValidation.subtitle')} + + + + + - + {t('stationDetailPageValidation.configuration.title')} - - - {t('stationDetailPageValidation.configuration.subtitle')} - - - - - - - - + + <> {t('stationDetailPageValidation.configuration.registry')} @@ -188,185 +220,147 @@ Props) => { - {t('stationDetailPageValidation.configuration.version')} - - - - - {stationDetail?.version ?? '-'} - - - - - {t('stationDetailPageValidation.configuration.intermediaryCode')} + {t('stationDetailPageValidation.configuration.connectionType.label')} - {stationDetail?.brokerCode ?? '-'} + {t( + `stationDetailPageValidation.configuration.connectionType.${ + stationDetail?.isConnectionSync ? 'sync' : 'async' + }` + )} + - - - {t('stationDetailPageValidation.endpoints.modello1')} - - - - - {t('stationDetailPageValidation.endpoints.endpointRTConcat')} - - - - - {stationDetail?.targetHost}:{stationDetail?.targetPort} - {stationDetail?.targetPath} - - - - - {t('stationDetailPageValidation.endpoints.endpointRedirectConcat')} - - - - - {stationDetail?.redirectProtocol - ? `${stationDetail?.redirectProtocol.toLowerCase()}://` - : ''} - {stationDetail?.redirectIp} - {stationDetail?.redirectPort ? `:${stationDetail?.redirectPort}` : ''} - {stationDetail?.redirectPath} - {stationDetail?.redirectQueryString - ? `?${stationDetail?.redirectQueryString}` - : ''} - - - - - {t('stationDetailPageValidation.endpoints.modelloUnico')} - - - - - {t('stationDetailPageValidation.endpoints.endpointMUConcat')} - - - - - {stationDetail?.targetHostPof} - {stationDetail?.targetPortPof ? `:${stationDetail?.targetPortPof}` : ''} - {stationDetail?.targetPathPof} - - - - - {t('stationDetailPageValidation.endpoints.primitiveVersion')} - - - - - {stationDetail?.primitiveVersion} - - + {stationDetail?.isConnectionSync && ( + <> + <> + + + {t('stationDetailPageValidation.endpoints.modello1')} + + + + + {t('stationDetailPageValidation.endpoints.endpointRTConcat')} + + + + + {stationDetail?.targetHost}:{stationDetail?.targetPort} + {stationDetail?.targetPath} + + + + + {t('stationDetailPageValidation.endpoints.endpointRedirectConcat')} + + + + + {stationDetail?.redirectProtocol + ? `${stationDetail?.redirectProtocol.toLowerCase()}://` + : ''} + {stationDetail?.redirectIp} + {stationDetail?.redirectPort ? `:${stationDetail?.redirectPort}` : ''} + {stationDetail?.redirectPath} + {stationDetail?.redirectQueryString + ? `?${stationDetail?.redirectQueryString}` + : ''} + + + - - - {t('stationDetailPageValidation.configuration.modify')} - - - - } - sx={{ color: 'primary.main', mr: '20px' }} - weight="default" - disabled - > - {t('stationDetailPageValidation.configuration.changeHistory')} - - - - - {t('stationDetailPageValidation.configuration.lastUpgrade')} - - - - - {stationDetail?.modifiedAt?.toLocaleDateString('en-GB') ?? '-'} - - - - - {t('stationDetailPageValidation.configuration.operatedBy')} - - - - - {stationDetail?.modifiedBy} - - - + <> + + + {t('stationDetailPageValidation.endpoints.modelloUnico')} + + + + + {t('stationDetailPageValidation.endpoints.endpointMUConcat')} + + + + + {stationDetail?.targetHostPof} + {stationDetail?.targetPortPof ? `:${stationDetail?.targetPortPof}` : ''} + {stationDetail?.targetPathPof} + + + + + {t('stationDetailPageValidation.endpoints.primitiveVersion')} + + + + + {stationDetail?.primitiveVersion} + + + + + )} - - + - - - - - {t('stationDetailPageValidation.infoToComplete.title')} - - - - - {t('stationDetailPageValidation.infoToComplete.subtitle')} - - - - - - - + {stationDetail?.pofService && ( + + - - {t('stationDetailPageValidation.infoToComplete.registry')} - - - - - {t('stationDetailPageValidation.infoToComplete.version')} - - - - - {stationDetail?.version ?? '-'} + + {t('stationDetailPageValidation.infoToComplete.title')} - - - {t('stationDetailPageValidation.infoToComplete.password')} + + + {t('stationDetailPageValidation.infoToComplete.subtitle')} + - - {stationDetail?.password ? ( - <> + + <> + + + {t('stationDetailPageValidation.infoToComplete.registry')} + + + + + {t('stationDetailPageValidation.infoToComplete.version')} + + + + + {stationDetail?.version ?? '-'} + + + + + {t('stationDetailPageValidation.infoToComplete.password')} + + + {stationDetail?.password && ( + {showOrHidePassword(stationDetail?.password)} @@ -386,158 +380,159 @@ Props) => { )} - - ) : ( - '-' + )} - + - - - {t('stationDetailPageValidation.infoToComplete.configuration')} - - - {stationDetail && stationDetail.ip && isNewConn ? ( - <> - - - {t('stationDetailPageValidation.infoToComplete.newConn')} - - - - - {t('stationDetailPageValidation.infoToComplete.forwarderNewConn')} -{' '} - {stationDetail.ip} - {stationDetail.pofService} - - - - ) : stationDetail && stationDetail.ip && isGDP ? ( - <> - - - {t('stationDetailPageValidation.infoToComplete.GPD')} - - - - - {t('stationDetailPageValidation.infoToComplete.gdpDetail')} -{' '} - {stationDetail.ip} - {stationDetail.pofService} - - - - ) : ( - <> - - {'-'} - - - {'-'} - - - )} - {/* - - {t('stationDetailPageValidation.infoToComplete.newConn')} - - - - - {stationDetail && stationDetail.ip && isNewConn - ? `${stationDetail.protocol === 'HTTPS' ? 'https://' : 'http://'}${ - stationDetail.ip - }${stationDetail.port ? `:${stationDetail.port}` : ''}${ - stationDetail.service + <> + + + {t('stationDetailPageValidation.infoToComplete.configuration')} + + + + + + {t( + `stationDetailPageValidation.infoToComplete.${ + stationDetail?.isConnectionSync ? 'newConn' : 'GPD' }` - : '-'} - - - - - {t('stationDetailPageValidation.infoToComplete.GPD')} - - - - - {stationDetail && stationDetail.ip && isGDP - ? `${stationDetail.protocol === 'HTTPS' ? 'https://' : 'http://'}${ - stationDetail.ip - }${stationDetail.port ? `:${stationDetail.port}` : ''}${ - stationDetail.service + )} + + + + + {t( + `stationDetailPageValidation.infoToComplete.${ + stationDetail?.isConnectionSync ? 'forwarderNewConn' : 'gdpDetail' }` - : '-'} - - */} - - - {t('stationDetailPageValidation.infoToComplete.proxy')} - - - - - {t('stationDetailPageValidation.infoToComplete.proxyAddress')} - - - - - {stationDetail?.proxyHost && stationDetail?.proxyPort - ? `${stationDetail.proxyHost}:${stationDetail.proxyPort}` - : '-'} + )}{' '} + - {stationDetail.ip} + {stationDetail.pofService} + + + - {stationDetail?.proxyHost !== '' && - Object.entries(proxyAddresses).map(([key, value]) => - value.includes( - stationDetail?.proxyHost && stationDetail.proxyHost.toString() - ) - ? ` (${t( - 'stationDetailPageValidation.infoToComplete.proxyLabels.' + key - )})` - : '' - )} - - - - - {t('stationDetailPageValidation.infoToComplete.otherInfo')} - - - - - {t('stationDetailPageValidation.infoToComplete.timeoutA')} - - - - - {stationDetail?.timeoutA ?? '-'} - - - - - {t('stationDetailPageValidation.infoToComplete.timeoutB')} - - - - - {stationDetail?.timeoutB ?? '-'} - - - - - {t('stationDetailPageValidation.infoToComplete.timeoutC')} - - - - - {stationDetail?.timeoutC ?? '-'} - - + <> + + + {t('stationDetailPageValidation.infoToComplete.proxy')} + + + + + {t('stationDetailPageValidation.infoToComplete.proxyAddress')} + + + + + {stationDetail?.proxyHost && stationDetail?.proxyPort + ? `${stationDetail.proxyHost}:${stationDetail.proxyPort}` + : '-'} + + {stationDetail?.proxyHost !== '' && + Object.entries(proxyAddresses).map(([key, value]) => + value.includes( + stationDetail?.proxyHost && stationDetail.proxyHost.toString() + ) + ? ` (${t( + 'stationDetailPageValidation.infoToComplete.proxyLabels.' + key + )})` + : '' + )} + + + + + <> + + + {t('stationDetailPageValidation.infoToComplete.otherInfo')} + + + + + {t('stationDetailPageValidation.infoToComplete.timeoutA')} + + + + + {stationDetail?.timeoutA ?? '-'} + + + + + {t('stationDetailPageValidation.infoToComplete.timeoutB')} + + + + + {stationDetail?.timeoutB ?? '-'} + + + + + {t('stationDetailPageValidation.infoToComplete.timeoutC')} + + + + + {stationDetail?.timeoutC ?? '-'} + + + - - - + + )} + + + {t('channelDetailPage.createdOn')}{' '} + + {`${stationDetail?.createdAt?.toLocaleDateString('en-GB')} da ${ + stationDetail?.createdBy + }`} + + + + {(stationDetail?.wrapperStatus === WrapperStatusEnum.TO_CHECK || + stationDetail?.wrapperStatus === WrapperStatusEnum.TO_CHECK_UPDATE) && ( + + )} + + + - + {showModal && ( + ( + + )} + /> + )} +
); }; export default StationDetailsValidation; diff --git a/src/pages/stations/detail/components/__tests__/StationDetailsValidation.test.tsx b/src/pages/stations/detail/components/__tests__/StationDetailsValidation.test.tsx index 67886ab65..127d7a4af 100644 --- a/src/pages/stations/detail/components/__tests__/StationDetailsValidation.test.tsx +++ b/src/pages/stations/detail/components/__tests__/StationDetailsValidation.test.tsx @@ -60,6 +60,7 @@ export const mockedFullStation: StationDetailResource = { targetPath: 'Valore', targetPort: 1000, version: 2, + pofService: "pofService" }; describe('', () => { diff --git a/src/pages/stations/list/StationsTableColumns.tsx b/src/pages/stations/list/StationsTableColumns.tsx index f7e569573..a6202faea 100644 --- a/src/pages/stations/list/StationsTableColumns.tsx +++ b/src/pages/stations/list/StationsTableColumns.tsx @@ -1,7 +1,4 @@ -import { Box, Chip } from '@mui/material'; -import ChevronRightIcon from '@mui/icons-material/ChevronRight'; -import { GridColDef, GridRenderCellParams } from '@mui/x-data-grid'; -import i18n from '@pagopa/selfcare-common-frontend/locale/locale-utils'; +import { GridColDef } from '@mui/x-data-grid'; import { TFunction } from 'react-i18next'; import { generatePath } from 'react-router-dom'; import GridLinkAction from '../../../components/Table/GridLinkAction'; @@ -9,7 +6,7 @@ import { FormAction } from '../../../model/Station'; import ROUTES from '../../../routes'; import { StatusEnum } from '../../../api/generated/portal/StationDetailsDto'; import { renderCell, showCustomHeader } from '../../../components/Table/TableUtils'; -import { WrapperStatusEnum } from '../../../api/generated/portal/WrapperStationResource'; +import { StatusChip } from '../../../components/StatusChip'; export function buildColumnDefs( t: TFunction<'translation', undefined>, @@ -109,7 +106,7 @@ export function buildColumnDefs( editable: false, disableColumnMenu: true, renderHeader: showCustomHeader, - renderCell: (params) => showStatus(params, userIsPagopaOperator), + renderCell: (params) => , sortable: false, flex: 4, }, @@ -123,107 +120,66 @@ export function buildColumnDefs( disableColumnMenu: true, editable: false, - getActions: (params: any) => { - const manageStationAction = ( - - ); - const editStationAction = ( - - ); - const duplicateStationAction = ( - - ); - const manageStationECAction = ( - - ); - - if(userIsPagopaOperator){ - return [manageStationAction, manageStationECAction]; - } else if (params.row.wrapperStatus === StatusEnum.APPROVED) { - return [manageStationAction, manageStationECAction, duplicateStationAction]; - } else { - return [manageStationAction, editStationAction]; - } - }, + getActions: (params: any) => getRowActions(params, userIsPagopaOperator), sortable: false, flex: 1, }, ] as Array; } -// TODO check to clean -// eslint-disable-next-line sonarjs/cognitive-complexity -export function showStatus(params: GridRenderCellParams, userIsPagopaOperator: boolean) { - return renderCell({ - value: ( - - - - ), - overrideStyle: { - paddingLeft: 0, - paddingRight: 0, - textAlign: 'left', - }, - }); -} +export const getRowActions = (params: any, userIsPagopaOperator: boolean) => { + const stationCode = params.row.stationCode; + if (params.row.wrapperStatus === StatusEnum.APPROVED) { + if (userIsPagopaOperator) { + return [manageStationAction(stationCode), manageStationECAction(stationCode)]; + } + return [ + manageStationAction(stationCode), + manageStationECAction(stationCode), + duplicateStationAction(stationCode), + ]; + } else { + return [manageStationAction(stationCode), editStationAction(stationCode)]; + } +}; + +export const manageStationAction = (stationCode: string) => ( + +); +export const editStationAction = (stationCode: string) => ( + +); +export const duplicateStationAction = (stationCode: string) => ( + +); +export const manageStationECAction = (stationCode: string) => ( + +); diff --git a/src/pages/stations/list/__tests__/StationsTableColumns.test.tsx b/src/pages/stations/list/__tests__/StationsTableColumns.test.tsx index 2c6169c83..1565dd664 100644 --- a/src/pages/stations/list/__tests__/StationsTableColumns.test.tsx +++ b/src/pages/stations/list/__tests__/StationsTableColumns.test.tsx @@ -1,7 +1,16 @@ import { GridColDef, GridRenderCellParams, GridStateColDef } from '@mui/x-data-grid'; import { cleanup, render } from '@testing-library/react'; -import { showStatus, buildColumnDefs } from '../StationsTableColumns'; +import { + buildColumnDefs, + duplicateStationAction, + editStationAction, + getRowActions, + manageStationAction, + manageStationECAction, +} from '../StationsTableColumns'; import React from 'react'; +import { mockedFullStation } from '../../detail/components/__tests__/StationDetailsValidation.test'; +import { WrapperStatusEnum } from '../../../../api/generated/portal/StationDetailResource'; beforeEach(() => { jest.spyOn(console, 'error').mockImplementation(() => {}); @@ -83,7 +92,7 @@ describe('', () => { { field: 'connectionType', cellClassName: 'justifyContentNormal', - headerName: "stationsPage.stationsTableColumns.headerFields.connection", + headerName: 'stationsPage.stationsTableColumns.headerFields.connection', align: 'left', headerAlign: 'left', editable: false, @@ -165,8 +174,6 @@ describe('', () => { ] as Array; expect(buildColumnDefs(mockTFunction, false)).toEqual(ArrayBuildColumnDefs); - - render(<>{showStatus(params, false)}); }); test('Test of all the functions inside StationsTableColumns as pagopa operator', () => { @@ -188,7 +195,7 @@ describe('', () => { { field: 'connectionType', cellClassName: 'justifyContentNormal', - headerName: "stationsPage.stationsTableColumns.headerFields.connection", + headerName: 'stationsPage.stationsTableColumns.headerFields.connection', align: 'left', headerAlign: 'left', editable: false, @@ -242,7 +249,39 @@ describe('', () => { ] as Array; expect(buildColumnDefs(mockTFunction, true)).toEqual(ArrayBuildColumnDefs); + }); + + test('Test row actions StationsTableColumns as pagopa operator', () => { + let paramsApproved = { + row: { ...mockedFullStation, wrapperStatus: WrapperStatusEnum.APPROVED }, + }; + let paramsToCheck = { + row: { ...mockedFullStation, wrapperStatus: WrapperStatusEnum.TO_CHECK }, + }; + + // Station approved, not an operator + expect(getRowActions(paramsApproved, false)).toEqual([ + manageStationAction(mockedFullStation.stationCode), + manageStationECAction(mockedFullStation.stationCode), + duplicateStationAction(mockedFullStation.stationCode), + ]); + + // Station not approved, not an operator + expect(getRowActions(paramsToCheck, false)).toEqual([ + manageStationAction(mockedFullStation.stationCode), + editStationAction(mockedFullStation.stationCode), + ]); + + // Station approved, as operator + expect(getRowActions(paramsApproved, true)).toEqual([ + manageStationAction(mockedFullStation.stationCode), + manageStationECAction(mockedFullStation.stationCode), + ]); - render(<>{showStatus(params, true)}); + // Station not approved, as operator + expect(getRowActions(paramsToCheck, true)).toEqual([ + manageStationAction(mockedFullStation.stationCode), + editStationAction(mockedFullStation.stationCode), + ]); }); }); diff --git a/src/services/__mocks__/stationService.ts b/src/services/__mocks__/stationService.ts index 5e3d52eca..2af1d5fc1 100644 --- a/src/services/__mocks__/stationService.ts +++ b/src/services/__mocks__/stationService.ts @@ -679,8 +679,8 @@ export const getECListByStationCode = ( export const updateWrapperStation = (_stations: StationDetailsDto): Promise => new Promise((resolve) => resolve(mockedWrapperStation)); -export const updateWrapperStationByOpt = (_stations: StationDetailsDto): Promise => - new Promise((resolve) => resolve(mockedWrapperStation)); +export const updateWrapperStationByOpt = ( +): Promise => new Promise((resolve) => resolve(mockedFullStation)); export const updateStation = ( _stations: StationDetailsDto, diff --git a/src/services/__tests__/stationService.test.ts b/src/services/__tests__/stationService.test.ts index 2ea481afc..4e8b147cb 100644 --- a/src/services/__tests__/stationService.test.ts +++ b/src/services/__tests__/stationService.test.ts @@ -35,7 +35,7 @@ import { getWrapperStation, testStation, updateStation, - updateWrapperStationByOpt, + updateWrapperStationWithOperatorReview, updateWrapperStationToCheck, updateWrapperStationToCheckUpdate, } from '../stationService'; @@ -103,9 +103,13 @@ describe('StationService test mocked', () => { const response = await updateWrapperStationToCheckUpdate(mockedStationDetailsDTO); expect(response).toMatchObject(mockedWrapperStation); }); - test('Test updateWrapperStationByOpt', async () => { - const response = await updateWrapperStationByOpt(mockedStationDetailsDTO); - expect(response).toMatchObject(mockedWrapperStation); + test('Test updateWrapperStationWithOperatorReview', async () => { + const response = await updateWrapperStationWithOperatorReview({ + stationCode: 'stationCode', + ciTaxCode: 'ciTaxCode', + note: 'note', + }); + expect(response).toMatchObject(mockedFullStation); }); test('Test updateStation', async () => { const response = await updateStation(mockedStationDetailsDTO, 'stationCode'); @@ -260,11 +264,17 @@ describe('StationService test', () => { expect(updateWrapperStationToCheckUpdate(mockedStationDetailsDTO)).resolves.not.toThrow(); expect(spyOn).toBeCalledTimes(1); }); - test('Test updateWrapperStationByOpt', async () => { + test('Test updateWrapperStationWithOperatorReview', async () => { const spyOn = jest - .spyOn(BackofficeApi, 'updateWrapperStationByOpt') - .mockReturnValue(new Promise((resolve) => resolve(mockedWrapperStation))); - expect(updateWrapperStationByOpt(mockedStationDetailsDTO)).resolves.not.toThrow(); + .spyOn(BackofficeApi, 'updateWrapperStationWithOperatorReview') + .mockReturnValue(new Promise((resolve) => resolve(mockedFullStation))); + expect( + updateWrapperStationWithOperatorReview({ + stationCode: 'stationCode', + ciTaxCode: 'ciTaxCode', + note: 'note', + }) + ).resolves.not.toThrow(); expect(spyOn).toBeCalledTimes(1); }); test('Test updateStation', async () => { diff --git a/src/services/stationService.ts b/src/services/stationService.ts index daeb087b3..48b34020d 100644 --- a/src/services/stationService.ts +++ b/src/services/stationService.ts @@ -191,11 +191,23 @@ export const updateWrapperStationToCheckUpdate = ( } }; -export const updateWrapperStationByOpt = (station: StationDetailsDto): Promise => { +export const updateWrapperStationWithOperatorReview = ({ + stationCode, + ciTaxCode, + note, +}: { + stationCode: string; + ciTaxCode: string; + note: string; +}): Promise => { if (process.env.REACT_APP_API_MOCK_BACKOFFICE === 'true') { - return updateStationWrapByOpt(station); + return updateStationWrapByOpt(); } else { - return BackofficeApi.updateWrapperStationByOpt(station).then((resources) => resources); + return BackofficeApi.updateWrapperStationWithOperatorReview({ + stationCode, + ciTaxCode, + note, + }).then((resources) => resources); } }; diff --git a/src/utils/constants.ts b/src/utils/constants.ts index f6061653e..b7f57d066 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -20,6 +20,7 @@ export const LOADING_TASK_CHANNEL_PSP_TABLE = 'CHANNEL_PSP_TABLE'; export const LOADING_TASK_STATION_ADD_EDIT = 'STATIONS_ADD_EDIT'; export const LOADING_TASK_STATION_DETAILS = 'STATION_DETAILS'; export const LOADING_TASK_STATION_DETAILS_WRAPPER = 'STATION_DETAILS_WRAPPER'; +export const LOADING_TASK_STATION_DETAILS_REQUEST_EDIT = 'STATION_DETAILS_REQUEST_EDIT'; export const LOADING_TASK_STATION_EC_TABLE = 'STATION_EC_TABLE'; export const LOADING_TASK_EC_AVAILABLE = 'EC_AVAILABLE'; export const LOADING_TASK_SEGREGATION_CODES_AVAILABLE = 'EC_AVAILABLE';