diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/datacentre-general-information-tile/DatacentreGeneralInformationTile.spec.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/datacentre-general-information-tile/DatacentreGeneralInformationTile.spec.tsx index eef4a6e1616e..b7b71890451c 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/datacentre-general-information-tile/DatacentreGeneralInformationTile.spec.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/datacentre-general-information-tile/DatacentreGeneralInformationTile.spec.tsx @@ -1,3 +1,4 @@ +import React from 'react'; import { render } from '@testing-library/react'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { describe, expect, it, vi } from 'vitest'; @@ -6,7 +7,7 @@ import { ODS_THEME_TYPOGRAPHY_LEVEL, ODS_THEME_TYPOGRAPHY_SIZE, } from '@ovhcloud/ods-common-theming'; -import React from 'react'; +import { VCDDatacentre, VCDOrganization } from '@ovh-ux/manager-module-vcd-api'; import DatacentreGeneralInformationTile from './DatacentreGeneralInformationTile.component'; const queryClient = new QueryClient({ @@ -78,8 +79,8 @@ describe.skip('DatacentreGeneralInformationTile component unit test suite', () = const { getByText } = render( , ); diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/DatacentreDashboard.spec.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/DatacentreDashboard.spec.tsx index ab21d4b41ea9..2da581fe603e 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/DatacentreDashboard.spec.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/DatacentreDashboard.spec.tsx @@ -2,7 +2,8 @@ import { organizationList, datacentreList, } from '@ovh-ux/manager-module-vcd-api'; -import { checkTextVisibility, labels, renderTest } from '../../../test-utils'; +import { checkTextVisibility } from '@ovh-ux/manager-core-test-utils'; +import { labels, renderTest } from '../../../test-utils'; describe('Datacentre Dashboard Page', () => { it('display the datacentre dashboard page', async () => { diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/compute-order/DatacentreComputeOrder.spec.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/compute-order/DatacentreComputeOrder.spec.tsx index e615c95d8410..54b56a32075a 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/compute-order/DatacentreComputeOrder.spec.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/compute-order/DatacentreComputeOrder.spec.tsx @@ -4,11 +4,8 @@ import { organizationList, datacentreList, } from '@ovh-ux/manager-module-vcd-api'; -import { - checkTextVisibility, - labels, - renderTest, -} from '../../../../test-utils'; +import { checkTextVisibility } from '@ovh-ux/manager-core-test-utils'; +import { labels, renderTest } from '../../../../test-utils'; const orderCTA = labels.datacentresCompute.managed_vcd_vdc_compute_order_cta; const orderTitle = orderCTA; diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/compute/DatacentreCompute.spec.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/compute/DatacentreCompute.spec.tsx index 9cbea5bb23be..d1ed32095e9a 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/compute/DatacentreCompute.spec.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/compute/DatacentreCompute.spec.tsx @@ -4,8 +4,8 @@ import { organizationList, datacentreList, } from '@ovh-ux/manager-module-vcd-api'; +import { checkTextVisibility } from '@ovh-ux/manager-core-test-utils'; import { - checkTextVisibility, DEFAULT_LISTING_ERROR, labels, renderTest, diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/general-informations/DatacentreGeneralInformation.spec.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/general-informations/DatacentreGeneralInformation.spec.tsx index 7e7b0083b4c1..9a1b7ffcdd02 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/general-informations/DatacentreGeneralInformation.spec.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/general-informations/DatacentreGeneralInformation.spec.tsx @@ -5,16 +5,16 @@ import { datacentreList, } from '@ovh-ux/manager-module-vcd-api'; import { - checkModalError, - checkModalVisibility, + assertModalVisibility, + assertModalText, + WAIT_FOR_DEFAULT_OPTIONS, +} from '@ovh-ux/manager-core-test-utils'; +import { labels, mockEditInputValue, renderTest, -} from '../../../../test-utils'; -import { - DEFAULT_TIMEOUT, mockSubmitNewValue, -} from '../../../../test-utils/uiTestHelpers'; +} from '@/test-utils'; const submitButtonLabel = labels.dashboard.managed_vcd_dashboard_edit_modal_cta_edit; @@ -30,23 +30,20 @@ describe('Datacentre General Information Page', () => { expect( screen.getByText(labels.datacentres.managed_vcd_vdc_vcpu_count), ).toBeVisible(), - { timeout: DEFAULT_TIMEOUT }, + WAIT_FOR_DEFAULT_OPTIONS, ); let editButton; - await waitFor( - () => { - editButton = screen.getByTestId('editIcon'); - return expect(editButton).toBeEnabled(); - }, - { timeout: DEFAULT_TIMEOUT }, - ); + await waitFor(() => { + editButton = screen.getByTestId('editIcon'); + return expect(editButton).toBeEnabled(); + }, WAIT_FOR_DEFAULT_OPTIONS); await waitFor(() => userEvent.click(editButton)); - await checkModalVisibility({ container, isVisible: true }); + await assertModalVisibility({ container, isVisible: true }); await mockSubmitNewValue({ submitButtonLabel }); - await checkModalVisibility({ container, isVisible: false }); + await assertModalVisibility({ container, isVisible: false }); expect( screen.queryByText( @@ -63,13 +60,13 @@ describe('Datacentre General Information Page', () => { labels.dashboard .managed_vcd_dashboard_edit_description_modal_helper_error; - await checkModalVisibility({ container, isVisible: true }); + await assertModalVisibility({ container, isVisible: true }); await mockEditInputValue(''); - await checkModalError({ container, error: expectedError }); + await assertModalText({ container, text: expectedError }); await mockEditInputValue('a'.repeat(256)); - await checkModalError({ container, error: expectedError }); + await assertModalText({ container, text: expectedError }); }); it('display an error if update datacentre service is KO', async () => { @@ -78,11 +75,11 @@ describe('Datacentre General Information Page', () => { isDatacentreUpdateKo: true, }); - await checkModalVisibility({ container, isVisible: true }); + await assertModalVisibility({ container, isVisible: true }); await mockSubmitNewValue({ submitButtonLabel }); - await checkModalVisibility({ container, isVisible: true }); - await checkModalError({ container, error: 'Datacentre update error' }); + await assertModalVisibility({ container, isVisible: true }); + await assertModalText({ container, text: 'Datacentre update error' }); }); }); diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/storage-order/DatacentreStorageOrder.spec.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/storage-order/DatacentreStorageOrder.spec.tsx index 0d8470e3bcc7..3e8b962b025d 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/storage-order/DatacentreStorageOrder.spec.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/storage-order/DatacentreStorageOrder.spec.tsx @@ -4,11 +4,8 @@ import { organizationList, datacentreList, } from '@ovh-ux/manager-module-vcd-api'; -import { - checkTextVisibility, - labels, - renderTest, -} from '../../../../test-utils'; +import { checkTextVisibility } from '@ovh-ux/manager-core-test-utils'; +import { labels, renderTest } from '../../../../test-utils'; const orderCTA = labels.datacentresStorage.managed_vcd_vdc_storage_order_cta; const orderTitle = labels.datacentresOrder.managed_vcd_vdc_order_storage_title; diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/storage/DatacentreStorage.spec.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/storage/DatacentreStorage.spec.tsx index a586280b2789..9788b58761b5 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/storage/DatacentreStorage.spec.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/datacentre/storage/DatacentreStorage.spec.tsx @@ -4,8 +4,8 @@ import { organizationList, datacentreList, } from '@ovh-ux/manager-module-vcd-api'; +import { checkTextVisibility } from '@ovh-ux/manager-core-test-utils'; import { - checkTextVisibility, DEFAULT_LISTING_ERROR, labels, renderTest, diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/organization/OrganizationDashboard.spec.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/organization/OrganizationDashboard.spec.tsx index 567306a6e1ff..15d3cb063438 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/organization/OrganizationDashboard.spec.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/organization/OrganizationDashboard.spec.tsx @@ -1,6 +1,7 @@ import userEvents from '@testing-library/user-event'; import { screen, waitFor } from '@testing-library/react'; import { organizationList } from '@ovh-ux/manager-module-vcd-api'; +import { checkTextVisibility } from '@ovh-ux/manager-core-test-utils'; import { renderTest, labels } from '../../../test-utils'; describe('Organization Dashboard Page', () => { @@ -9,19 +10,11 @@ describe('Organization Dashboard Page', () => { const link = screen.getByText(organizationList[0].currentState.fullName); await waitFor(() => userEvents.click(link)); - await waitFor( - () => - expect( - screen.getByText( - labels.dashboard.managed_vcd_dashboard_data_protection, - ), - ).toBeVisible(), - { timeout: 30000 }, + await checkTextVisibility( + labels.dashboard.managed_vcd_dashboard_data_protection, ); - expect( - screen.getByText(organizationList[0].currentState.description), - ).toBeVisible(); + await checkTextVisibility(organizationList[0].currentState.description); }); it('display an error', async () => { @@ -29,9 +22,7 @@ describe('Organization Dashboard Page', () => { initialRoute: `/${organizationList[0].id}`, isOrganizationKo: true, }); - await waitFor( - () => expect(screen.getByText('Organization error')).toBeVisible(), - { timeout: 30000 }, - ); + + await checkTextVisibility('Organization error'); }); }); diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/organization/general-information/OrganizationGeneralInformation.spec.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/organization/general-information/OrganizationGeneralInformation.spec.tsx index 1a1a91394cfc..42b247573ef5 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/organization/general-information/OrganizationGeneralInformation.spec.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/organization/general-information/OrganizationGeneralInformation.spec.tsx @@ -2,15 +2,13 @@ import userEvents from '@testing-library/user-event'; import { screen, waitFor } from '@testing-library/react'; import { organizationList } from '@ovh-ux/manager-module-vcd-api'; import { - renderTest, - labels, - checkModalVisibility, - waitForEnabledElement, - mockSubmitNewValue, - checkModalError, - DEFAULT_TIMEOUT, + getButtonByLabel, + assertModalVisibility, + assertModalText, + WAIT_FOR_DEFAULT_OPTIONS, checkTextVisibility, -} from '../../../../test-utils'; +} from '@ovh-ux/manager-core-test-utils'; +import { renderTest, labels, mockSubmitNewValue } from '../../../../test-utils'; const submitButtonLabel = labels.dashboard.managed_vcd_dashboard_edit_modal_cta_edit; @@ -26,20 +24,17 @@ describe('Organization General Information Page', () => { ); let editButton; - await waitFor( - () => { - editButton = screen.getAllByTestId('editIcon').at(0); - return expect(editButton).toBeEnabled(); - }, - { timeout: DEFAULT_TIMEOUT }, - ); + await waitFor(() => { + editButton = screen.getAllByTestId('editIcon').at(0); + return expect(editButton).toBeEnabled(); + }, WAIT_FOR_DEFAULT_OPTIONS); await waitFor(() => userEvents.click(editButton)); - await checkModalVisibility({ container, isVisible: true }); + await assertModalVisibility({ container, isVisible: true }); await mockSubmitNewValue({ submitButtonLabel }); - await checkModalVisibility({ container, isVisible: false }); + await assertModalVisibility({ container, isVisible: false }); await checkTextVisibility( labels.dashboard.managed_vcd_dashboard_edit_name_modal_success, ); @@ -51,12 +46,12 @@ describe('Organization General Information Page', () => { isOrganizationUpdateKo: true, }); - await checkModalVisibility({ container, isVisible: true }); + await assertModalVisibility({ container, isVisible: true }); await mockSubmitNewValue({ submitButtonLabel }); - await checkModalVisibility({ container, isVisible: true }); - await checkModalError({ container, error: 'Organization update error' }); + await assertModalVisibility({ container, isVisible: true }); + await assertModalText({ container, text: 'Organization update error' }); }); it('modify the description of the organization', async () => { @@ -69,20 +64,17 @@ describe('Organization General Information Page', () => { ); let editButton; - await waitFor( - () => { - editButton = screen.getAllByTestId('editIcon').at(1); - return expect(editButton).toBeEnabled(); - }, - { timeout: DEFAULT_TIMEOUT }, - ); + await waitFor(() => { + editButton = screen.getAllByTestId('editIcon').at(1); + return expect(editButton).toBeEnabled(); + }, WAIT_FOR_DEFAULT_OPTIONS); await waitFor(() => userEvents.click(editButton)); - await checkModalVisibility({ container, isVisible: true }); + await assertModalVisibility({ container, isVisible: true }); await mockSubmitNewValue({ submitButtonLabel }); - await checkModalVisibility({ container, isVisible: false }); + await assertModalVisibility({ container, isVisible: false }); await checkTextVisibility( labels.dashboard.managed_vcd_dashboard_edit_description_modal_success, ); @@ -94,12 +86,12 @@ describe('Organization General Information Page', () => { isOrganizationUpdateKo: true, }); - await checkModalVisibility({ container, isVisible: true }); + await assertModalVisibility({ container, isVisible: true }); await mockSubmitNewValue({ submitButtonLabel }); - await checkModalVisibility({ container, isVisible: true }); - await checkModalError({ container, error: 'Organization update error' }); + await assertModalVisibility({ container, isVisible: true }); + await assertModalText({ container, text: 'Organization update error' }); }); it('resets the password of the organization', async () => { @@ -111,19 +103,22 @@ describe('Organization General Information Page', () => { labels.dashboard.managed_vcd_dashboard_password_renew, ); - const resetPasswordLink = await waitForEnabledElement( - labels.dashboard.managed_vcd_dashboard_password_renew, - ); + const resetPasswordLink = await getButtonByLabel({ + container, + label: labels.dashboard.managed_vcd_dashboard_password_renew, + isLink: true, + }); await waitFor(() => userEvents.click(resetPasswordLink)); - await checkModalVisibility({ container, isVisible: true }); + await assertModalVisibility({ container, isVisible: true }); - const validateButton = await waitForEnabledElement( - labels.dashboard.managed_vcd_dashboard_edit_modal_cta_validate, - ); + const validateButton = await getButtonByLabel({ + container, + label: labels.dashboard.managed_vcd_dashboard_edit_modal_cta_validate, + }); await waitFor(() => userEvents.click(validateButton)); - await checkModalVisibility({ container, isVisible: false }); + await assertModalVisibility({ container, isVisible: false }); await checkTextVisibility( labels.dashboard.managed_vcd_dashboard_password_renew_success, ); @@ -135,14 +130,15 @@ describe('Organization General Information Page', () => { isOrganizationResetPasswordKo: true, }); - await checkModalVisibility({ container, isVisible: true }); + await assertModalVisibility({ container, isVisible: true }); - const validateButton = await waitForEnabledElement( - labels.dashboard.managed_vcd_dashboard_edit_modal_cta_validate, - ); + const validateButton = await getButtonByLabel({ + container, + label: labels.dashboard.managed_vcd_dashboard_edit_modal_cta_validate, + }); await waitFor(() => userEvents.click(validateButton)); - await checkModalVisibility({ container, isVisible: false }); + await assertModalVisibility({ container, isVisible: false }); await checkTextVisibility( labels.dashboard.managed_vcd_dashboard_password_renew_error, ); diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/listing/datacentres/datacentres.spec.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/listing/datacentres/datacentres.spec.tsx index a1ce694decf3..eddd56f1665c 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/listing/datacentres/datacentres.spec.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/listing/datacentres/datacentres.spec.tsx @@ -1,14 +1,9 @@ -import { screen, waitFor } from '@testing-library/react'; import { organizationList, datacentreList, } from '@ovh-ux/manager-module-vcd-api'; -import { - checkTextVisibility, - DEFAULT_LISTING_ERROR, - labels, - renderTest, -} from '../../../test-utils'; +import { checkTextVisibility } from '@ovh-ux/manager-core-test-utils'; +import { DEFAULT_LISTING_ERROR, labels, renderTest } from '../../../test-utils'; describe('Datacentres Listing Page', () => { it('displays the virtual datacentres listing page', async () => { @@ -16,19 +11,9 @@ describe('Datacentres Listing Page', () => { initialRoute: `/${organizationList[0].id}/datacentres`, }); - await waitFor( - () => - expect( - screen.getByText(labels.datacentres.managed_vcd_vdc_title), - ).toBeVisible(), - { timeout: 30_000 }, - ); + await checkTextVisibility(labels.datacentres.managed_vcd_vdc_title); - await waitFor(() => - expect( - screen.getByText(datacentreList[0].currentState.name), - ).toBeVisible(), - ); + await checkTextVisibility(datacentreList[0].currentState.name); }); it('display an error', async () => { diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/listing/organizations/Organizations.spec.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/listing/organizations/Organizations.spec.tsx index 8109a7cd913f..f9656db9eda2 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/listing/organizations/Organizations.spec.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/listing/organizations/Organizations.spec.tsx @@ -1,21 +1,13 @@ -import { screen, waitFor } from '@testing-library/react'; import { organizationList } from '@ovh-ux/manager-module-vcd-api'; +import { checkTextVisibility } from '@ovh-ux/manager-core-test-utils'; import { renderTest, labels } from '../../../test-utils'; describe('Organizations Listing Page', () => { it('display the listing page if there is at least one organization', async () => { await renderTest({ nbOrganization: 1 }); - await waitFor(() => - expect( - screen.getByText(labels.listing.managed_vcd_listing_description), - ).toBeVisible(), - ); + await checkTextVisibility(labels.listing.managed_vcd_listing_description); - await waitFor(() => - expect( - screen.getByText(organizationList[0].currentState.fullName), - ).toBeVisible(), - ); + await checkTextVisibility(organizationList[0].currentState.fullName); }); }); diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/onboarding/Onboarding.spec.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/onboarding/Onboarding.spec.tsx index 74612cb296ea..fac30989f5ee 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/onboarding/Onboarding.spec.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/onboarding/Onboarding.spec.tsx @@ -1,15 +1,11 @@ -import { screen, waitFor } from '@testing-library/react'; +import { checkTextVisibility } from '@ovh-ux/manager-core-test-utils'; import { renderTest, labels } from '../../test-utils'; describe('Onboarding Page', () => { it('display the onboarding page if there is no VCD Organization', async () => { await renderTest({ nbOrganization: 0 }); - await waitFor(() => - expect( - screen.getByText( - labels.onboarding.managed_vcd_onboarding_description_part1, - ), - ).toBeVisible(), + await checkTextVisibility( + labels.onboarding.managed_vcd_onboarding_description_part1, ); }); }); diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/test-utils/index.ts b/packages/manager/apps/hpc-vmware-managed-vcd/src/test-utils/index.ts index 27f202fe11ad..a0cde9effbd7 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/test-utils/index.ts +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/test-utils/index.ts @@ -1,12 +1,3 @@ export { renderTest } from './render-test'; export { labels } from './test-i18n'; -export { - DEFAULT_TIMEOUT, - DEFAULT_LISTING_ERROR, - checkTextVisibility, - waitForEnabledElement, - mockEditInputValue, - mockSubmitNewValue, - checkModalVisibility, - checkModalError, -} from './uiTestHelpers'; +export * from './uiTestHelpers'; diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/test-utils/uiTestHelpers.ts b/packages/manager/apps/hpc-vmware-managed-vcd/src/test-utils/uiTestHelpers.ts index 72b8d1c0a686..84d5a05484da 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/test-utils/uiTestHelpers.ts +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/test-utils/uiTestHelpers.ts @@ -1,43 +1,9 @@ -import '@testing-library/jest-dom'; import userEvent from '@testing-library/user-event'; -import { - screen, - act, - waitFor, - fireEvent, - within, -} from '@testing-library/react'; -import { expect } from 'vitest'; +import { screen, act, waitFor, fireEvent } from '@testing-library/react'; +import '@testing-library/jest-dom'; -export const DEFAULT_TIMEOUT = 30_000; export const DEFAULT_LISTING_ERROR = 'An error occured while fetching data'; -// General helpers -/** - * @description Standard check: wait and expect some text to be visible on the screen - * @param text expected to be visible - * @param timeout time to wait for (default to 30sec) - * @returns - */ -export const checkTextVisibility = ( - text: string, - timeout = DEFAULT_TIMEOUT, -): Promise => - waitFor(() => expect(screen.getByText(text)).toBeVisible(), { - timeout, - }); - -export const waitForEnabledElement = async ( - elementLabel: string, -): Promise => { - let button; - await waitFor(() => { - button = screen.getByText(elementLabel); - return expect(button).toBeEnabled(); - }); - return button; -}; - // Form helpers export const mockEditInputValue = async (value: string) => { const input = screen.getByLabelText('edit-input'); @@ -57,38 +23,3 @@ export const mockSubmitNewValue = async ({ const submitButton = screen.getByText(submitButtonLabel, { exact: true }); return waitFor(() => userEvent.click(submitButton)); }; - -// Modal helpers -export const checkModalVisibility = ({ - container, - isVisible, -}: { - container: HTMLElement; - isVisible: boolean; -}): Promise => - waitFor( - () => { - const modal = container.querySelector('osds-modal'); - return isVisible - ? expect(modal).toBeInTheDocument() - : expect(modal).not.toBeInTheDocument(); - }, - { timeout: DEFAULT_TIMEOUT }, - ); - -export const checkModalError = ({ - container, - error, -}: { - container: HTMLElement; - error: string; -}): Promise => - waitFor( - () => - expect( - within(container.querySelector('osds-modal')).getByText(error, { - exact: false, - }), - ).toBeVisible(), - { timeout: DEFAULT_TIMEOUT }, - ); diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/tsconfig.test.json b/packages/manager/apps/hpc-vmware-managed-vcd/tsconfig.test.json deleted file mode 100644 index 7048c297c8f6..000000000000 --- a/packages/manager/apps/hpc-vmware-managed-vcd/tsconfig.test.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "CommonJS" - } -} diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/vitest.config.js b/packages/manager/apps/hpc-vmware-managed-vcd/vitest.config.js index eba2881506f1..f13836749312 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/vitest.config.js +++ b/packages/manager/apps/hpc-vmware-managed-vcd/vitest.config.js @@ -18,6 +18,9 @@ export default defineConfig({ 'src/App.tsx', 'src/index.tsx', 'src/tracking.constant.ts', + '404.tsx', + 'src/**/*.spec.ts', + 'src/**/*.spec.tsx', ], }, testTimeout: 60000, diff --git a/packages/manager/apps/veeam-backup/src/pages/dashboard/dashboard.spec.tsx b/packages/manager/apps/veeam-backup/src/pages/dashboard/dashboard.spec.tsx index 3aaa71b06f85..27e802cb72dc 100644 --- a/packages/manager/apps/veeam-backup/src/pages/dashboard/dashboard.spec.tsx +++ b/packages/manager/apps/veeam-backup/src/pages/dashboard/dashboard.spec.tsx @@ -1,7 +1,7 @@ import { screen, waitFor } from '@testing-library/react'; import { ODS_ICON_NAME } from '@ovhcloud/ods-components'; import { - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, getButtonByIcon, getButtonByLabel, } from '@ovh-ux/manager-core-test-utils'; @@ -24,7 +24,7 @@ describe('dashboard', () => { ), ), ), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); }); @@ -42,7 +42,7 @@ describe('dashboard', () => { ), ), ), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); await getButtonByIcon({ diff --git a/packages/manager/apps/veeam-backup/src/pages/delete-veeam/delete-veeam.spec.tsx b/packages/manager/apps/veeam-backup/src/pages/delete-veeam/delete-veeam.spec.tsx index 333bacc7283f..fa71ffe4b0d4 100644 --- a/packages/manager/apps/veeam-backup/src/pages/delete-veeam/delete-veeam.spec.tsx +++ b/packages/manager/apps/veeam-backup/src/pages/delete-veeam/delete-veeam.spec.tsx @@ -1,7 +1,7 @@ import userEvents from '@testing-library/user-event'; import { screen, waitFor } from '@testing-library/react'; import { - checkModal, + assertModalVisibility, changeInputValue, getButtonByLabel, } from '@ovh-ux/manager-core-test-utils'; @@ -22,7 +22,7 @@ describe('Delete veeam-backup', () => { }); await waitFor(() => userEvents.click(deleteButton)); - await checkModal({ container, isVisible: true }); + await assertModalVisibility({ container, isVisible: true }); await changeInputValue({ inputLabel: 'delete-input', @@ -37,7 +37,7 @@ describe('Delete veeam-backup', () => { await waitFor(() => userEvents.click(confirmButton)); - await checkModal({ container, isVisible: false }); + await assertModalVisibility({ container, isVisible: false }); expect( screen.getByText(labels.deleteVeeam.terminate_veeam_backup_success), diff --git a/packages/manager/apps/veeam-backup/src/pages/edit-name/edit-name.spec.tsx b/packages/manager/apps/veeam-backup/src/pages/edit-name/edit-name.spec.tsx index 62f1c1393ef0..5987af4e0b4a 100644 --- a/packages/manager/apps/veeam-backup/src/pages/edit-name/edit-name.spec.tsx +++ b/packages/manager/apps/veeam-backup/src/pages/edit-name/edit-name.spec.tsx @@ -2,8 +2,8 @@ import { ODS_ICON_NAME } from '@ovhcloud/ods-components'; import userEvents from '@testing-library/user-event'; import { screen, waitFor } from '@testing-library/react'; import { - checkModal, - waitForOptions, + assertModalVisibility, + WAIT_FOR_DEFAULT_OPTIONS, changeInputValue, getButtonByIcon, } from '@ovh-ux/manager-core-test-utils'; @@ -21,7 +21,7 @@ describe('Edit name', () => { await waitFor( () => expect(screen.getByText(labels.dashboard.delete_service)).toBeVisible(), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); const editButton = await getButtonByIcon({ @@ -30,7 +30,7 @@ describe('Edit name', () => { }); await waitFor(() => userEvents.click(editButton)); - await checkModal({ container, isVisible: true }); + await assertModalVisibility({ container, isVisible: true }); await changeInputValue({ inputLabel: 'update-input', value: 'new name' }); @@ -41,7 +41,7 @@ describe('Edit name', () => { await waitFor(() => userEvents.click(modifyButton)); - await checkModal({ container, isVisible: false }); + await assertModalVisibility({ container, isVisible: false }); expect( screen.getByText(labels.common.update_veeam_backup_display_name_success), diff --git a/packages/manager/apps/veeam-backup/src/pages/listing/listing.spec.tsx b/packages/manager/apps/veeam-backup/src/pages/listing/listing.spec.tsx index b8c98d6628a4..848abe8751cc 100644 --- a/packages/manager/apps/veeam-backup/src/pages/listing/listing.spec.tsx +++ b/packages/manager/apps/veeam-backup/src/pages/listing/listing.spec.tsx @@ -1,6 +1,6 @@ import { screen, waitFor } from '@testing-library/react'; import { - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, getButtonByLabel, } from '@ovh-ux/manager-core-test-utils'; import { renderTest, labels } from '@/test-helpers'; @@ -11,7 +11,7 @@ describe('listing', () => { await renderTest(); await waitFor( () => expect(screen.getByText(labels.listing.description)).toBeVisible(), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); }); diff --git a/packages/manager/apps/veeam-backup/src/pages/onboarding/onboarding.spec.tsx b/packages/manager/apps/veeam-backup/src/pages/onboarding/onboarding.spec.tsx index 7984776c1164..f99b54733228 100644 --- a/packages/manager/apps/veeam-backup/src/pages/onboarding/onboarding.spec.tsx +++ b/packages/manager/apps/veeam-backup/src/pages/onboarding/onboarding.spec.tsx @@ -1,5 +1,5 @@ import { screen, waitFor } from '@testing-library/react'; -import { waitForOptions } from '@ovh-ux/manager-core-test-utils'; +import { WAIT_FOR_DEFAULT_OPTIONS } from '@ovh-ux/manager-core-test-utils'; import { renderTest, labels } from '@/test-helpers'; import '@testing-library/jest-dom'; @@ -9,7 +9,7 @@ describe('onboarding', () => { await waitFor( () => expect(screen.getByText(labels.onboarding.description)).toBeVisible(), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); expect( @@ -20,7 +20,7 @@ describe('onboarding', () => { expect( screen.getByText(labels.onboarding.order_button_label), ).toBeEnabled(), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); }); @@ -28,7 +28,7 @@ describe('onboarding', () => { await renderTest({ nbBackup: 1 }); await waitFor( () => expect(screen.getByText(labels.listing.description)).toBeVisible(), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); expect( screen.queryByText(labels.onboarding.description), @@ -42,7 +42,7 @@ describe('onboarding', () => { expect( screen.getByText(labels.onboarding.order_button_label), ).toBeDisabled(), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); await waitFor( () => @@ -51,7 +51,7 @@ describe('onboarding', () => { exact: false, }), ).toBeVisible(), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); }); }); diff --git a/packages/manager/apps/veeam-backup/src/pages/order-veeam/order-veeam.spec.tsx b/packages/manager/apps/veeam-backup/src/pages/order-veeam/order-veeam.spec.tsx index 8574c0e7fb14..c75eec11fbc5 100644 --- a/packages/manager/apps/veeam-backup/src/pages/order-veeam/order-veeam.spec.tsx +++ b/packages/manager/apps/veeam-backup/src/pages/order-veeam/order-veeam.spec.tsx @@ -1,7 +1,7 @@ import userEvent from '@testing-library/user-event'; import { screen, waitFor } from '@testing-library/react'; import { - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, getButtonByLabel, } from '@ovh-ux/manager-core-test-utils'; import { renderTest, labels } from '@/test-helpers'; @@ -17,7 +17,7 @@ describe('order', () => { await waitFor(() => { orderButton = screen.getByText(labels.listing.order_button); return expect(orderButton).toBeEnabled(); - }, waitForOptions); + }, WAIT_FOR_DEFAULT_OPTIONS); await waitFor(() => userEvent.click(orderButton)); @@ -26,7 +26,7 @@ describe('order', () => { expect( screen.getByText(labels.orderVeeam.description), ).toBeInTheDocument(), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); }); @@ -50,7 +50,7 @@ describe('order', () => { { exact: false }, ), ).toBeInTheDocument(), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); }); @@ -62,7 +62,7 @@ describe('order', () => { expect( screen.getByText(labels.orderVeeam.description), ).toBeInTheDocument(), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); const nextButton = await getButtonByLabel({ @@ -76,7 +76,7 @@ describe('order', () => { expect( screen.getByText(labels.orderVeeam.choose_org_title), ).toBeInTheDocument(), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); }); @@ -91,7 +91,7 @@ describe('order', () => { expect( screen.getByText(labels.orderVeeam.description), ).toBeInTheDocument(), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); const nextButton = await getButtonByLabel({ @@ -107,7 +107,7 @@ describe('order', () => { labels.orderVeeam.all_organization_backed_up_message, ), ).toBeInTheDocument(), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); }); @@ -122,7 +122,7 @@ describe('order', () => { expect( screen.getByText(labels.orderVeeam.description), ).toBeInTheDocument(), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); const nextButton = await getButtonByLabel({ @@ -138,7 +138,7 @@ describe('order', () => { exact: false, }), ).toBeInTheDocument(), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); }); }); diff --git a/packages/manager/apps/veeam-backup/src/test-helpers/test-utils.ts b/packages/manager/apps/veeam-backup/src/test-helpers/test-utils.ts index eb07f6de29e7..3e92025c1c04 100644 --- a/packages/manager/apps/veeam-backup/src/test-helpers/test-utils.ts +++ b/packages/manager/apps/veeam-backup/src/test-helpers/test-utils.ts @@ -1,6 +1,6 @@ import { screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { waitForOptions } from '@ovh-ux/manager-core-test-utils'; +import { WAIT_FOR_DEFAULT_OPTIONS } from '@ovh-ux/manager-core-test-utils'; import { labels } from './labels'; export const goToDashboard = async (name: string) => { @@ -10,6 +10,6 @@ export const goToDashboard = async (name: string) => { await waitFor( () => expect(screen.getByText(labels.dashboard.general_informations)), - waitForOptions, + WAIT_FOR_DEFAULT_OPTIONS, ); }; diff --git a/packages/manager/apps/veeam-backup/tsconfig.test.json b/packages/manager/apps/veeam-backup/tsconfig.test.json deleted file mode 100644 index 7048c297c8f6..000000000000 --- a/packages/manager/apps/veeam-backup/tsconfig.test.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "CommonJS" - } -} diff --git a/packages/manager/core/test-utils/src/utils/ui-test-helpers-ods17.ts b/packages/manager/core/test-utils/src/utils/ui-test-helpers-ods17.ts index 0900774b8c11..09b59e79b45e 100644 --- a/packages/manager/core/test-utils/src/utils/ui-test-helpers-ods17.ts +++ b/packages/manager/core/test-utils/src/utils/ui-test-helpers-ods17.ts @@ -1,12 +1,12 @@ import { ODS_ICON_NAME } from '@ovhcloud/ods-components'; -import { screen, waitFor, fireEvent } from '@testing-library/react'; +import { within, screen, waitFor, fireEvent } from '@testing-library/react'; import '@testing-library/jest-dom'; -export const waitForOptions = { +export const WAIT_FOR_DEFAULT_OPTIONS = { timeout: 30_000, }; -export const checkModal = async ({ +export const assertModalVisibility = async ({ container, isVisible, }: { @@ -18,22 +18,43 @@ export const checkModal = async ({ return isVisible ? expect(modal).toBeInTheDocument() : expect(modal).not.toBeInTheDocument(); - }, waitForOptions); + }, WAIT_FOR_DEFAULT_OPTIONS); + +export const assertModalText = ({ + container, + text, +}: { + container: HTMLElement; + text: string; +}): Promise => + waitFor( + () => + expect( + within(container.querySelector('osds-modal')).getByText(text, { + exact: false, + }), + ).toBeVisible(), + WAIT_FOR_DEFAULT_OPTIONS, + ); export const getButtonByLabel = async ({ container, label, altLabel, disabled, + isLink, }: { container: HTMLElement; label: string; altLabel?: string; disabled?: boolean; + isLink?: boolean; }) => { let button: HTMLElement; await waitFor(() => { - const buttonList = container.querySelectorAll('osds-button'); + const buttonList = container.querySelectorAll( + isLink ? 'osds-link' : 'osds-button', + ); buttonList.forEach((btn) => { if ([label, altLabel].includes(btn.textContent)) { button = btn; @@ -42,7 +63,7 @@ export const getButtonByLabel = async ({ return disabled ? expect(button).toHaveAttribute('disabled') : expect(button).not.toHaveAttribute('disabled'); - }, waitForOptions); + }, WAIT_FOR_DEFAULT_OPTIONS); return button; }; @@ -62,7 +83,7 @@ export const getButtonByIcon = async ({ return disabled ? expect(button).toHaveAttribute('disabled') : expect(button).not.toHaveAttribute('disabled'); - }, waitForOptions); + }, WAIT_FOR_DEFAULT_OPTIONS); return button; }; @@ -73,7 +94,7 @@ export const getButtonByTestId = async (testId: string, disabled?: boolean) => { return disabled ? expect(button).toHaveAttribute('disabled') : expect(button).not.toHaveAttribute('disabled'); - }, waitForOptions); + }, WAIT_FOR_DEFAULT_OPTIONS); return button; }; @@ -90,3 +111,15 @@ export const changeInputValue = async ({ }); return waitFor(() => fireEvent(input, event)); }; + +/** + * @description Standard check: wait and expect some text to be visible on the screen + * @param text expected to be visible + * @param timeout time to wait for (default to 30sec) + * @returns + */ +export const checkTextVisibility = (text: string): Promise => + waitFor( + () => expect(screen.getByText(text)).toBeVisible(), + WAIT_FOR_DEFAULT_OPTIONS, + );