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( - } - /> - ); - const menuIcon = getByTestId('delegationMenuIcon'); - - fireEvent.click(menuIcon); - const menu = getByTestId('delegationMenu'); - const show = menu.querySelectorAll('[role="menuitem"]')[0]; - fireEvent.click(show); - const showDialog = await waitFor(() => screen.getByTestId('codeDialog')); - const codeInputs = showDialog?.querySelectorAll('input'); - const arrayOfVerificationCode = verificationCode.split(''); - codeInputs?.forEach((input, index) => { - expect(input).toHaveValue(arrayOfVerificationCode[index]); - }); - const cancelButton = within(showDialog).getByTestId('codeCancelButton'); - fireEvent.click(cancelButton!); - await waitFor(() => { - expect(showDialog).not.toBeInTheDocument(); - }); - }); - - it('check revoke for delegatates', async () => { - mock.onPatch(REVOKE_DELEGATION('111')).reply(204); - const { getByTestId } = render( - } - onAction={actionCbk} - /> - ); - const menuIcon = getByTestId('delegationMenuIcon'); - fireEvent.click(menuIcon); - const menu = getByTestId('delegationMenu'); - const revoke = menu.querySelectorAll('[role="menuitem"]')[1]; - fireEvent.click(revoke); - const showDialog = await waitFor(() => screen.getByTestId('confirmationDialog')); - const revokeButton = within(showDialog).getAllByTestId('dialogAction')[1]; - fireEvent.click(revokeButton); - await waitFor(() => { - expect(mock.history.patch.length).toBe(1); - expect(mock.history.patch[0].url).toContain('mandate/api/v1/mandate/111/revoke'); - expect(showDialog).not.toBeInTheDocument(); - }); - expect(actionCbk).toBeCalledTimes(1); - }); - - it('check close confimationDialog', async () => { - const { getByTestId } = render( - } - /> - ); - const menuIcon = getByTestId('delegationMenuIcon'); - fireEvent.click(menuIcon); - const menu = getByTestId('delegationMenu'); - const revoke = menu.querySelectorAll('[role="menuitem"]')[1]; - fireEvent.click(revoke); - const showDialog = await waitFor(() => screen.getByTestId('confirmationDialog')); - const cancelButton = within(showDialog).getAllByTestId('dialogAction')[0]; - fireEvent.click(cancelButton!); - await waitFor(() => { - expect(showDialog).not.toBeInTheDocument(); - }); - }); - - it('check reject for delegator', async () => { - mock.onPatch(REJECT_DELEGATION('111')).reply(204); - const { getByTestId } = render( - } - /> - ); - const menuIcon = getByTestId('delegationMenuIcon'); - fireEvent.click(menuIcon); - const menu = getByTestId('delegationMenu'); - const reject = menu.querySelectorAll('[role="menuitem"]')[0]; - fireEvent.click(reject); - const showDialog = await waitFor(() => screen.getByTestId('confirmationDialog')); - const rejectButton = within(showDialog).getAllByTestId('dialogAction')[1]; - fireEvent.click(rejectButton); - await waitFor(() => { - expect(mock.history.patch.length).toBe(1); - expect(mock.history.patch[0].url).toContain('mandate/api/v1/mandate/111/reject'); - expect(showDialog).not.toBeInTheDocument(); - }); - }); - - it("doesn't show the update button - delegator", async () => { - const { getByTestId } = render( - - } - /> - ); - const menuIcon = getByTestId('delegationMenuIcon'); - fireEvent.click(menuIcon); - const menu = getByTestId('delegationMenu'); - const menuItems = menu.querySelectorAll('[role="menuitem"]'); - expect(menuItems).toHaveLength(1); - }); - - it('shows the update button and modal - delegator', async () => { - const groups = [ - { id: 'group-1', name: 'Group 1' }, - { id: 'group-2', name: 'Group 2' }, - { id: 'group-3', name: 'Group 3' }, - ]; - const { getByTestId } = render( - - } - />, - { - preloadedState: { - delegationsState: { - groups, - }, - }, - } - ); - const menuIcon = getByTestId('delegationMenuIcon'); - fireEvent.click(menuIcon); - const menu = getByTestId('delegationMenu'); - const menuItems = menu.querySelectorAll('[role="menuitem"]'); - expect(menuItems).toHaveLength(2); - const updateButton = menuItems[1]; - fireEvent.click(updateButton); - const updateDialog = await waitFor(() => screen.getByTestId('groupDialog')); - expect(updateDialog).toBeInTheDocument(); - const cancelButton = getByTestId('groupCancelButton'); - fireEvent.click(cancelButton); - await waitFor(() => expect(updateDialog).not.toBeInTheDocument()); - expect(actionCbk).not.toBeCalled(); - }); - - it('update groups - delegator', async () => { - const groups = [ - { id: 'group-1', name: 'Group 1', status: 'ACTIVE' }, - { id: 'group-2', name: 'Group 2', status: 'ACTIVE' }, - { id: 'group-3', name: 'Group 3', status: 'ACTIVE' }, - ]; - mock.onPatch(UPDATE_DELEGATION('4')).reply(204); - const { getByTestId } = render( - , - } as Row - } - onAction={actionCbk} - />, - { - preloadedState: { - delegationsState: { - groups, - delegations: { - delegators: arrayOfDelegators, - }, - }, - }, - } - ); - const menuIcon = getByTestId('delegationMenuIcon'); - fireEvent.click(menuIcon); - const menu = getByTestId('delegationMenu'); - const menuItems = menu.querySelectorAll('[role="menuitem"]'); - expect(menuItems).toHaveLength(2); - const updateButton = menuItems[1]; - fireEvent.click(updateButton); - const updateDialog = await waitFor(() => screen.getByTestId('groupDialog')); - expect(updateDialog).toBeInTheDocument(); - await testAutocomplete(updateDialog, 'groups', groups, true, 2); - const groupConfirmButton = within(updateDialog).getByTestId('groupConfirmButton'); - fireEvent.click(groupConfirmButton); - await waitFor(() => { - expect(mock.history.patch.length).toBe(1); - expect(mock.history.patch[0].url).toContain('/mandate/api/v1/mandate/4/update'); - expect(JSON.parse(mock.history.patch[0].data)).toStrictEqual({ - groups: ['group-2', 'group-3'], - }); - }); - expect(actionCbk).toBeCalledTimes(1); - }); -}); diff --git a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegationsOfTheCompany.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegationsOfTheCompany.a11y.test.tsx deleted file mode 100644 index 29d1c0b30e..0000000000 --- a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegationsOfTheCompany.a11y.test.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { vi } from 'vitest'; - -import { arrayOfDelegators } from '../../../__mocks__/Delegations.mock'; -import { axe, render } from '../../../__test__/test-utils'; -import DelegationsOfTheCompany from '../DelegationsOfTheCompany'; - -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('Delegators Component - accessibility tests', () => { - it('is Delegator component accessible', async () => { - const result = render(, { - preloadedState: { - delegationsState: { - delegations: { - delegators: arrayOfDelegators, - }, - pagination: { - nextPagesKey: [], - moreResult: false, - }, - groups: [], - delegatorsNames: [], - }, - }, - }); - const results = await axe(result.container); - expect(results).toHaveNoViolations(); - }); -}); diff --git a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegationsOfTheCompany.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegationsOfTheCompany.test.tsx deleted file mode 100644 index ee3b3d66af..0000000000 --- a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/DelegationsOfTheCompany.test.tsx +++ /dev/null @@ -1,481 +0,0 @@ -import MockAdapter from 'axios-mock-adapter'; -import { ReactNode } from 'react'; -import { vi } from 'vitest'; - -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, - DELEGATIONS_BY_DELEGATE, - REJECT_DELEGATION, - UPDATE_DELEGATION, -} from '../../../api/delegations/delegations.routes'; -import { DelegationStatus } from '../../../models/Deleghe'; -import DelegationsOfTheCompany from '../DelegationsOfTheCompany'; - -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 && props.components!.map((c) => c)} - - ), -})); - -export async function testMultiSelect( - form: HTMLElement, - elementName: string, - options: Array<{ id: string; name: string }>, - optToSelect: number, - mustBeOpened: boolean -) { - if (mustBeOpened) { - const selectButton = form.querySelector(`div[id="${elementName}"]`); - fireEvent.mouseDown(selectButton!); - } - const selectOptionsContainer = await screen.findByRole('presentation'); - expect(selectOptionsContainer).toBeInTheDocument(); - const selectOptionsList = await within(selectOptionsContainer).findByRole('listbox'); - expect(selectOptionsList).toBeInTheDocument(); - const selectOptionsListItems = await within(selectOptionsList).findAllByRole('option'); - expect(selectOptionsListItems).toHaveLength(options.length); - selectOptionsListItems.forEach((opt, index) => { - expect(opt).toHaveTextContent(options[index].name); - }); - fireEvent.click(selectOptionsListItems[optToSelect]); -} - -const initialState = { - delegations: { - delegators: [], - delegates: [], - }, - pagination: { - nextPagesKey: [], - moreResult: false, - }, - groups: [], - filters: { - size: 10, - page: 0, - }, -}; - -describe('DelegationsOfTheCompany Component', async () => { - let mock: MockAdapter; - - beforeAll(() => { - mock = new MockAdapter(apiClient); - }); - - afterEach(() => { - mock.reset(); - }); - - afterAll(() => { - mock.restore(); - }); - - it('renders the empty state', () => { - const { container } = render(); - expect(container).toHaveTextContent(/deleghe.delegatorsTitle/i); - expect(container).toHaveTextContent(/deleghe.no_delegators/i); - expect(container).not.toHaveTextContent(/deleghe.table.name/i); - expect(container).not.toHaveTextContent(/deleghe.table.delegationStart/i); - expect(container).not.toHaveTextContent(/deleghe.table.delegationEnd/i); - expect(container).not.toHaveTextContent(/deleghe.table.permissions/i); - expect(container).not.toHaveTextContent(/deleghe.table.groups/i); - expect(container).not.toHaveTextContent(/deleghe.table.status/i); - }); - - it('renders the table', () => { - const { container, getByTestId, getAllByTestId } = render(, { - preloadedState: { - delegationsState: { - ...initialState, - delegations: { - delegators: arrayOfDelegators, - }, - }, - }, - }); - - expect(container).not.toHaveTextContent(/deleghe.no_delegators/i); - expect(container).toHaveTextContent(/deleghe.table.name/i); - expect(container).toHaveTextContent(/deleghe.table.delegationStart/i); - expect(container).toHaveTextContent(/deleghe.table.delegationEnd/i); - expect(container).toHaveTextContent(/deleghe.table.permissions/i); - expect(container).toHaveTextContent(/deleghe.table.groups/i); - expect(container).toHaveTextContent(/deleghe.table.status/i); - const table = getByTestId('delegationsDesktop'); - expect(table).toBeInTheDocument(); - const rows = getAllByTestId('delegationsBodyRowDesktop'); - expect(rows).toHaveLength(arrayOfDelegators.length); - rows.forEach((row, index) => { - expect(row).toHaveTextContent(arrayOfDelegators[index].delegator?.displayName!); - }); - }); - - it('filters the results', async () => { - mock - .onPost(DELEGATIONS_BY_DELEGATE({ size: 10, nextPageKey: undefined }), { - groups: ['group-2'], - status: [DelegationStatus.ACTIVE, DelegationStatus.REJECTED], - }) - .reply(200, { - resultsPage: [arrayOfDelegators[1]], - moreResult: false, - nextPagesKey: [], - }); - const groups = [ - { - id: 'group-1', - name: 'Group 1', - status: 'ACTIVE', - }, - { - id: 'group-2', - name: 'Group 2', - status: 'ACTIVE', - }, - ]; - const status = [ - { id: DelegationStatus.ACTIVE, name: 'deleghe.table.active' }, - { id: DelegationStatus.PENDING, name: 'deleghe.table.pending' }, - { id: DelegationStatus.REJECTED, name: 'deleghe.table.rejected' }, - ]; - const { container, getAllByTestId } = render(, { - preloadedState: { - delegationsState: { - ...initialState, - delegations: { - delegators: arrayOfDelegators, - }, - groups, - }, - }, - }); - - const form = container.querySelector('form'); - const cancelButton = within(form!).getByTestId('cancelButton'); - const confirmButton = within(form!).getByTestId('confirmButton'); - expect(cancelButton).toBeInTheDocument(); - expect(cancelButton).toBeDisabled(); - expect(confirmButton).toBeInTheDocument(); - expect(confirmButton).toBeDisabled(); - await testAutocomplete(form!, 'groups', groups, true, 1, false); - await testMultiSelect(form!, 'status', status, 0, true); - await testMultiSelect(form!, 'status', status, 2, false); - expect(confirmButton).toBeEnabled(); - fireEvent.click(confirmButton); - await waitFor(() => { - expect(mock.history.post.length).toBe(1); - expect(mock.history.post[0].url).toContain('mandate/api/v1/mandates-by-delegate?size=10'); - expect(JSON.parse(mock.history.post[0].data)).toStrictEqual({ - groups: ['group-2'], - status: [DelegationStatus.ACTIVE, DelegationStatus.REJECTED], - }); - }); - const rows = getAllByTestId('delegationsBodyRowDesktop'); - expect(rows).toHaveLength(1); - expect(rows[0]).toHaveTextContent(arrayOfDelegators[1].delegator?.displayName!); - expect(cancelButton).toBeEnabled(); - }); - - it('filters the results and show empty state', async () => { - mock - .onPost(DELEGATIONS_BY_DELEGATE({ size: 10, nextPageKey: undefined }), { - groups: ['group-2'], - status: [DelegationStatus.ACTIVE, DelegationStatus.REJECTED], - }) - .reply(200, { - resultsPage: [], - moreResult: false, - nextPagesKey: [], - }); - mock.onPost(DELEGATIONS_BY_DELEGATE({ size: 10, nextPageKey: undefined })).reply(200, { - resultsPage: arrayOfDelegators, - moreResult: false, - nextPagesKey: [], - }); - const groups = [ - { - id: 'group-1', - name: 'Group 1', - status: 'ACTIVE', - }, - { - id: 'group-2', - name: 'Group 2', - status: 'ACTIVE', - }, - ]; - const status = [ - { id: DelegationStatus.ACTIVE, name: 'deleghe.table.active' }, - { id: DelegationStatus.PENDING, name: 'deleghe.table.pending' }, - { id: DelegationStatus.REJECTED, name: 'deleghe.table.rejected' }, - ]; - const { container, queryByTestId, getByTestId } = render(, { - preloadedState: { - delegationsState: { - ...initialState, - delegations: { - delegators: arrayOfDelegators, - }, - groups, - }, - }, - }); - const form = container.querySelector('form'); - const cancelButton = within(form!).getByTestId('cancelButton'); - const confirmButton = within(form!).getByTestId('confirmButton'); - expect(cancelButton).toBeInTheDocument(); - expect(cancelButton).toBeDisabled(); - expect(confirmButton).toBeInTheDocument(); - expect(confirmButton).toBeDisabled(); - await testAutocomplete(form!, 'groups', groups, true, 1, false); - await testMultiSelect(form!, 'status', status, 0, true); - await testMultiSelect(form!, 'status', status, 2, false); - expect(confirmButton).toBeEnabled(); - fireEvent.click(confirmButton); - await waitFor(() => { - expect(mock.history.post.length).toBe(1); - expect(mock.history.post[0].url).toContain('mandate/api/v1/mandates-by-delegate?size=10'); - expect(JSON.parse(mock.history.post[0].data)).toStrictEqual({ - groups: ['group-2'], - status: [DelegationStatus.ACTIVE, DelegationStatus.REJECTED], - }); - }); - let table = queryByTestId('delegationsDesktop'); - expect(table).not.toBeInTheDocument(); - expect(container).toHaveTextContent(/deleghe.no_delegators_after_filters/i); - // clicks on empty state action - const button = getByTestId('link-remove-filters'); - fireEvent.click(button); - await waitFor(() => { - expect(mock.history.post.length).toBe(2); - expect(mock.history.post[0].url).toContain('mandate/api/v1/mandates-by-delegate?size=10'); - }); - expect(container).not.toHaveTextContent(/deleghe.no_delegators_after_filters/i); - table = getByTestId('delegationsDesktop'); - expect(table).toBeInTheDocument(); - }); - - it('change pagination size', async () => { - mock.onPost(DELEGATIONS_BY_DELEGATE({ size: 20 })).reply(200, { - resultsPage: [arrayOfDelegators[1]], - moreResult: false, - nextPagesKey: [], - }); - const { getAllByTestId, getByTestId } = render(, { - preloadedState: { - delegationsState: { - ...initialState, - delegations: { - delegators: [arrayOfDelegators[0]], - }, - }, - }, - }); - - let rows = getAllByTestId('delegationsBodyRowDesktop'); - expect(rows).toHaveLength(1); - expect(rows[0]).toHaveTextContent(arrayOfDelegators[0].delegator?.displayName!); - const itemsPerPageSelector = getByTestId('itemsPerPageSelector'); - const button = itemsPerPageSelector.querySelector('button'); - expect(button).toHaveTextContent(/10/i); - fireEvent.click(button!); - const itemsPerPageListContainer = await waitFor(() => screen.queryByRole('presentation')); - expect(itemsPerPageListContainer).toBeInTheDocument(); - const itemsPerPageList = screen.getAllByRole('menuitem'); - expect(itemsPerPageList).toHaveLength(3); - fireEvent.click(itemsPerPageList[1]!); - await waitFor(() => { - expect(button).toHaveTextContent(/20/i); - expect(mock.history.post.length).toBe(1); - expect(mock.history.post[0].url).toContain('mandate/api/v1/mandates-by-delegate?size=20'); - }); - rows = getAllByTestId('delegationsBodyRowDesktop'); - expect(rows).toHaveLength(1); - expect(rows[0]).toHaveTextContent(arrayOfDelegators[1].delegator?.displayName!); - }); - - it('change pagination page', async () => { - mock.onPost(DELEGATIONS_BY_DELEGATE({ size: 10, nextPageKey: 'page-1' })).reply(200, { - resultsPage: [arrayOfDelegators[1]], - moreResult: false, - nextPagesKey: [], - }); - const { getAllByTestId, getByTestId } = render(, { - preloadedState: { - delegationsState: { - ...initialState, - delegations: { - delegators: [arrayOfDelegators[0]], - }, - pagination: { - nextPagesKey: ['page-1', 'page-2', 'page-3'], - moreResult: false, - }, - }, - }, - }); - let rows = getAllByTestId('delegationsBodyRowDesktop'); - expect(rows).toHaveLength(1); - expect(rows[0]).toHaveTextContent(arrayOfDelegators[0].delegator?.displayName!); - const pageSelector = getByTestId('pageSelector'); - const pageButtons = pageSelector.querySelectorAll('button'); - // depends on mui pagination - // for 10 pages we have: < 1 2 3 > - expect(pageButtons).toHaveLength(5); - expect(pageButtons[1]).toHaveTextContent(/1/i); - expect(pageButtons[2]).toHaveTextContent(/2/i); - expect(pageButtons[3]).toHaveTextContent(/3/i); - fireEvent.click(pageButtons[2]); - await waitFor(() => { - expect(mock.history.post.length).toBe(1); - expect(mock.history.post[0].url).toContain( - 'mandate/api/v1/mandates-by-delegate?size=10&nextPageKey=page-1' - ); - }); - rows = getAllByTestId('delegationsBodyRowDesktop'); - expect(rows).toHaveLength(1); - expect(rows[0]).toHaveTextContent(arrayOfDelegators[1].delegator?.displayName!); - }); - - it('test reject delegation', async () => { - mock.onPatch(REJECT_DELEGATION(arrayOfDelegators[0].mandateId)).reply(204); - const { getAllByTestId, getByTestId } = render(, { - preloadedState: { - delegationsState: { - ...initialState, - delegations: { - delegators: arrayOfDelegators, - delegates: [], - }, - }, - }, - }); - const menu = getAllByTestId('delegationMenuIcon'); - fireEvent.click(menu[0]); - const menuOpen = await waitFor(async () => getByTestId('delegationMenu')); - const menuItems = menuOpen.querySelectorAll('[role="menuitem"]'); - expect(menuItems).toHaveLength(1); - expect(menuItems[0]).toHaveTextContent(/deleghe.reject/i); - fireEvent.click(menuItems[0]); - 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/${arrayOfDelegators[0].mandateId}/reject` - ); - expect(dialog).not.toBeInTheDocument(); - }); - const rows = getAllByTestId('delegationsBodyRowDesktop'); - expect(rows).toHaveLength(arrayOfDelegators.length - 1); - // the index + 1 is because we reject the first delegator - rows.forEach((row, index) => { - expect(row).toHaveTextContent(arrayOfDelegators[index + 1].delegator?.displayName!); - }); - }); - - it('test accept delegation', async () => { - mock.onPatch(ACCEPT_DELEGATION(arrayOfDelegators[0].mandateId)).reply(204); - const { getByTestId } = render(, { - preloadedState: { - delegationsState: { - ...initialState, - delegations: { - delegators: arrayOfDelegators, - delegates: [], - }, - }, - }, - }); - const table = getByTestId('delegationsDesktop'); - expect(table).toBeInTheDocument(); - const acceptButton = within(table).getByTestId('acceptButton'); - expect(acceptButton).toBeInTheDocument(); - fireEvent.click(acceptButton); - const dialog = await waitFor(() => getByTestId('codeDialog')); - expect(dialog).toBeInTheDocument(); - // fill the code - const codeInputs = dialog.querySelectorAll('input'); - codeInputs.forEach((input, index) => { - fireEvent.change(input, { target: { value: index.toString() } }); - }); - const codeConfirmButton = within(dialog).getByTestId('codeConfirmButton'); - // click on confirm button - fireEvent.click(codeConfirmButton); - await waitFor(() => { - expect(mock.history.patch.length).toBe(1); - expect(mock.history.patch[0].url).toContain( - `mandate/api/v1/mandate/${arrayOfDelegators[0].mandateId}/accept` - ); - expect(JSON.parse(mock.history.patch[0].data)).toStrictEqual({ - groups: [], - verificationCode: '01234', - }); - expect(dialog).not.toBeInTheDocument(); - }); - expect(acceptButton).not.toBeInTheDocument(); - }); - - it('test update delegation', async () => { - const groups = [ - { id: 'group-1', name: 'Group 1', status: 'ACTIVE' }, - { id: 'group-2', name: 'Group 2', status: 'ACTIVE' }, - { id: 'group-3', name: 'Group 3', status: 'ACTIVE' }, - ]; - mock.onPatch(UPDATE_DELEGATION(arrayOfDelegators[1].mandateId)).reply(204); - const { getByTestId, getAllByTestId } = render(, { - preloadedState: { - delegationsState: { - ...initialState, - delegations: { - delegators: arrayOfDelegators, - delegates: [], - }, - groups, - }, - }, - }); - let rows = getAllByTestId('delegationsBodyRowDesktop'); - expect(rows[1]).not.toHaveTextContent('Group 3'); - const menu = within(rows[1]).getByTestId('delegationMenuIcon'); - fireEvent.click(menu); - const menuOpen = await waitFor(async () => getByTestId('delegationMenu')); - const menuItems = menuOpen.querySelectorAll('[role="menuitem"]'); - expect(menuItems).toHaveLength(2); - expect(menuItems[1]).toHaveTextContent(/deleghe.update/i); - fireEvent.click(menuItems[1]); - const updateDialog = await waitFor(() => screen.getByTestId('groupDialog')); - expect(updateDialog).toBeInTheDocument(); - const associateGroupRadio = within(updateDialog).getByTestId('associate-group'); - fireEvent.click(associateGroupRadio); - await testAutocomplete(updateDialog, 'groups', groups, true, 2); - const groupConfirmButton = within(updateDialog).getByTestId('groupConfirmButton'); - fireEvent.click(groupConfirmButton); - await waitFor(() => { - expect(mock.history.patch.length).toBe(1); - expect(mock.history.patch[0].url).toContain( - `/mandate/api/v1/mandate/${arrayOfDelegators[1].mandateId}/update` - ); - expect(JSON.parse(mock.history.patch[0].data)).toStrictEqual({ - groups: ['group-3'], - }); - }); - rows = getAllByTestId('delegationsBodyRowDesktop'); - expect(rows[1]).toHaveTextContent('Group 3'); - }); -}); diff --git a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/VerificationCodeComponent.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/VerificationCodeComponent.a11y.test.tsx deleted file mode 100644 index 796ed62f1a..0000000000 --- a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/VerificationCodeComponent.a11y.test.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { axe, render } from '../../../__test__/test-utils'; -import VerificationCodeComponent from '../VerificationCodeComponent'; - -describe('VerificationCodeComponent - accessibility tests', () => { - it('is Verification Code component accessible', async () => { - const fiveDigits = '12345'; - const result = render(); - const results = await axe(result.container); - expect(results).toHaveNoViolations(); - }); -}); diff --git a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/VerificationCodeComponent.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/VerificationCodeComponent.test.tsx deleted file mode 100644 index 29d7da508e..0000000000 --- a/packages/pn-personagiuridica-webapp/src/components/Deleghe/__test__/VerificationCodeComponent.test.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { render } from '../../../__test__/test-utils'; -import VerificationCodeComponent from '../VerificationCodeComponent'; - -describe('VerificationCodeComponent', () => { - it('renders the component and checks the digits', () => { - const fiveDigits = '12345'; - const { queryAllByTestId } = render(); - const digitsElements = queryAllByTestId('codeDigit'); - const codes = fiveDigits.split(''); - expect(digitsElements).toHaveLength(fiveDigits.length); - digitsElements.forEach((code, index) => { - expect(code).toHaveTextContent(codes[index]); - }); - }); -}); diff --git a/packages/pn-personagiuridica-webapp/src/components/DomicileBanner/__test__/DomicileBanner.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/DomicileBanner/__test__/DomicileBanner.a11y.test.tsx deleted file mode 100644 index 427ad5092f..0000000000 --- a/packages/pn-personagiuridica-webapp/src/components/DomicileBanner/__test__/DomicileBanner.a11y.test.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import { vi } from 'vitest'; - -import { axe, render } from '../../../__test__/test-utils'; -import DomicileBanner from '../DomicileBanner'; - -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('DomicileBanner component - accessibility tests', () => { - it('is Domicile Banner component accessible', async () => { - const result = render(); - const results = await axe(result.container); - expect(results).toHaveNoViolations(); - }); -}); diff --git a/packages/pn-personagiuridica-webapp/src/components/LoadingPageWrapper/__test__/LoadingPageWrapper.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/LoadingPageWrapper/__test__/LoadingPageWrapper.a11y.test.tsx deleted file mode 100644 index 790bf49e9d..0000000000 --- a/packages/pn-personagiuridica-webapp/src/components/LoadingPageWrapper/__test__/LoadingPageWrapper.a11y.test.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { axe, render } from '../../../__test__/test-utils'; -import LoadingPageWrapper from '../LoadingPageWrapper'; - -describe('LoadingPageWrapper component - accessibility tests', () => { - it('is component accessible', async () => { - const result = render(test); - const results = await axe(result.container); - expect(results).toHaveNoViolations(); - }); - - it('is component accessible - spinner', async () => { - const result = render(test, { - preloadedState: { - appState: { - loading: { - result: true, - }, - }, - }, - }); - const results = await axe(result.container); - expect(results).toHaveNoViolations(); - }); -}); diff --git a/packages/pn-personagiuridica-webapp/src/components/Notifications/__test__/DesktopNotifications.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Notifications/__test__/DesktopNotifications.a11y.test.tsx deleted file mode 100644 index a2e8881d91..0000000000 --- a/packages/pn-personagiuridica-webapp/src/components/Notifications/__test__/DesktopNotifications.a11y.test.tsx +++ /dev/null @@ -1,88 +0,0 @@ -import { vi } from 'vitest'; - -import { formatToTimezoneString, tenYearsAgo, today } from '@pagopa-pn/pn-commons'; - -import { notificationsToFe } from '../../../__mocks__/Notifications.mock'; -import { RenderResult, act, axe, render } from '../../../__test__/test-utils'; -import DesktopNotifications from '../DesktopNotifications'; - -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, - i18n: { language: 'it' }, - }), -})); - -describe('DesktopNotifications Component - accessibility tests', () => { - it('does not have basic accessibility issues', async () => { - let result: RenderResult | undefined; - await act(async () => { - result = await render(); - }); - - if (result) { - const res = await axe(result.container); - expect(res).toHaveNoViolations(); - } else { - fail('render() returned undefined!'); - } - }, 15000); - - it('does not have basic accessibility issues - delegate access', async () => { - let result: RenderResult | undefined; - await act(async () => { - result = await render( - - ); - }); - - if (result) { - const res = await axe(result.container); - expect(res).toHaveNoViolations(); - } else { - fail('render() returned undefined!'); - } - }, 15000); - - it('does not have basic accessibility issues (empty notifications)', async () => { - // eslint-disable-next-line functional/no-let - let result: RenderResult | undefined; - await act(async () => { - result = await render(); - }); - - if (result) { - const res = await axe(result.container); - expect(res).toHaveNoViolations(); - } else { - fail('render() returned undefined!'); - } - }, 15000); - - it('does not have basic accessibility issues (empty notifications after filter)', async () => { - let result: RenderResult | undefined; - await act(async () => { - result = render(, { - preloadedState: { - dashboardState: { - filters: { - startDate: formatToTimezoneString(tenYearsAgo), - endDate: formatToTimezoneString(today), - iunMatch: 'ABCD-EFGH-ILMN-123456-A-1', - mandateId: undefined, - }, - }, - }, - }); - }); - // the rerendering must be done to take the useRef updates - result!.rerender(); - if (result) { - const res = await axe(result.container); - expect(res).toHaveNoViolations(); - } else { - fail('render() returned undefined!'); - } - }, 15000); -}); diff --git a/packages/pn-personagiuridica-webapp/src/components/Notifications/__test__/FilterNotifications.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Notifications/__test__/FilterNotifications.a11y.test.tsx deleted file mode 100644 index 4d5e1239db..0000000000 --- a/packages/pn-personagiuridica-webapp/src/components/Notifications/__test__/FilterNotifications.a11y.test.tsx +++ /dev/null @@ -1,65 +0,0 @@ -import { vi } from 'vitest'; - -import { createMatchMedia } from '@pagopa-pn/pn-commons/src/test-utils'; - -import { - RenderResult, - act, - axe, - fireEvent, - render, - screen, - waitFor, -} from '../../../__test__/test-utils'; -import FilterNotifications from '../FilterNotifications'; - -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, - i18n: { language: 'it' }, - }), -})); - -describe('Filter Notifications Table Component - accessibility tests', () => { - const original = window.matchMedia; - - afterAll(() => { - window.matchMedia = original; - }); - - it('does not have basic accessibility issues', 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!'); - } - }, 15000); - - it('does not have basic accessibility issues - mobile', async () => { - window.matchMedia = createMatchMedia(800); - let result: RenderResult | undefined; - - await act(async () => { - result = render(); - }); - - const button = result!.getByTestId('dialogToggleButton'); - fireEvent.click(button); - - const dialogForm = await waitFor(() => screen.getByTestId('filter-form')); - expect(dialogForm).toBeInTheDocument(); - - if (dialogForm) { - const results = await axe(dialogForm); - expect(results).toHaveNoViolations(); - } - }, 15000); -}); diff --git a/packages/pn-personagiuridica-webapp/src/components/Notifications/__test__/MobileNotifications.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Notifications/__test__/MobileNotifications.a11y.test.tsx deleted file mode 100644 index 2cd55078ad..0000000000 --- a/packages/pn-personagiuridica-webapp/src/components/Notifications/__test__/MobileNotifications.a11y.test.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import { vi } from 'vitest'; - -import { formatToTimezoneString, tenYearsAgo, today } from '@pagopa-pn/pn-commons'; - -import { notificationsToFe } from '../../../__mocks__/Notifications.mock'; -import { RenderResult, act, axe, render } from '../../../__test__/test-utils'; -import MobileNotifications from '../MobileNotifications'; - -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, - i18n: { language: 'it' }, - }), -})); - -describe('MobileNotifications Component - accessibility tests', () => { - it('does not have basic accessibility issues', async () => { - let result: RenderResult | undefined; - await act(async () => { - result = await render(); - }); - - if (result) { - const res = await axe(result.container); - expect(res).toHaveNoViolations(); - } else { - fail('render() returned undefined!'); - } - }, 15000); - - it('does not have basic accessibility issues - delegate access', async () => { - let result: RenderResult | undefined; - await act(async () => { - result = await render( - - ); - }); - - if (result) { - const res = await axe(result.container); - expect(res).toHaveNoViolations(); - } else { - fail('render() returned undefined!'); - } - }, 15000); - - it('does not have basic accessibility issues (empty notifications)', async () => { - let result: RenderResult | undefined; - await act(async () => { - result = await render(); - }); - - if (result) { - const res = await axe(result.container); - expect(res).toHaveNoViolations(); - } else { - fail('render() returned undefined!'); - } - }, 15000); - - it('does not have basic accessibility issues (empty notifications after filter)', async () => { - let result: RenderResult | undefined; - await act(async () => { - result = render(, { - preloadedState: { - dashboardState: { - filters: { - startDate: formatToTimezoneString(tenYearsAgo), - endDate: formatToTimezoneString(today), - iunMatch: 'ABCD-EFGH-ILMN-123456-A-1', - }, - }, - }, - }); - }); - // the rerendering must be done to take the useRef updates - result!.rerender(); - if (result) { - const res = await axe(result.container); - expect(res).toHaveNoViolations(); - } else { - fail('render() returned undefined!'); - } - }, 15000); -}); diff --git a/packages/pn-personagiuridica-webapp/src/components/Party/__test__/DropDownParty.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/components/Party/__test__/DropDownParty.a11y.test.tsx deleted file mode 100644 index 70d52ceeb1..0000000000 --- a/packages/pn-personagiuridica-webapp/src/components/Party/__test__/DropDownParty.a11y.test.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import { axe, render } from '../../../__test__/test-utils'; -import DropDownPartyMenuItem from '../DropDownParty'; - -describe('DropDownParty Component - accessibility tests', () => { - it('is DropDownParty component accessible', async () => { - const result = render(); - const results = await axe(result.container); - expect(results).toHaveNoViolations(); - }); -}); diff --git a/packages/pn-personagiuridica-webapp/src/pages/__test__/Contacts.page.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/pages/__test__/Contacts.page.a11y.test.tsx deleted file mode 100644 index 85c74d9587..0000000000 --- a/packages/pn-personagiuridica-webapp/src/pages/__test__/Contacts.page.a11y.test.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import MockAdapter from 'axios-mock-adapter'; -import { vi } from 'vitest'; - -import { AppResponseMessage, ResponseEventDispatcher } from '@pagopa-pn/pn-commons'; - -import { digitalAddresses } from '../../../../pn-personafisica-webapp/src/__mocks__/Contacts.mock'; -import { RenderResult, act, axe, render } from '../../__test__/test-utils'; -import { apiClient } from '../../api/apiClients'; -import { CONTACTS_LIST } from '../../api/contacts/contacts.routes'; -import Contacts from '../Contacts.page'; - -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('Contacts page - accessibility tests', async () => { - let mock: MockAdapter; - let result: RenderResult; - - beforeAll(() => { - mock = new MockAdapter(apiClient); - }); - - afterEach(() => { - mock.reset(); - }); - - afterAll(() => { - mock.restore(); - }); - - it('is contact page accessible - no contacts', async () => { - mock.onGet(CONTACTS_LIST()).reply(200, []); - await act(async () => { - result = render(); - }); - - if (result) { - const { container } = result; - const results = await axe(container); - expect(results).toHaveNoViolations(); - } else { - fail('render() returned undefined!'); - } - }, 15000); - - it('is contact page accessible - contacts', async () => { - mock.onGet(CONTACTS_LIST()).reply(200, digitalAddresses); - await act(async () => { - result = render(); - }); - - if (result) { - const { container } = result; - const results = await axe(container); - expect(results).toHaveNoViolations(); - } else { - fail('render() returned undefined!'); - } - }, 15000); - - it('is contact page accessible - API error', async () => { - mock.onGet(CONTACTS_LIST()).reply(500); - await act(async () => { - result = render( - <> - - - - - ); - }); - - if (result) { - const { container } = result; - const results = await axe(container); - expect(results).toHaveNoViolations(); - } else { - fail('render() returned undefined!'); - } - }, 15000); -}); diff --git a/packages/pn-personagiuridica-webapp/src/pages/__test__/Deleghe.page.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/pages/__test__/Deleghe.page.a11y.test.tsx deleted file mode 100644 index 6a43097e91..0000000000 --- a/packages/pn-personagiuridica-webapp/src/pages/__test__/Deleghe.page.a11y.test.tsx +++ /dev/null @@ -1,90 +0,0 @@ -import MockAdapter from 'axios-mock-adapter'; -import { vi } from 'vitest'; - -import { userResponse } from '../../__mocks__/Auth.mock'; -import { arrayOfDelegates, arrayOfDelegators } from '../../__mocks__/Delegations.mock'; -import { RenderResult, act, axe, render } from '../../__test__/test-utils'; -import { apiClient } from '../../api/apiClients'; -import { - DELEGATIONS_BY_DELEGATE, - DELEGATIONS_BY_DELEGATOR, -} from '../../api/delegations/delegations.routes'; -import Deleghe from '../Deleghe.page'; - -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('Deleghe page - accessibility tests', async () => { - let result: RenderResult; - let mock: MockAdapter; - - beforeAll(() => { - mock = new MockAdapter(apiClient); - }); - - afterEach(() => { - mock.reset(); - }); - - afterAll(() => { - mock.restore(); - }); - - it('is deleghe page accessible - no data', async () => { - mock.onGet(DELEGATIONS_BY_DELEGATOR()).reply(200, []); - mock.onPost(DELEGATIONS_BY_DELEGATE({ size: 10 })).reply(200, { - resultsPage: [], - nextPagesKey: [], - moreResult: false, - }); - await act(async () => { - result = render(, { preloadedState: { userState: { user: userResponse } } }); - }); - if (result) { - const { container } = result; - const results = await axe(container); - expect(results).toHaveNoViolations(); - } else { - fail('render() returned undefined!'); - } - }); - - it('is deleghe page accessible - with data', async () => { - mock.onGet(DELEGATIONS_BY_DELEGATOR()).reply(200, arrayOfDelegates); - mock.onPost(DELEGATIONS_BY_DELEGATE({ size: 10 })).reply(200, { - resultsPage: arrayOfDelegators, - nextPagesKey: [], - moreResult: false, - }); - await act(async () => { - result = render(, { preloadedState: { userState: { user: userResponse } } }); - }); - if (result) { - const { container } = result; - const results = await axe(container); - expect(results).toHaveNoViolations(); - } else { - fail('render() returned undefined!'); - } - }); - - it('is deleghe page accessible - with data and user with groups', async () => { - mock.onGet(DELEGATIONS_BY_DELEGATOR()).reply(200, arrayOfDelegates); - await act(async () => { - result = render(, { - preloadedState: { userState: { user: { ...userResponse, hasGroup: true } } }, - }); - }); - if (result) { - const { container } = result; - const results = await axe(container); - expect(results).toHaveNoViolations(); - } else { - fail('render() returned undefined!'); - } - }); -}); diff --git a/packages/pn-personagiuridica-webapp/src/pages/__test__/NotificationDetail.page.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/pages/__test__/NotificationDetail.page.a11y.test.tsx deleted file mode 100644 index 5aaf61a299..0000000000 --- a/packages/pn-personagiuridica-webapp/src/pages/__test__/NotificationDetail.page.a11y.test.tsx +++ /dev/null @@ -1,98 +0,0 @@ -import MockAdapter from 'axios-mock-adapter'; -import { vi } from 'vitest'; - -import { DOWNTIME_HISTORY } from '@pagopa-pn/pn-commons'; - -import { downtimesDTO } from '../../__mocks__/AppStatus.mock'; -import { userResponse } from '../../__mocks__/Auth.mock'; -import { arrayOfDelegators } from '../../__mocks__/Delegations.mock'; -import { paymentInfo } from '../../__mocks__/ExternalRegistry.mock'; -import { notificationDTO } from '../../__mocks__/NotificationDetail.mock'; -import { RenderResult, act, axe, render } from '../../__test__/test-utils'; -import { apiClient } from '../../api/apiClients'; -import { - NOTIFICATION_DETAIL, - NOTIFICATION_PAYMENT_INFO, -} from '../../api/notifications/notifications.routes'; -import NotificationDetail from '../NotificationDetail.page'; - -let mockIsDelegate = false; - -// mock imports -vi.mock('react-router-dom', async () => ({ - ...(await vi.importActual('react-router-dom')), - useParams: () => - mockIsDelegate - ? { id: 'DAPQ-LWQV-DKQH-202308-A-1', mandateId: '5' } - : { id: 'DAPQ-LWQV-DKQH-202308-A-1' }, -})); - -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 delegator = arrayOfDelegators.find( - (delegator) => delegator.delegator?.fiscalCode === notificationDTO.recipients[1].taxId -); - -const paymentInfoRequest = paymentInfo.map((payment) => ({ - creditorTaxId: payment.creditorTaxId, - noticeCode: payment.noticeCode, -})); - -describe('NotificationDetail Page - accessibility tests', async () => { - let result: RenderResult; - let mock: MockAdapter; - - beforeAll(() => { - mock = new MockAdapter(apiClient); - }); - - afterEach(() => { - vi.clearAllMocks(); - mock.reset(); - mockIsDelegate = false; - }); - - afterAll(() => { - mock.restore(); - }); - - it('renders NotificationDetail page', async () => { - mock.onGet(NOTIFICATION_DETAIL(notificationDTO.iun)).reply(200, notificationDTO); - mock.onPost(NOTIFICATION_PAYMENT_INFO(), paymentInfoRequest).reply(200, paymentInfo); - // we use regexp to not set the query parameters - mock.onGet(new RegExp(DOWNTIME_HISTORY({ startDate: '' }))).reply(200, downtimesDTO); - await act(async () => { - result = render(, { - preloadedState: { - userState: { - user: userResponse, - }, - }, - }); - }); - expect(await axe(result.container!)).toHaveNoViolations(); - }, 15000); - - it('renders NotificationDetail page with delegator logged', async () => { - mockIsDelegate = true; - mock - .onGet(NOTIFICATION_DETAIL(notificationDTO.iun, delegator?.mandateId)) - .reply(200, notificationDTO); - mock.onPost(NOTIFICATION_PAYMENT_INFO(), paymentInfoRequest).reply(200, paymentInfo); - // we use regexp to not set the query parameters - mock.onGet(new RegExp(DOWNTIME_HISTORY({ startDate: '' }))).reply(200, downtimesDTO); - await act(async () => { - result = render(, { - preloadedState: { - userState: { user: userResponse }, - }, - }); - }); - expect(await axe(result.container!)).toHaveNoViolations(); // Accesibility test - }, 15000); -}); diff --git a/packages/pn-personagiuridica-webapp/src/pages/__test__/Notifiche.page.a11y.test.tsx b/packages/pn-personagiuridica-webapp/src/pages/__test__/Notifiche.page.a11y.test.tsx deleted file mode 100644 index 5613b0cb6e..0000000000 --- a/packages/pn-personagiuridica-webapp/src/pages/__test__/Notifiche.page.a11y.test.tsx +++ /dev/null @@ -1,108 +0,0 @@ -import MockAdapter from 'axios-mock-adapter'; -import { vi } from 'vitest'; - -import { - AppResponseMessage, - ResponseEventDispatcher, - formatToTimezoneString, - tenYearsAgo, - today, -} from '@pagopa-pn/pn-commons'; - -import { emptyNotificationsFromBe, notificationsDTO } from '../../__mocks__/Notifications.mock'; -import { RenderResult, act, axe, render } from '../../__test__/test-utils'; -import { apiClient } from '../../api/apiClients'; -import { NOTIFICATIONS_LIST } from '../../api/notifications/notifications.routes'; -import Notifiche from '../Notifiche.page'; - -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, - i18n: { language: 'it' }, - }), -})); - -describe('Notifiche Page - accessibility tests', async () => { - let mock: MockAdapter; - let result: RenderResult; - - beforeAll(() => { - mock = new MockAdapter(apiClient); - }); - - afterEach(() => { - mock.reset(); - }); - - afterAll(() => { - mock.restore(); - }); - - it('does not have basic accessibility issues - no notifications', async () => { - mock - .onGet( - NOTIFICATIONS_LIST({ - startDate: formatToTimezoneString(tenYearsAgo), - endDate: formatToTimezoneString(today), - size: 10, - }) - ) - .reply(200, emptyNotificationsFromBe); - await act(async () => { - result = render(); - }); - if (result) { - const res = await axe(result.container); - expect(res).toHaveNoViolations(); - } else { - fail('render() returned undefined!'); - } - }, 15000); - - it('does not have basic accessibility issues rendering the page', async () => { - mock - .onGet( - NOTIFICATIONS_LIST({ - startDate: formatToTimezoneString(tenYearsAgo), - endDate: formatToTimezoneString(today), - size: 10, - }) - ) - .reply(200, notificationsDTO); - - await act(async () => { - result = render(); - }); - if (result) { - const results = await axe(result.container); - expect(results).toHaveNoViolations(); - } - }, 15000); - - it('does not have basic accessibility issues rendering the page - errors on api', async () => { - mock - .onGet( - NOTIFICATIONS_LIST({ - startDate: formatToTimezoneString(tenYearsAgo), - endDate: formatToTimezoneString(today), - size: 10, - }) - ) - .reply(500); - - await act(async () => { - result = render( - <> - - - - - ); - }); - if (result) { - const results = await axe(result.container); - expect(results).toHaveNoViolations(); - } - }, 15000); -}); diff --git a/packages/pn-personagiuridica-webapp/vite.config.a11y.ts b/packages/pn-personagiuridica-webapp/vite.config.a11y.ts deleted file mode 100644 index 9866859847..0000000000 --- a/packages/pn-personagiuridica-webapp/vite.config.a11y.ts +++ /dev/null @@ -1,18 +0,0 @@ -/// -import { defineConfig } from 'vite'; - -import react from '@vitejs/plugin-react'; - -// https://vitejs.dev/config/ -export default defineConfig(() => { - return { - plugins: [react()], - test: { - globals: true, - setupFiles: './src/setupTests.ts', - environment: 'jsdom', - include: ['**/*.a11y.test.ts', '**/*.a11y.test.tsx'], - reporters: ['default'], - }, - }; -}); diff --git a/packages/pn-personagiuridica-webapp/vite.config.mts b/packages/pn-personagiuridica-webapp/vite.config.mts index 1298cb3743..1611937009 100644 --- a/packages/pn-personagiuridica-webapp/vite.config.mts +++ b/packages/pn-personagiuridica-webapp/vite.config.mts @@ -9,13 +9,13 @@ const vitestConfig = defineVitestConfig({ globals: true, setupFiles: './src/setupTests.ts', environment: 'jsdom', - exclude: [...configDefaults.exclude, '**/*.a11y.test.ts', '**/*.a11y.test.tsx'], + exclude: configDefaults.exclude, reporters: ['vitest-sonar-reporter', 'default'], outputFile: 'test-report.xml', coverage: { provider: 'v8', reporter: ['lcov'], - exclude: ['**/*.a11y.test.ts', '**/*.a11y.test.tsx', 'src/models/**'], + exclude: ['src/models/**'], reportOnFailure: true, }, }, diff --git a/yarn.lock b/yarn.lock index fd7b39843d..4af123b476 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2852,7 +2852,7 @@ "@types/react" "*" hoist-non-react-statics "^3.3.0" -"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0": +"@types/istanbul-lib-coverage@^2.0.0": version "2.0.6" resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz#7739c232a1fee9b4d3ce8985f314c0c6d33549d7" integrity sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w== @@ -2862,13 +2862,6 @@ resolved "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz" integrity sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g== -"@types/istanbul-lib-report@*": - version "3.0.3" - resolved "https://registry.yarnpkg.com/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.3.tgz#53047614ae72e19fc0401d872de3ae2b4ce350bf" - integrity sha512-NQn7AHQnk/RSLOxrBbGyJM/aVQ+pjj5HCgasFxc0K/KhoATfQ/47AyUl15I2yBUpihjmas+a+VJBOqecrFH+uA== - dependencies: - "@types/istanbul-lib-coverage" "*" - "@types/istanbul-reports@^3.0.0": version "3.0.4" resolved "https://registry.yarnpkg.com/@types/istanbul-reports/-/istanbul-reports-3.0.4.tgz#0f03e3d2f670fbdac586e34b433783070cc16f54" @@ -2894,11 +2887,6 @@ resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz" integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ== -"@types/json5@^0.0.29": - version "0.0.29" - resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" - integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ== - "@types/lodash@^4.14.172": version "4.14.178" resolved "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.178.tgz" @@ -6281,7 +6269,7 @@ jest-axe@^6.0.0: jest-matcher-utils "27.0.2" lodash.merge "4.6.2" -jest-diff@^27.0.2: +jest-diff@^27.0.0, jest-diff@^27.0.2: version "27.5.1" resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-27.5.1.tgz#a07f5011ac9e6643cf8a95a462b7b1ecf6680def" integrity sha512-m0NvkX55LDt9T4mctTEgnZk3fmEg3NRYutvMPWM/0iPnkFj2wIeF45O1718cMSOFO1vINkqmxqD8vE37uTEbqw== @@ -6462,13 +6450,6 @@ json-stringify-safe@^5.0.1: resolved "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz" integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus= -json5@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.2.tgz#63d98d60f21b313b77c4d6da18bfa69d80e1d593" - integrity sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA== - dependencies: - minimist "^1.2.0" - json5@^2.2.2, json5@^2.2.3: version "2.2.3" resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283" @@ -8010,7 +7991,7 @@ pretty-format@29.4.3: ansi-styles "^5.0.0" react-is "^18.0.0" -pretty-format@^27.0.2, pretty-format@^27.5.1: +pretty-format@^27.0.0, pretty-format@^27.0.2, pretty-format@^27.5.1: version "27.5.1" resolved "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.1.tgz" integrity sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ== @@ -9272,17 +9253,7 @@ ts-api-utils@^1.0.1: resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.0.3.tgz#f12c1c781d04427313dbac808f453f050e54a331" integrity sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg== -tsconfig-paths@^3.12.0: - version "3.15.0" - resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz#5299ec605e55b1abb23ec939ef15edaf483070d4" - integrity sha512-2Ac2RgzDe/cn48GvOe3M+o82pEFewD3UPbyoUHHdKasHwJKjds4fLXWf/Ux5kATBKN20oaFGu+jbElp1pos0mg== - dependencies: - "@types/json5" "^0.0.29" - json5 "^1.0.2" - minimist "^1.2.6" - strip-bom "^3.0.0" - -tsconfig-paths@^4.1.2: +tsconfig-paths@^3.12.0, tsconfig-paths@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-4.1.2.tgz#4819f861eef82e6da52fb4af1e8c930a39ed979a" integrity sha512-uhxiMgnXQp1IR622dUXI+9Ehnws7i/y6xvpZB9IbUVOPy0muvdvgXeZOn88UcGPiT98Vp3rJPTa8bFoalZ3Qhw==