diff --git a/packages/pn-personagiuridica-webapp/package.json b/packages/pn-personagiuridica-webapp/package.json
index a793ce1a5c..7bef12fd2c 100644
--- a/packages/pn-personagiuridica-webapp/package.json
+++ b/packages/pn-personagiuridica-webapp/package.json
@@ -41,7 +41,6 @@
"preview": "vite preview",
"test": "tsc && vitest --run",
"test:fast": "vitest --run",
- "test:a11y": "vitest --run --config ./vite.config.a11y.ts",
"test:all": "vitest --run --config ./vite.config.all.ts",
"test:coverage": "tsc && vitest run --coverage",
"lint": "eslint . -c .eslintrc.js --ext .ts,.tsx --fix",
@@ -74,6 +73,7 @@
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.1",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
+ "@types/jest": "^29.5.12",
"@types/mixpanel-browser": "^2.38.0",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
@@ -88,7 +88,6 @@
"eslint-plugin-react": "^7.27.1",
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-plugin-sonarjs": "^0.10.0",
- "jest-axe": "^6.0.0",
"jsdom": "^24.0.0",
"prettier": "^2.4.1",
"sonarqube-scanner": "^3.3.0",
diff --git a/packages/pn-personagiuridica-webapp/src/__test__/App.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/__test__/App.a11y.test.tsx
deleted file mode 100644
index 844b6c6d5a..0000000000
--- a/packages/pn-personagiuridica-webapp/src/__test__/App.a11y.test.tsx
+++ /dev/null
@@ -1,128 +0,0 @@
-import MockAdapter from 'axios-mock-adapter';
-import { vi } from 'vitest';
-
-import { ThemeProvider } from '@mui/material';
-import { theme } from '@pagopa/mui-italia';
-
-import App from '../App';
-import { currentStatusDTO } from '../__mocks__/AppStatus.mock';
-import { userResponse } from '../__mocks__/Auth.mock';
-import { digitalAddresses } from '../__mocks__/Contacts.mock';
-import { apiClient } from '../api/apiClients';
-import { GET_CONSENTS } from '../api/consents/consents.routes';
-import { CONTACTS_LIST } from '../api/contacts/contacts.routes';
-import { COUNT_DELEGATORS } from '../api/delegations/delegations.routes';
-import { DelegationStatus } from '../models/Deleghe';
-import { ConsentType } from '../models/consents';
-import { RenderResult, act, axe, render } from './test-utils';
-
-// mock imports
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translation hook can use it without a warning being shown
- Trans: (props: { i18nKey: string }) => props.i18nKey,
- useTranslation: () => ({
- t: (str: string) => str,
- i18n: { language: 'it' },
- }),
-}));
-
-vi.mock('../pages/Dashboard.page', () => () =>
Generic Page
);
-
-const unmockedFetch = global.fetch;
-
-const Component = () => (
-
-
-
-);
-
-const reduxInitialState = {
- userState: {
- user: userResponse,
- fetchedTos: false,
- fetchedPrivacy: false,
- tosConsent: {
- accepted: false,
- isFirstAccept: false,
- currentVersion: 'mocked-version-1',
- },
- privacyConsent: {
- accepted: false,
- isFirstAccept: false,
- currentVersion: 'mocked-version-1',
- },
- },
-};
-
-describe('App.tsx - accessibility tests', async () => {
- let mock: MockAdapter;
-
- beforeAll(() => {
- mock = new MockAdapter(apiClient);
- // FooterPreLogin (mui-italia) component calls an api to fetch selfcare products list.
- // this causes an error, so we mock to avoid it
- global.fetch = () =>
- Promise.resolve({
- json: () => Promise.resolve([]),
- }) as Promise;
- });
-
- afterEach(() => {
- mock.reset();
- });
-
- afterAll(() => {
- mock.restore();
- global.fetch = unmockedFetch;
- });
-
- it('Test if automatic accessibility tests passes', async () => {
- const { container } = render();
- const result = await axe(container);
- expect(result).toHaveNoViolations();
- });
-
- it('Test if automatic accessibility tests passes - user logged in', async () => {
- mock.onGet(GET_CONSENTS(ConsentType.DATAPRIVACY)).reply(200, {
- recipientId: userResponse.uid,
- consentType: ConsentType.DATAPRIVACY,
- accepted: true,
- });
- mock.onGet(GET_CONSENTS(ConsentType.TOS)).reply(200, {
- recipientId: userResponse.uid,
- consentType: ConsentType.TOS,
- accepted: true,
- });
- mock.onGet('downtime/v1/status').reply(200, currentStatusDTO);
- mock.onGet(CONTACTS_LIST()).reply(200, digitalAddresses);
- mock.onGet(COUNT_DELEGATORS(DelegationStatus.PENDING)).reply(200, 3);
- let result: RenderResult | undefined;
- await act(async () => {
- result = render(, { preloadedState: reduxInitialState });
- });
- if (result) {
- const results = await axe(result.container);
- expect(results).toHaveNoViolations();
- }
- }, 15000);
-
- it('Test if automatic accessibility tests passes - errors on API call', async () => {
- mock.onGet(GET_CONSENTS(ConsentType.DATAPRIVACY)).reply(200, {
- recipientId: userResponse.uid,
- consentType: ConsentType.DATAPRIVACY,
- accepted: true,
- });
- mock.onGet(GET_CONSENTS(ConsentType.TOS)).reply(500);
- mock.onGet('downtime/v1/status').reply(200, currentStatusDTO);
- mock.onGet(CONTACTS_LIST()).reply(200, digitalAddresses);
- mock.onGet(COUNT_DELEGATORS(DelegationStatus.PENDING)).reply(200, 3);
- let result: RenderResult | undefined;
- await act(async () => {
- result = render(, { preloadedState: reduxInitialState });
- });
- if (result) {
- const results = await axe(result.container);
- expect(results).toHaveNoViolations();
- }
- }, 15000);
-});
diff --git a/packages/pn-personagiuridica-webapp/src/__test__/test-utils.tsx b/packages/pn-personagiuridica-webapp/src/__test__/test-utils.tsx
index 4bc2a9ea3d..816f3e8ed2 100644
--- a/packages/pn-personagiuridica-webapp/src/__test__/test-utils.tsx
+++ b/packages/pn-personagiuridica-webapp/src/__test__/test-utils.tsx
@@ -1,4 +1,3 @@
-import { configureAxe, toHaveNoViolations } from 'jest-axe';
import { ReactElement, ReactNode } from 'react';
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
@@ -60,12 +59,6 @@ const customRender = (
});
};
-const axe = configureAxe({
- rules: {
- region: { enabled: false },
- },
-});
-
const createMockedStore = (preloadedState: any) =>
configureStore({
reducer: appReducers,
@@ -76,9 +69,7 @@ const createMockedStore = (preloadedState: any) =>
}),
});
-expect.extend(toHaveNoViolations);
-
// re-exporting everything
export * from '@testing-library/react';
// override render method
-export { axe, createMockedStore, customRender as render, testStore };
+export { createMockedStore, customRender as render, testStore };
diff --git a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/CourtesyContactItem.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/CourtesyContactItem.a11y.test.tsx
deleted file mode 100644
index a865bb4e5e..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/CourtesyContactItem.a11y.test.tsx
+++ /dev/null
@@ -1,140 +0,0 @@
-import { vi } from 'vitest';
-
-import { RenderResult, act, axe, fireEvent, render } from '../../../__test__/test-utils';
-import CourtesyContactItem, { CourtesyFieldType } from '../CourtesyContactItem';
-import { DigitalContactsCodeVerificationProvider } from '../DigitalContactsCodeVerification.context';
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
- Trans: (props: { i18nKey: string }) => props.i18nKey,
-}));
-
-describe('CourtesyContactItem component - accessibility tests', () => {
- const INPUT_VALID_PHONE = '3331234567';
- const VALID_EMAIL = 'prova@pagopa.it';
-
- let result: RenderResult;
-
- it('type "phone" - no phone added - does not have basic accessibility issues', async () => {
- await act(async () => {
- result = render(
-
-
-
- );
- });
-
- if (result) {
- const results = await axe(result.container);
- expect(results).toHaveNoViolations();
- }
- });
-
- it('type "phone" - phone added - does not have basic accessibility issues', async () => {
- await act(async () => {
- result = render(
-
-
-
- );
- });
-
- if (result) {
- const results = await axe(result.container);
- expect(results).toHaveNoViolations();
- }
- });
-
- it('type "phone" - phone added (edit mode) - does not have basic accessibility issues', async () => {
- await act(async () => {
- result = render(
-
-
-
- );
- });
-
- const editButton = result.getByRole('button', { name: 'button.modifica' });
- fireEvent.click(editButton!);
-
- if (result) {
- const results = await axe(result.container);
- expect(results).toHaveNoViolations();
- }
- });
-
- it('type "email" - no email added - does not have basic accessibility issues', async () => {
- await act(async () => {
- result = render(
-
-
-
- );
- });
-
- if (result) {
- const results = await axe(result.container);
- expect(results).toHaveNoViolations();
- }
- });
-
- it('type "email" - email added - does not have basic accessibility issues', async () => {
- await act(async () => {
- result = render(
-
-
-
- );
- });
-
- if (result) {
- const results = await axe(result.container);
- expect(results).toHaveNoViolations();
- }
- });
-
- it('type "email" - email added (edit mode) - does not have basic accessibility issues', async () => {
- await act(async () => {
- result = render(
-
-
-
- );
- });
-
- const editButton = result.getByRole('button', { name: 'button.modifica' });
- fireEvent.click(editButton!);
-
- if (result) {
- const results = await axe(result.container);
- expect(results).toHaveNoViolations();
- }
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/CourtesyContacts.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/CourtesyContacts.a11y.test.tsx
deleted file mode 100644
index 548cdc37bd..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/CourtesyContacts.a11y.test.tsx
+++ /dev/null
@@ -1,46 +0,0 @@
-import { vi } from 'vitest';
-
-import { digitalAddresses } from '../../../__mocks__/Contacts.mock';
-import { RenderResult, act, axe, render } from '../../../__test__/test-utils';
-import CourtesyContacts from '../CourtesyContacts';
-import { DigitalContactsCodeVerificationProvider } from '../DigitalContactsCodeVerification.context';
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
- Trans: (props: { i18nKey: string }) => props.i18nKey,
-}));
-
-describe('CourtesyContacts Component', async () => {
- let result: RenderResult;
-
- it('does not have basic accessibility issues - no contacts', async () => {
- await act(async () => {
- result = render(
-
-
-
- );
- });
- if (result) {
- const results = await axe(result.container);
- expect(results).toHaveNoViolations();
- }
- });
-
- it('does not have basic accessibility issues - contacts', async () => {
- await act(async () => {
- result = render(
-
-
-
- );
- });
- if (result) {
- const results = await axe(result.container);
- expect(results).toHaveNoViolations();
- }
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/CourtesyContactsList.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/CourtesyContactsList.a11y.test.tsx
deleted file mode 100644
index 1001d3c6c4..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/CourtesyContactsList.a11y.test.tsx
+++ /dev/null
@@ -1,53 +0,0 @@
-import { fail } from 'assert';
-import { vi } from 'vitest';
-
-import { digitalAddresses } from '../../../__mocks__/Contacts.mock';
-import { RenderResult, act, axe, render } from '../../../__test__/test-utils';
-import CourtesyContactsList from '../CourtesyContactsList';
-import { DigitalContactsCodeVerificationProvider } from '../DigitalContactsCodeVerification.context';
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
- Trans: (props: { i18nKey: string }) => props.i18nKey,
-}));
-
-describe('CourtesyContactsList Component', () => {
- let result: RenderResult | undefined;
-
- it('does not have basic accessibility issues (empty store)', async () => {
- await act(async () => {
- result = render(
-
-
-
- );
- });
-
- if (result) {
- const res = await axe(result.container);
- expect(res).toHaveNoViolations();
- } else {
- fail('render() returned undefined!');
- }
- });
-
- it('does not have basic accessibility issues (data in store)', async () => {
- await act(async () => {
- result = render(
-
-
-
- );
- });
-
- if (result) {
- const res = await axe(result.container);
- expect(res).toHaveNoViolations();
- } else {
- fail('render() returned undefined!');
- }
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/DigitalContactElem.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/DigitalContactElem.a11y.test.tsx
deleted file mode 100644
index 9d6c600b17..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/DigitalContactElem.a11y.test.tsx
+++ /dev/null
@@ -1,147 +0,0 @@
-import { vi } from 'vitest';
-
-import { TextField } from '@mui/material';
-
-import {
- RenderResult,
- act,
- axe,
- fireEvent,
- render,
- screen,
- waitFor,
-} from '../../../__test__/test-utils';
-import { LegalChannelType } from '../../../models/contacts';
-import DigitalContactElem from '../DigitalContactElem';
-import { DigitalContactsCodeVerificationProvider } from '../DigitalContactsCodeVerification.context';
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
- Trans: (props: { i18nKey: string }) => props.i18nKey,
-}));
-
-const fields = [
- {
- id: 'label',
- component: 'PEC',
- size: 'variable' as 'variable' | 'auto',
- key: 'key',
- },
- {
- id: 'value',
- key: 'key',
- component: (
-
- ),
- size: 'auto' as 'variable' | 'auto',
- isEditable: true,
- },
-];
-
-describe('DigitalContactElem Component - accessibility tests', () => {
- let result: RenderResult;
-
- it('does not have basic accessibility issues', async () => {
- // render component
- await act(async () => {
- result = render(
-
- {}}
- resetModifyValue={() => {}}
- />
-
- );
- });
-
- if (result) {
- const res = await axe(result.container);
- expect(res).toHaveNoViolations();
- } else {
- fail('render() returned undefined!');
- }
- });
-
- it('does not have basic accessibility issues - edit mode', async () => {
- // render component
- await act(async () => {
- result = render(
-
- {}}
- resetModifyValue={() => {}}
- />
-
- );
- });
- const buttons = result.container.querySelectorAll('button');
- fireEvent.click(buttons![0]);
- const input = await waitFor(() => result.container.querySelector('[name="pec"]'));
- expect(input).toBeInTheDocument();
-
- if (result) {
- const res = await axe(result.container);
- expect(res).toHaveNoViolations();
- } else {
- fail('render() returned undefined!');
- }
- });
-
- it('does not have basic accessibility issues - delete contact', async () => {
- // render component
- await act(async () => {
- result = render(
-
- {}}
- resetModifyValue={() => {}}
- />
-
- );
- });
- const buttons = result.container.querySelectorAll('button');
- fireEvent.click(buttons![1]);
- const dialog = await waitFor(() => screen.getByRole('dialog'));
- expect(dialog).toBeInTheDocument();
-
- if (result) {
- const res = await axe(result.container);
- expect(res).toHaveNoViolations();
- } else {
- fail('render() returned undefined!');
- }
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/DigitalContactsCard.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/DigitalContactsCard.a11y.test.tsx
deleted file mode 100644
index 7965fb647d..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/DigitalContactsCard.a11y.test.tsx
+++ /dev/null
@@ -1,34 +0,0 @@
-import { vi } from 'vitest';
-
-import { axe, render } from '../../../__test__/test-utils';
-import DigitalContactsCard from '../DigitalContactsCard';
-
-const title = 'Mocked title';
-const subTitle = 'Mocked subtitle';
-const actions = ;
-const body = Body
;
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
-}));
-
-describe('DigitalContactsCard Component - accessibility tests', () => {
- it('does not have basic accessibility issues', async () => {
- const { container } = render(
-
- {body}
-
- );
- const result = await axe(container);
- expect(result).toHaveNoViolations();
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/DigitalContactsCodeVerification.context.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/DigitalContactsCodeVerification.context.a11y.test.tsx
deleted file mode 100644
index 959670243f..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/DigitalContactsCodeVerification.context.a11y.test.tsx
+++ /dev/null
@@ -1,121 +0,0 @@
-import { vi } from 'vitest';
-
-import { digitalAddresses } from '../../../__mocks__/Contacts.mock';
-import {
- RenderResult,
- axe,
- fireEvent,
- render,
- screen,
- waitFor,
-} from '../../../__test__/test-utils';
-import * as api from '../../../api/contacts/Contacts.api';
-import { CourtesyChannelType, DigitalAddress, LegalChannelType } from '../../../models/contacts';
-import { DigitalContactsCodeVerificationProvider } from '../DigitalContactsCodeVerification.context';
-import {
- Component,
- pecValue,
- pecValueToVerify,
- senderId,
- showDialog,
-} from './DigitalContactsCodeVerification.context.test-utils';
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
- Trans: (props: { i18nKey: string }) => props.i18nKey,
-}));
-
-/*
-In questo test manca il test di accessibilità sulla modale che compare in fase di inserimento di un contatto già eistente.
-Il componente, infatti, si trova in pn-commons e qualora sia necessario un test di accessibilità, è giusto farlo li
-
-Andrea Cimini - 11/09/2023
-*/
-describe('DigitalContactsCodeVerification Context - accessibility tests', () => {
- let result: RenderResult;
-
- afterEach(() => {
- vi.clearAllMocks();
- });
-
- afterAll(() => {
- vi.restoreAllMocks();
- });
-
- it('does not have basic accessibility issues (code modal)', async () => {
- vi.spyOn(api.ContactsApi, 'createOrUpdateLegalAddress').mockResolvedValueOnce(void 0);
- // render component
- result = render(
-
-
-
- );
- const dialog = await showDialog(result);
- expect(dialog).toBeInTheDocument();
- if (result) {
- const res = await axe(result.container);
- expect(res).toHaveNoViolations();
- } else {
- fail('render() returned undefined!');
- }
- });
-
- it('does not have basic accessibility issues (pec to verify)', async () => {
- jest
- .spyOn(api.ContactsApi, 'createOrUpdateLegalAddress')
- .mockResolvedValueOnce(void 0)
- .mockResolvedValueOnce({ pecValid: false } as DigitalAddress);
- // render component
- result = render(
-
-
-
- );
- const dialog = await showDialog(result);
- const codeInputs = dialog?.querySelectorAll('input');
- // fill inputs with values
- codeInputs?.forEach((input, index) => {
- fireEvent.change(input, { target: { value: index.toString() } });
- });
- const buttons = dialog?.querySelectorAll('button');
- fireEvent.click(buttons![1]);
- await waitFor(() => {
- expect(dialog).not.toBeInTheDocument();
- });
- const validationDialog = result.getByTestId('validationDialog');
- expect(validationDialog).toBeInTheDocument();
- if (result) {
- const res = await axe(result.container);
- expect(res).toHaveNoViolations();
- } else {
- fail('render() returned undefined!');
- }
- });
-
- it('does not have basic accessibility issues (try to add an already existing contact)', async () => {
- vi.spyOn(api.ContactsApi, 'createOrUpdateCourtesyAddress').mockResolvedValueOnce(void 0);
- // render component
- result = render(
-
-
-
- );
- const button = screen.getByRole('button', { name: 'Click me' });
- fireEvent.click(button);
- const duplicateDialog = await waitFor(() => result.getByTestId('duplicateDialog'));
- expect(duplicateDialog).toBeInTheDocument();
- if (result) {
- const res = await axe(result.container);
- expect(res).toHaveNoViolations();
- } else {
- fail('render() returned undefined!');
- }
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/InsertLegalContact.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/InsertLegalContact.a11y.test.tsx
deleted file mode 100644
index ab2e042c13..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/InsertLegalContact.a11y.test.tsx
+++ /dev/null
@@ -1,33 +0,0 @@
-import { vi } from 'vitest';
-
-import { RenderResult, act, axe, render } from '../../../__test__/test-utils';
-import { DigitalContactsCodeVerificationProvider } from '../DigitalContactsCodeVerification.context';
-import InsertLegalContact from '../InsertLegalContact';
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
- Trans: (props: { i18nKey: string }) => props.i18nKey,
-}));
-
-describe('InsertLegalContact component', () => {
- let result: RenderResult;
-
- it('does not have basic accessibility issues', async () => {
- await act(async () => {
- result = render(
-
-
-
- );
- });
- if (result) {
- const res = await axe(result.container);
- expect(res).toHaveNoViolations();
- } else {
- fail('render() returned undefined!');
- }
- }, 10000);
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/LegalContactsList.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/LegalContactsList.a11y.test.tsx
deleted file mode 100644
index cb9b1dac41..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/LegalContactsList.a11y.test.tsx
+++ /dev/null
@@ -1,62 +0,0 @@
-import { vi } from 'vitest';
-
-import { digitalAddresses } from '../../../__mocks__/Contacts.mock';
-import { RenderResult, act, axe, render } from '../../../__test__/test-utils';
-import { DigitalContactsCodeVerificationProvider } from '../DigitalContactsCodeVerification.context';
-import LegalContactsList from '../LegalContactsList';
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
- Trans: (props: { i18nKey: string }) => props.i18nKey,
-}));
-
-const defaultAddress = digitalAddresses.legal.find(
- (addr) => addr.senderId === 'default' && addr.pecValid
-);
-
-describe('LegalContactsList Component - accessibility tests', () => {
- it('does not have basic accessibility issues - pec valid', async () => {
- let result: RenderResult | undefined;
-
- await act(async () => {
- result = render(
-
-
-
- );
- });
- if (result) {
- const res = await axe(result.container);
- expect(res).toHaveNoViolations();
- } else {
- fail('render() returned undefined!');
- }
- });
-
- it('does not have basic accessibility issues - pec validating', async () => {
- let result: RenderResult | undefined;
-
- await act(async () => {
- result = render(
-
-
-
- );
- });
- if (result) {
- const res = await axe(result.container);
- expect(res).toHaveNoViolations();
- } else {
- fail('render() returned undefined!');
- }
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/SpecialContactElem.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/SpecialContactElem.a11y.test.tsx
deleted file mode 100644
index ca7c88bded..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/SpecialContactElem.a11y.test.tsx
+++ /dev/null
@@ -1,45 +0,0 @@
-import { vi } from 'vitest';
-
-import { SpecialContactsProvider } from '@pagopa-pn/pn-commons';
-
-import { RenderResult, act, axe, render } from '../../../__test__/test-utils';
-import { DigitalContactsCodeVerificationProvider } from '../DigitalContactsCodeVerification.context';
-import SpecialContactElem from '../SpecialContactElem';
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
- Trans: (props: { i18nKey: string }) => props.i18nKey,
-}));
-
-describe('SpecialContactElem Component - accessibility tests', () => {
- let result: RenderResult;
-
- it('does not have basic accessibility issues', async () => {
- await act(async () => {
- result = render(
-
-
-
-
-
- );
- });
- if (result) {
- const res = await axe(result.container);
- expect(res).toHaveNoViolations();
- } else {
- fail('render() returned undefined!');
- }
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/SpecialContacts.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/SpecialContacts.a11y.test.tsx
deleted file mode 100644
index 880ccb0725..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Contacts/__test__/SpecialContacts.a11y.test.tsx
+++ /dev/null
@@ -1,87 +0,0 @@
-import MockAdapter from 'axios-mock-adapter';
-import { vi } from 'vitest';
-
-import { AppResponseMessage, ResponseEventDispatcher } from '@pagopa-pn/pn-commons';
-
-import { digitalAddresses } from '../../../__mocks__/Contacts.mock';
-import { parties } from '../../../__mocks__/ExternalRegistry.mock';
-import { RenderResult, act, axe, render } from '../../../__test__/test-utils';
-import { apiClient } from '../../../api/apiClients';
-import { GET_ALL_ACTIVATED_PARTIES } from '../../../api/external-registries/external-registries-routes';
-import { DigitalContactsCodeVerificationProvider } from '../DigitalContactsCodeVerification.context';
-import SpecialContacts from '../SpecialContacts';
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
- Trans: (props: { i18nKey: string }) => props.i18nKey,
-}));
-
-describe('SpecialContacts Component - accessibility tests', async () => {
- let result: RenderResult;
- let mock: MockAdapter;
-
- beforeAll(() => {
- mock = new MockAdapter(apiClient);
- });
-
- afterEach(() => {
- mock.reset();
- });
-
- afterAll(() => {
- mock.restore();
- });
-
- it('does not have basic accessibility issues - API OK', async () => {
- mock.onGet(GET_ALL_ACTIVATED_PARTIES()).reply(200, parties);
- // render component
- await act(async () => {
- result = render(
-
-
-
- );
- });
-
- if (result) {
- const res = await axe(result.container);
- expect(res).toHaveNoViolations();
- } else {
- fail('render() returned undefined!');
- }
- }, 10000);
-
- it('does not have basic accessibility issues - API ERROR', async () => {
- mock.onGet(GET_ALL_ACTIVATED_PARTIES()).reply(500);
- // render component
- await act(async () => {
- result = render(
- <>
-
-
-
-
-
- >
- );
- });
-
- if (result) {
- const res = await axe(result.container);
- expect(res).toHaveNoViolations();
- } else {
- fail('render() returned undefined!');
- }
- }, 10000);
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/AcceptDelegationModal.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/AcceptDelegationModal.a11y.test.tsx
deleted file mode 100644
index 6af1e04880..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/AcceptDelegationModal.a11y.test.tsx
+++ /dev/null
@@ -1,60 +0,0 @@
-import { vi } from 'vitest';
-
-import { axe, fireEvent, render, screen, waitFor, within } from '../../../__test__/test-utils';
-import AcceptDelegationModal from '../AcceptDelegationModal';
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
-}));
-
-describe('AcceptDelegationModal - accessibility tests', () => {
- it('is AcceptDelegationModal component accessible - first step', async () => {
- render(
- {}}
- handleConfirm={() => {}}
- />
- );
- const dialog = screen.getByTestId('codeDialog');
- const results = await axe(dialog);
- expect(results).toHaveNoViolations();
- });
-
- it('is AcceptDelegationModal component accessible - second step - no group selected', async () => {
- render(
- {}}
- handleConfirm={() => {}}
- />
- );
- const dialog = screen.getByTestId('groupDialog');
- const results = await axe(dialog);
- expect(results).toHaveNoViolations();
- });
-
- it('is AcceptDelegationModal component accessible - second step - group selected', async () => {
- render(
- {}}
- handleConfirm={() => {}}
- />
- );
- const dialog = screen.getByTestId('groupDialog');
- const results = await axe(dialog);
- const associateGroupRadio = within(dialog).getByTestId('associate-group');
- fireEvent.click(associateGroupRadio);
- await waitFor(() => expect(results).toHaveNoViolations());
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/AcceptDelegationModal.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/AcceptDelegationModal.test.tsx
deleted file mode 100644
index ca6a50d7fb..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/AcceptDelegationModal.test.tsx
+++ /dev/null
@@ -1,267 +0,0 @@
-import { vi } from 'vitest';
-
-import { testAutocomplete } from '@pagopa-pn/pn-commons/src/test-utils';
-
-import { fireEvent, render, screen, waitFor, within } from '../../../__test__/test-utils';
-import AcceptDelegationModal from '../AcceptDelegationModal';
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
-}));
-
-const confirmCbk = vi.fn();
-const cancelCbk = vi.fn();
-
-describe('AcceptDelegationModal', () => {
- afterEach(() => {
- vi.clearAllMocks();
- });
-
- it('renders CodeModal', async () => {
- render(
-
- );
- const dialog = screen.getByTestId('codeDialog') as Element;
- expect(dialog).toBeInTheDocument();
- });
-
- it('calls cancel callback - codeModal', () => {
- render(
-
- );
- const dialog = screen.getByTestId('codeDialog');
- const codeConfirmButton = within(dialog).getByTestId('codeConfirmButton');
- const codeCancelButton = within(dialog).getByTestId('codeCancelButton');
- expect(codeConfirmButton).toBeDisabled();
- fireEvent.click(codeCancelButton);
- expect(cancelCbk).toBeCalledTimes(1);
- });
-
- it('renders GroupModal - no groups selected', () => {
- render(
-
- );
- const dialog = screen.getByTestId('groupDialog');
- expect(dialog).toBeInTheDocument();
- const noGroupRadio = dialog.querySelector('[data-testid="no-group"] input');
- expect(noGroupRadio).toBeChecked();
- });
-
- it('renders GroupModal - groups selected', () => {
- const groups = [
- { id: 'group-1', name: 'Group 1' },
- { id: 'group-2', name: 'Group 2' },
- ];
- render(
- ,
- {
- preloadedState: {
- delegationsState: {
- groups,
- },
- },
- }
- );
- const dialog = screen.getByTestId('groupDialog');
- expect(dialog).toBeInTheDocument();
- const associateGroupRadio = dialog.querySelector('[data-testid="associate-group"] input');
- expect(associateGroupRadio).toBeChecked();
- const autocomplete = within(dialog).getByTestId(`groups`);
- expect(autocomplete).toHaveTextContent(groups[1].name);
- });
-
- it('calls cancel callback - groupModal', () => {
- render(
-
- );
- const dialog = screen.getByTestId('groupDialog');
- const groupConfirmButton = within(dialog).getByTestId('groupConfirmButton');
- const groupCancelButton = within(dialog).getByTestId('groupCancelButton');
- expect(groupConfirmButton).toBeEnabled();
- expect(groupCancelButton).toHaveTextContent('button.annulla');
- fireEvent.click(groupCancelButton);
- expect(cancelCbk).toBeCalledTimes(1);
- });
-
- it('selects groups - groupModal', async () => {
- const groups = [
- { id: 'group-1', name: 'Group 1', status: 'ACTIVE' },
- { id: 'group-2', name: 'Group 2', status: 'ACTIVE' },
- ];
- render(
- ,
- {
- preloadedState: {
- delegationsState: {
- groups,
- },
- },
- }
- );
- const dialog = screen.getByTestId('groupDialog');
- const groupConfirmButton = within(dialog).getByTestId('groupConfirmButton');
- const associateGroupRadio = within(dialog).getByTestId('associate-group');
- fireEvent.click(associateGroupRadio);
- await testAutocomplete(dialog, 'groups', groups, true, 1);
- expect(groupConfirmButton).toBeEnabled();
- fireEvent.click(groupConfirmButton);
- expect(confirmCbk).toBeCalledTimes(1);
- expect(confirmCbk).toBeCalledWith([], [groups[1]]);
- });
-
- it('fills the code, go next step and returns back', async () => {
- const groups = [
- { id: 'group-1', name: 'Group 1' },
- { id: 'group-2', name: 'Group 2' },
- ];
- render(
- ,
- {
- preloadedState: {
- delegationsState: {
- groups,
- },
- },
- }
- );
- let codeDialog = screen.getByTestId('codeDialog');
- const codeConfirmButton = within(codeDialog).getByTestId('codeConfirmButton');
- expect(codeConfirmButton).toBeDisabled();
- const codeInputs = codeDialog.querySelectorAll('input');
- codeInputs.forEach((input, index) => {
- fireEvent.change(input, { target: { value: index.toString() } });
- });
- expect(codeConfirmButton).toBeEnabled();
- // got to next step
- fireEvent.click(codeConfirmButton);
- const groupDialog = await waitFor(() => screen.findByTestId('groupDialog'));
- expect(codeDialog).not.toBeInTheDocument();
- expect(groupDialog).toBeInTheDocument();
- // go to previous step and check that inputs are filled with previous values
- const groupCancelButton = within(groupDialog).getByTestId('groupCancelButton');
- expect(groupCancelButton).toHaveTextContent('button.indietro');
- fireEvent.click(groupCancelButton);
- await waitFor(() => {
- codeDialog = screen.getByTestId('codeDialog');
- expect(groupDialog).not.toBeInTheDocument();
- });
- expect(codeDialog).toBeInTheDocument();
- codeInputs.forEach((input, index) => {
- expect(input).toHaveValue(index.toString());
- });
- });
-
- it('fills the code and confirm - no groups', async () => {
- render(
-
- );
- const codeDialog = screen.getByTestId('codeDialog');
- const codeConfirmButton = within(codeDialog).getByTestId('codeConfirmButton');
- expect(codeConfirmButton).toBeDisabled();
- const codeInputs = codeDialog.querySelectorAll('input');
- codeInputs.forEach((input, index) => {
- fireEvent.change(input, { target: { value: index.toString() } });
- });
- expect(codeConfirmButton).toBeEnabled();
- fireEvent.click(codeConfirmButton);
- expect(confirmCbk).toBeCalledTimes(1);
- expect(confirmCbk).toBeCalledWith(['0', '1', '2', '3', '4'], []);
- });
-
- it('fills the code, go next step, choose groups and confirm', async () => {
- const groups = [
- { id: 'group-1', name: 'Group 1', status: 'ACTIVE' },
- { id: 'group-2', name: 'Group 2', status: 'ACTIVE' },
- ];
- render(
- ,
- {
- preloadedState: {
- delegationsState: {
- groups,
- },
- },
- }
- );
- const codeDialog = screen.getByTestId('codeDialog');
- const codeConfirmButton = within(codeDialog).getByTestId('codeConfirmButton');
- expect(codeConfirmButton).toBeDisabled();
- const codeInputs = codeDialog.querySelectorAll('input');
- codeInputs.forEach((input, index) => {
- fireEvent.change(input, { target: { value: index.toString() } });
- });
- expect(codeConfirmButton).toBeEnabled();
- // got to next step
- fireEvent.click(codeConfirmButton);
- const groupDialog = await waitFor(() => screen.findByTestId('groupDialog'));
- expect(codeDialog).not.toBeInTheDocument();
- expect(groupDialog).toBeInTheDocument();
- const associateGroupRadio = await waitFor(() =>
- within(groupDialog).getByTestId('associate-group')
- );
- fireEvent.click(associateGroupRadio);
- await testAutocomplete(groupDialog, 'groups', groups, true, 1);
- const groupConfirmButton = within(groupDialog).getByTestId('groupConfirmButton');
- fireEvent.click(groupConfirmButton);
- expect(confirmCbk).toBeCalledTimes(1);
- expect(confirmCbk).toBeCalledWith(['0', '1', '2', '3', '4'], [groups[1]]);
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/ConfirmationModal.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/ConfirmationModal.a11y.test.tsx
deleted file mode 100644
index c9d43d8c55..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/ConfirmationModal.a11y.test.tsx
+++ /dev/null
@@ -1,19 +0,0 @@
-import { axe, render } from '../../../__test__/test-utils';
-import ConfirmationModal from '../ConfirmationModal';
-
-describe('ConfirmationModal Component - accessibility tests', () => {
- it('is Confirmation Modal component accessible', async () => {
- const result = render(
- {}}
- onCloseLabel="Cancella"
- open={true}
- onConfirm={() => {}}
- onConfirmLabel="Conferma"
- />
- );
- const results = await axe(result?.container);
- expect(results).toHaveNoViolations();
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/ConfirmationModal.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/ConfirmationModal.test.tsx
deleted file mode 100644
index bd3fc9b567..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/ConfirmationModal.test.tsx
+++ /dev/null
@@ -1,78 +0,0 @@
-import { vi } from 'vitest';
-
-import { fireEvent, render } from '../../../__test__/test-utils';
-import ConfirmationModal from '../ConfirmationModal';
-
-const mockCancelFunction = vi.fn();
-const mockConfirmFunction = vi.fn();
-
-describe('ConfirmationModal Component', () => {
- afterEach(() => {
- vi.clearAllMocks();
- });
-
- it('renders the component', () => {
- const { getByRole, getAllByTestId } = render(
-
- );
- const dialog = getByRole('dialog');
- expect(dialog).toBeInTheDocument();
- expect(dialog).toHaveTextContent(/Test Title/i);
- const dialogActions = getAllByTestId('dialogAction');
- expect(dialogActions).toHaveLength(2);
- expect(dialogActions[1]).toHaveTextContent(/Confirm/i);
- expect(dialogActions[0]).toHaveTextContent(/Cancel/i);
- });
-
- it('checks that the confirm and cancel functions are executed', () => {
- const { getAllByTestId } = render(
-
- );
- const dialogActions = getAllByTestId('dialogAction');
- const confirm = dialogActions[1];
- const cancel = dialogActions[0];
- fireEvent.click(confirm);
- expect(mockConfirmFunction).toBeCalledTimes(1);
- fireEvent.click(cancel);
- expect(mockCancelFunction).toBeCalledTimes(1);
- });
-
- it('renders the dialog with default labels', () => {
- const { getAllByTestId } = render(
-
- );
- const dialogActions = getAllByTestId('dialogAction');
- const confirm = dialogActions[1];
- const cancel = dialogActions[0];
- expect(confirm).toHaveTextContent(/Riprova/i);
- expect(cancel).toHaveTextContent(/Annulla/i);
- });
-
- it('renders the dialog with no confirm button', () => {
- const { getAllByTestId } = render(
-
- );
- const dialogActions = getAllByTestId('dialogAction');
- expect(dialogActions).toHaveLength(1);
- expect(dialogActions[0]).toHaveTextContent(/Annulla/i);
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegatesByCompany.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegatesByCompany.a11y.test.tsx
deleted file mode 100644
index f831ac14ed..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegatesByCompany.a11y.test.tsx
+++ /dev/null
@@ -1,28 +0,0 @@
-import { vi } from 'vitest';
-
-import { arrayOfDelegates } from '../../../__mocks__/Delegations.mock';
-import { axe, render } from '../../../__test__/test-utils';
-import DelegatesByCompany from '../DelegatesByCompany';
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
-}));
-
-describe('Delegates Component - accessibility tests', () => {
- it('is Delegates component accessible', async () => {
- const result = render(, {
- preloadedState: {
- delegationsState: {
- delegations: {
- delegates: arrayOfDelegates,
- },
- },
- },
- });
- const results = await axe(result.container);
- expect(results).toHaveNoViolations();
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegatesByCompany.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegatesByCompany.test.tsx
deleted file mode 100644
index 3b489b18ed..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegatesByCompany.test.tsx
+++ /dev/null
@@ -1,165 +0,0 @@
-import MockAdapter from 'axios-mock-adapter';
-import { ReactNode } from 'react';
-import { vi } from 'vitest';
-
-import { arrayOfDelegates } from '../../../__mocks__/Delegations.mock';
-import { fireEvent, render, waitFor, within } from '../../../__test__/test-utils';
-import { apiClient } from '../../../api/apiClients';
-import { REVOKE_DELEGATION } from '../../../api/delegations/delegations.routes';
-import * as routes from '../../../navigation/routes.const';
-import DelegatesByCompany from '../DelegatesByCompany';
-
-const mockNavigateFn = vi.fn();
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
- Trans: (props: { i18nKey: string; components?: Array }) => (
- <>
- {props.i18nKey} {props.components!.map((c) => c)}
- >
- ),
-}));
-
-vi.mock('react-router-dom', async () => ({
- ...(await vi.importActual('react-router-dom')),
- useNavigate: () => mockNavigateFn,
-}));
-
-describe('Delegates Component - assuming delegates API works properly', async () => {
- let mock: MockAdapter;
-
- beforeAll(() => {
- mock = new MockAdapter(apiClient);
- });
-
- afterEach(() => {
- mock.reset();
- vi.clearAllMocks();
- });
-
- afterAll(() => {
- vi.clearAllMocks();
- mock.restore();
- });
-
- it('renders the empty state', () => {
- const { container, getByTestId } = render(, {
- preloadedState: {
- delegationsState: {
- delegations: {
- delegates: [],
- },
- },
- },
- });
- expect(container).toHaveTextContent(/deleghe.delegatesTitle/i);
- const addButton = getByTestId('addDeleghe');
- expect(addButton).toBeInTheDocument();
- expect(container).toHaveTextContent(/deleghe.add/i);
- expect(container).toHaveTextContent(/deleghe.no_delegates/i);
- // clicks on empty state action
- const button = getByTestId('link-add-delegate');
- fireEvent.click(button);
- expect(mockNavigateFn).toBeCalledTimes(1);
- expect(mockNavigateFn).toBeCalledWith(routes.NUOVA_DELEGA);
- });
-
- it('render table with data', async () => {
- const { container, getByTestId, getAllByTestId } = render(, {
- preloadedState: {
- delegationsState: {
- delegations: {
- delegates: arrayOfDelegates,
- },
- },
- },
- });
- expect(container).not.toHaveTextContent(/deleghe.no_delegates/i);
- const table = getByTestId('delegatesTableDesktop');
- expect(table).toBeInTheDocument();
- const rows = getAllByTestId('delegatesBodyRowDesktop');
- expect(rows).toHaveLength(arrayOfDelegates.length);
- rows.forEach((row, index) => {
- expect(row).toHaveTextContent(arrayOfDelegates[index].delegate?.displayName!);
- });
- });
-
- it('clicks on add button and navigate to new delegation page', () => {
- const { getByTestId } = render();
- const addButton = getByTestId('addDeleghe');
- fireEvent.click(addButton);
- expect(mockNavigateFn).toBeCalledTimes(1);
- expect(mockNavigateFn).toBeCalledWith(routes.NUOVA_DELEGA);
- });
-
- it('visualize modal code and check code', async () => {
- const { getAllByTestId, getByTestId } = render(, {
- preloadedState: {
- delegationsState: {
- delegations: {
- delegates: arrayOfDelegates,
- },
- },
- },
- });
- const menu = getAllByTestId('delegationMenuIcon');
- fireEvent.click(menu[0]);
- const menuOpen = await waitFor(async () => getByTestId('delegationMenu'));
- const menuItems = menuOpen.querySelectorAll('[role="menuitem"]');
- expect(menuItems).toHaveLength(2);
- expect(menuItems[0]).toHaveTextContent(/deleghe.show/i);
- fireEvent.click(menuItems[0]);
- await waitFor(() => {
- const dialog = getByTestId('codeDialog');
- const arrayOfVerificationCode = arrayOfDelegates[0].verificationCode.split('');
- const codeInputs = dialog?.querySelectorAll('input');
- codeInputs?.forEach((input, index) => {
- expect(input).toHaveValue(arrayOfVerificationCode[index]);
- });
- });
- });
-
- it('revoke mandate', async () => {
- mock.onPatch(REVOKE_DELEGATION(arrayOfDelegates[0].mandateId)).reply(204);
- const { getAllByTestId, getByTestId } = render(, {
- preloadedState: {
- delegationsState: {
- delegations: {
- delegates: arrayOfDelegates,
- delegators: [],
- },
- },
- },
- });
- const menu = getAllByTestId('delegationMenuIcon');
- fireEvent.click(menu[0]);
- const menuOpen = await waitFor(async () => getByTestId('delegationMenu'));
- const menuItems = menuOpen.querySelectorAll('[role="menuitem"]');
- expect(menuItems).toHaveLength(2);
- expect(menuItems[1]).toHaveTextContent(/deleghe.revoke/i);
- fireEvent.click(menuItems[1]);
- const dialog = await waitFor(() => getByTestId('confirmationDialog'));
- expect(dialog).toBeInTheDocument();
- const dialogAction = within(dialog).getAllByTestId('dialogAction');
- // click on confirm button
- fireEvent.click(dialogAction[1]);
- await waitFor(() => {
- expect(mock.history.patch.length).toBe(1);
- expect(mock.history.patch[0].url).toContain(
- `mandate/api/v1/mandate/${arrayOfDelegates[0].mandateId}/revoke`
- );
- expect(dialog).not.toBeInTheDocument();
- });
- const table = getByTestId('delegatesTableDesktop');
- expect(table).toBeInTheDocument();
- const rows = getAllByTestId('delegatesBodyRowDesktop');
- expect(rows).toHaveLength(arrayOfDelegates.length - 1);
- // the index + 1 is because wie revoke the first delegation
- rows.forEach((row, index) => {
- expect(row).toHaveTextContent(arrayOfDelegates[index + 1].delegate?.displayName!);
- });
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegationDataSwitch.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegationDataSwitch.test.tsx
deleted file mode 100644
index 157f94b9e0..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegationDataSwitch.test.tsx
+++ /dev/null
@@ -1,123 +0,0 @@
-import { vi } from 'vitest';
-
-import { Row } from '@pagopa-pn/pn-commons';
-
-import { arrayOfDelegators } from '../../../__mocks__/Delegations.mock';
-import { render } from '../../../__test__/test-utils';
-import { DelegationColumnData } from '../../../models/Deleghe';
-import delegationToItem from '../../../utility/delegation.utility';
-import { DelegationStatus, getDelegationStatusKeyAndColor } from '../../../utility/status.utility';
-import DelegationDataSwitch from '../DelegationDataSwitch';
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
-}));
-
-const data = {
- ...(delegationToItem(arrayOfDelegators)[0] as Row),
-};
-
-describe('DowntimeLogDataSwitch Component', () => {
- it('renders component - name', () => {
- const { container } = render(
- {}} />
- );
- const regexp = new RegExp(`^${data.name}$`, 'ig');
- expect(container).toHaveTextContent(regexp);
- });
-
- it('renders component - startDate', () => {
- const { container } = render(
- {}}
- />
- );
- const regexp = new RegExp(`^${data.startDate}$`, 'ig');
- expect(container).toHaveTextContent(regexp);
- });
-
- it('renders component - endDate', () => {
- const { container } = render(
- {}} />
- );
- const regexp = new RegExp(`^${data.endDate}$`, 'ig');
- expect(container).toHaveTextContent(regexp);
- });
-
- it('renders component - visibilityIds', () => {
- const { container } = render(
- {}}
- />
- );
- const regexp = new RegExp(
- `^deleghe.table.notificationsFrom${data.visibilityIds.join()}$`,
- 'ig'
- );
- expect(container).toHaveTextContent(regexp);
- });
-
- it('renders component - status', () => {
- const { getByTestId } = render(
- {}} />
- );
- const button = getByTestId('acceptButton');
- expect(button).toBeInTheDocument();
- });
-
- it('renders component - status active', () => {
- const { key } = getDelegationStatusKeyAndColor(DelegationStatus.ACTIVE);
- const { container, queryByTestId } = render(
- {}}
- />
- );
- const regexp = new RegExp(`^${key}$`, 'ig');
- expect(container).toHaveTextContent(regexp);
- const button = queryByTestId('acceptButton');
- expect(button).not.toBeInTheDocument();
- });
-
- it('renders component - groups', () => {
- const groupData = {
- ...data,
- groups: [
- { id: 'group-1', name: 'Group1' },
- { id: 'group-2', name: 'Group2' },
- { id: 'group-3', name: 'Group3' },
- ],
- };
- const { container, queryByTestId } = render(
- {}}
- />
- );
- const regexp = new RegExp(`^${groupData.groups.map((g) => g.name).join('')}$`, 'ig');
- expect(container).toHaveTextContent(regexp);
- const button = queryByTestId('acceptButton');
- expect(button).not.toBeInTheDocument();
- });
-
- it('renders component - menu', () => {
- const { getByTestId } = render(
- {}} />
- );
- const menu = getByTestId('delegationMenuIcon');
- expect(menu).toBeInTheDocument();
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegationsElements.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegationsElements.a11y.test.tsx
deleted file mode 100644
index 4e0182d383..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegationsElements.a11y.test.tsx
+++ /dev/null
@@ -1,60 +0,0 @@
-import { vi } from 'vitest';
-
-import { axe, fireEvent, render } from '../../../__test__/test-utils';
-import { AcceptButton, Menu, OrganizationsList } from '../DelegationsElements';
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
-}));
-
-describe('DelegationElements - accessibility tests', () => {
- it('is Menu component accessible - delegators', async () => {
- const { getByTestId, queryByTestId, container } = render(
-
- );
- const menuIcon = getByTestId('delegationMenuIcon');
- const closedMenu = queryByTestId('delegationMenu');
- expect(closedMenu).toBeNull();
- fireEvent.click(menuIcon);
- const results = await axe(container);
- expect(results).toHaveNoViolations();
- });
-
- it('is Menu component accessible - delegates', async () => {
- const { getByTestId, queryByTestId, container } = render(
-
- );
- const menuIcon = getByTestId('delegationMenuIcon');
- const closedMenu = queryByTestId('delegationMenu');
- expect(closedMenu).toBeNull();
- fireEvent.click(menuIcon);
- const results = await axe(container);
- expect(results).toHaveNoViolations();
- });
-
- it('is OrganizationList component accessible - no organizations', async () => {
- const { container } = render();
- const results = await axe(container);
- expect(results).toHaveNoViolations();
- });
-
- it('is OrganizationList component accessible - with organizations', async () => {
- const { container } = render(
-
- );
- const results = await axe(container);
- expect(results).toHaveNoViolations();
- });
-
- it('is AcceptButton component accessible', async () => {
- const { container } = render( {}} />);
- const results = await axe(container);
- expect(results).toHaveNoViolations();
- });
-});
diff --git a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegationsElements.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegationsElements.test.tsx
deleted file mode 100644
index 0d08373fc9..0000000000
--- a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegationsElements.test.tsx
+++ /dev/null
@@ -1,402 +0,0 @@
-import MockAdapter from 'axios-mock-adapter';
-import { vi } from 'vitest';
-
-import { Row } from '@pagopa-pn/pn-commons';
-import { testAutocomplete } from '@pagopa-pn/pn-commons/src/test-utils';
-
-import { arrayOfDelegators } from '../../../__mocks__/Delegations.mock';
-import { fireEvent, render, screen, waitFor, within } from '../../../__test__/test-utils';
-import { apiClient } from '../../../api/apiClients';
-import {
- ACCEPT_DELEGATION,
- REJECT_DELEGATION,
- REVOKE_DELEGATION,
- UPDATE_DELEGATION,
-} from '../../../api/delegations/delegations.routes';
-import { DelegationColumnData, DelegationStatus } from '../../../models/Deleghe';
-import { AcceptButton, Menu, OrganizationsList } from '../DelegationsElements';
-
-vi.mock('react-i18next', () => ({
- // this mock makes sure any components using the translate hook can use it without a warning being shown
- useTranslation: () => ({
- t: (str: string) => str,
- }),
-}));
-
-const actionCbk = vi.fn();
-
-describe('DelegationElements', async () => {
- let mock: MockAdapter;
-
- beforeAll(() => {
- mock = new MockAdapter(apiClient);
- });
-
- afterEach(() => {
- mock.reset();
- vi.clearAllMocks();
- });
-
- afterAll(() => {
- mock.restore();
- });
-
- it('renders the Menu closed', () => {
- const { queryByTestId, getByTestId } = render();
- const menuIcon = getByTestId('delegationMenuIcon');
- const closedMenu = queryByTestId('delegationMenu');
- expect(menuIcon).not.toBeNull();
- expect(closedMenu).toBeNull();
- });
-
- it('opens the delegate Menu', () => {
- const { queryByTestId, getByTestId } = render();
- const menuIcon = getByTestId('delegationMenuIcon');
- const closedMenu = queryByTestId('delegationMenu');
- expect(closedMenu).toBeNull();
- fireEvent.click(menuIcon);
- const menu = getByTestId('delegationMenu');
- expect(menu).toHaveTextContent(/deleghe.revoke/i);
- expect(menu).toHaveTextContent(/deleghe.show/i);
- });
-
- it('opens the delegator Menu', () => {
- const { queryByTestId, getByTestId } = render();
- const menuIcon = getByTestId('delegationMenuIcon');
- const closedMenu = queryByTestId('delegationMenu');
- expect(closedMenu).toBeNull();
- fireEvent.click(menuIcon);
- const menu = getByTestId('delegationMenu');
- expect(menu).toHaveTextContent(/deleghe.reject/i);
- });
-
- it('renders the OrganizationList with all notifications label', () => {
- const { container } = render();
- expect(container).toHaveTextContent(/deleghe.table.allNotifications/i);
- });
-
- it('renders the OrganizationList with one organization', () => {
- const { container } = render(
-
- );
- expect(container).toHaveTextContent(/deleghe.table.notificationsFrom/i);
- expect(container).toHaveTextContent(/Bollate/i);
- expect(container).toHaveTextContent(/Comune di Milano/i);
- expect(container).toHaveTextContent(/Comune di Palermo/i);
- });
-
- it('renders the OrganizationList with multiple organizations and visibleItems set to 3', async () => {
- const { container, getByTestId } = render(
-
- );
- const organizationsList = getByTestId('custom-tooltip-indicator');
- expect(container).toHaveTextContent(/deleghe.table.notificationsFrom/i);
- expect(container).toHaveTextContent(/Bollate/i);
- expect(container).toHaveTextContent(/Milano/i);
- expect(container).toHaveTextContent(/Abbiategrasso/i);
- expect(container).toHaveTextContent(/\+1/i);
- expect(container).not.toHaveTextContent(/Malpesa/i);
- await waitFor(() => fireEvent.mouseOver(organizationsList));
- await waitFor(() => expect(screen.getByText(/Malpensa/i)).toBeInTheDocument());
- });
-
- it('renders the AcceptButton - open the modal', async () => {
- const { container, getByTestId } = render(
-
- );
- expect(container).toHaveTextContent(/deleghe.accept/i);
- const button = getByTestId('acceptButton');
- fireEvent.click(button);
- const codeDialog = await waitFor(() => screen.getByTestId('codeDialog'));
- expect(codeDialog).toBeInTheDocument();
- });
-
- it('renders the AcceptButton - close the modal', async () => {
- const { container, getByTestId } = render(
-
- );
- expect(container).toHaveTextContent(/deleghe.accept/i);
- const button = getByTestId('acceptButton');
- fireEvent.click(button);
- const codeDialog = await waitFor(() => screen.getByTestId('codeDialog'));
- expect(codeDialog).toBeInTheDocument();
- const cancelButton = getByTestId('codeCancelButton');
- fireEvent.click(cancelButton);
- await waitFor(() => expect(codeDialog).not.toBeInTheDocument());
- expect(actionCbk).not.toBeCalled();
- });
-
- it('renders the AcceptButton - accept the delegation', async () => {
- const groups = [
- { id: 'group-1', name: 'Group 1', status: 'ACTIVE' },
- { id: 'group-2', name: 'Group 2', status: 'ACTIVE' },
- ];
- mock.onPatch(ACCEPT_DELEGATION('4')).reply(204);
- const { container, getByTestId } = render(
- ,
- {
- preloadedState: {
- delegationsState: {
- groups,
- delegations: {
- delegators: arrayOfDelegators,
- },
- },
- },
- }
- );
- expect(container).toHaveTextContent(/deleghe.accept/i);
- const button = getByTestId('acceptButton');
- fireEvent.click(button);
- const codeDialog = await waitFor(() => screen.getByTestId('codeDialog'));
- expect(codeDialog).toBeInTheDocument();
- const codeConfirmButton = within(codeDialog).getByTestId('codeConfirmButton');
- expect(codeConfirmButton).toBeDisabled();
- // fill the code
- const codeInputs = codeDialog.querySelectorAll('input');
- codeInputs.forEach((input, index) => {
- fireEvent.change(input, { target: { value: index.toString() } });
- });
- expect(codeConfirmButton).toBeEnabled();
- // got to next step
- fireEvent.click(codeConfirmButton);
- const groupDialog = await waitFor(() => screen.getByTestId('groupDialog'));
- expect(groupDialog).toBeInTheDocument();
- // select groups to associate
- const associateGroupRadio = await waitFor(() =>
- within(groupDialog).getByTestId('associate-group')
- );
- fireEvent.click(associateGroupRadio);
- await testAutocomplete(groupDialog, 'groups', groups, true, 1);
- const groupConfirmButton = within(groupDialog).getByTestId('groupConfirmButton');
- fireEvent.click(groupConfirmButton);
- await waitFor(() => {
- expect(mock.history.patch.length).toBe(1);
- expect(mock.history.patch[0].url).toContain(ACCEPT_DELEGATION('4'));
- expect(JSON.parse(mock.history.patch[0].data)).toStrictEqual({
- groups: ['group-2'],
- verificationCode: '01234',
- });
- });
- expect(actionCbk).toBeCalledTimes(1);
- });
-
- it('check verificationCode for delegates', async () => {
- const verificationCode = '123456';
- const { getByTestId } = render(
-