Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hpc-vmware-managed-vcd): cleanup tests with test-utils #14260

Open
wants to merge 1 commit into
base: feat/vcd-veeam-postga
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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({
Expand Down Expand Up @@ -78,8 +79,8 @@ describe.skip('DatacentreGeneralInformationTile component unit test suite', () =
const { getByText } = render(
<QueryClientProvider client={queryClient}>
<DatacentreGeneralInformationTile
vcdOrganization={vcdOrg}
vcdDatacentre={datacentre}
vcdOrganization={vcdOrg as VCDOrganization}
vcdDatacentre={datacentre as VCDDatacentre}
/>
</QueryClientProvider>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import {
datacentreList,
} from '@ovh-ux/manager-module-vcd-api';
import {
checkModalError,
checkModalVisibility,
checkModal,
checkModalText,
waitForOptions,
} 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;
Expand All @@ -30,23 +30,20 @@ describe('Datacentre General Information Page', () => {
expect(
screen.getByText(labels.datacentres.managed_vcd_vdc_vcpu_count),
).toBeVisible(),
{ timeout: DEFAULT_TIMEOUT },
waitForOptions,
);

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();
}, waitForOptions);

await waitFor(() => userEvent.click(editButton));
await checkModalVisibility({ container, isVisible: true });
await checkModal({ container, isVisible: true });

await mockSubmitNewValue({ submitButtonLabel });
await checkModalVisibility({ container, isVisible: false });
await checkModal({ container, isVisible: false });

expect(
screen.queryByText(
Expand All @@ -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 checkModal({ container, isVisible: true });

await mockEditInputValue('');
await checkModalError({ container, error: expectedError });
await checkModalText({ container, text: expectedError });

await mockEditInputValue('a'.repeat(256));
await checkModalError({ container, error: expectedError });
await checkModalText({ container, text: expectedError });
});

it('display an error if update datacentre service is KO', async () => {
Expand All @@ -78,11 +75,11 @@ describe('Datacentre General Information Page', () => {
isDatacentreUpdateKo: true,
});

await checkModalVisibility({ container, isVisible: true });
await checkModal({ container, isVisible: true });

await mockSubmitNewValue({ submitButtonLabel });

await checkModalVisibility({ container, isVisible: true });
await checkModalError({ container, error: 'Datacentre update error' });
await checkModal({ container, isVisible: true });
await checkModalText({ container, text: 'Datacentre update error' });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -9,29 +10,19 @@ 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 () => {
await renderTest({
initialRoute: `/${organizationList[0].id}`,
isOrganizationKo: true,
});
await waitFor(
() => expect(screen.getByText('Organization error')).toBeVisible(),
{ timeout: 30000 },
);

await checkTextVisibility('Organization error');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
checkModal,
checkModalText,
waitForOptions,
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;
Expand All @@ -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();
}, waitForOptions);
await waitFor(() => userEvents.click(editButton));

await checkModalVisibility({ container, isVisible: true });
await checkModal({ container, isVisible: true });

await mockSubmitNewValue({ submitButtonLabel });

await checkModalVisibility({ container, isVisible: false });
await checkModal({ container, isVisible: false });
await checkTextVisibility(
labels.dashboard.managed_vcd_dashboard_edit_name_modal_success,
);
Expand All @@ -51,12 +46,12 @@ describe('Organization General Information Page', () => {
isOrganizationUpdateKo: true,
});

await checkModalVisibility({ container, isVisible: true });
await checkModal({ container, isVisible: true });

await mockSubmitNewValue({ submitButtonLabel });

await checkModalVisibility({ container, isVisible: true });
await checkModalError({ container, error: 'Organization update error' });
await checkModal({ container, isVisible: true });
await checkModalText({ container, text: 'Organization update error' });
});

it('modify the description of the organization', async () => {
Expand All @@ -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();
}, waitForOptions);
await waitFor(() => userEvents.click(editButton));

await checkModalVisibility({ container, isVisible: true });
await checkModal({ container, isVisible: true });

await mockSubmitNewValue({ submitButtonLabel });

await checkModalVisibility({ container, isVisible: false });
await checkModal({ container, isVisible: false });
await checkTextVisibility(
labels.dashboard.managed_vcd_dashboard_edit_description_modal_success,
);
Expand All @@ -94,12 +86,12 @@ describe('Organization General Information Page', () => {
isOrganizationUpdateKo: true,
});

await checkModalVisibility({ container, isVisible: true });
await checkModal({ container, isVisible: true });

await mockSubmitNewValue({ submitButtonLabel });

await checkModalVisibility({ container, isVisible: true });
await checkModalError({ container, error: 'Organization update error' });
await checkModal({ container, isVisible: true });
await checkModalText({ container, text: 'Organization update error' });
});

it('resets the password of the organization', async () => {
Expand All @@ -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 checkModal({ 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 checkModal({ container, isVisible: false });
await checkTextVisibility(
labels.dashboard.managed_vcd_dashboard_password_renew_success,
);
Expand All @@ -135,14 +130,15 @@ describe('Organization General Information Page', () => {
isOrganizationResetPasswordKo: true,
});

await checkModalVisibility({ container, isVisible: true });
await checkModal({ 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 checkModal({ container, isVisible: false });
await checkTextVisibility(
labels.dashboard.managed_vcd_dashboard_password_renew_error,
);
Expand Down
Loading
Loading