Skip to content

Commit

Permalink
feat(hpc-vmware-managed-vcd): add integration tests
Browse files Browse the repository at this point in the history
ref: MANAGER-15566

Signed-off-by: Nicolas Pierre-charles <[email protected]>
  • Loading branch information
Nicolas Pierre-charles committed Oct 15, 2024
1 parent d7a5c5f commit fb5f369
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 35 deletions.
17 changes: 7 additions & 10 deletions packages/manager/apps/hpc-vmware-managed-vcd/mocks/iam/iam.mock.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { IamCheckResponse } from '@ovh-ux/manager-react-components';
import { organizationList } from '../vcd-organization/vcd-organization.mock';
import { iamActions } from '@/utils/iam.constants';

export const resourceList: IamCheckResponse[] = [
{
urn: organizationList[0].iam.urn,
authorizedActions: [
'vmwareCloudDirectorBackup:apiovh:get',
'vmwareCloudDirector:apiovh:organization/get',
'account:apiovh:iam/resource/edit',
'account:apiovh:service/terminate',
iamActions.vmwareCloudDirectorApiovhOrganizationEdit,
iamActions.vmwareCloudDirectorApiovhOrganizationVirtualDataCenterEdit,
],
unauthorizedActions: [],
},
{
urn: organizationList[1].iam.urn,
authorizedActions: [],
unauthorizedActions: [
'vmwareCloudDirectorBackup:apiovh:get',
'vmwareCloudDirector:apiovh:organization/get',
'account:apiovh:iam/resource/edit',
'account:apiovh:service/terminate',
authorizedActions: [
iamActions.vmwareCloudDirectorApiovhOrganizationEdit,
iamActions.vmwareCloudDirectorApiovhOrganizationVirtualDataCenterEdit,
],
unauthorizedActions: [],
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import IVcdDatacentre from '../../src/types/vcd-datacenter.interface';

export const datacentreList: IVcdDatacentre[] = [
{
id: 'vdc-eu-central-waw-adc311b5-0c0b-4071-b48f-b20813868bcf',
resourceStatus: 'READY',
currentState: {
commercialRange: 'STANDARD',
description:
'Pour vous proposer une description adaptée, pourriez-vous me donner plus de détails sur votre service ? Cela me permettra de créer une description précise et impactante qui tient dans la limite des 255 caractères.',
ipQuota: 10,
memoryQuota: 64,
name: 'vdc-eu-central-waw-adc311b5-0c0b-4071-b48f-b20813868bcf',
region: 'EU-CENTRAL-WAW',
storageQuota: 1,
vCPUCount: 16,
vCPUSpeed: 3,
},
currentTasks: [],
targetSpec: {
description:
'Pour vous proposer une description adaptée, pourriez-vous me donner plus de détails sur votre service ? Cela me permettra de créer une description précise et impactante qui tient dans la limite des 255 caractères.',
vCPUSpeed: 3,
},
updatedAt: '2024-09-23T13:53:49Z',
iam: {
id: '33dda1c2-b24e-4db2-b7f3-4f3a8e08d68f',
urn:
'urn:v1:eu:resource:vmwareCloudDirector:org-eu-central-waw-366861de-e0e4-4ad5-a4c5-e9f80d744142/virtualDataCenter/vdc-eu-central-waw-adc311b5-0c0b-4071-b48f-b20813868bcf',
},
},
];
Original file line number Diff line number Diff line change
@@ -1,28 +1,61 @@
import { PathParams } from 'msw';
import { Handler } from '../../../../../../playwright-helpers';
import { organizationList } from './vcd-organization.mock';
import { datacentreList } from './vcd-datacentre.mock';

export type GetOrganizationMocksParams = {
isOrganizationKo?: boolean;
isOrganizationUpdateKo?: boolean;
nbOrganization?: number;
allOrgsBackedUp?: boolean;
isDatacentresKo?: boolean;
nbDatacentres?: number;
};

const findOrganizationById = (params: PathParams) =>
organizationList.find(({ id }) => id === params.id);

export const getOrganizationMocks = ({
isOrganizationKo,
isOrganizationUpdateKo,
nbOrganization = Number.POSITIVE_INFINITY,
allOrgsBackedUp,
isDatacentresKo,
nbDatacentres = Number.POSITIVE_INFINITY,
}: GetOrganizationMocksParams): Handler[] => {
const nb = allOrgsBackedUp ? 1 : nbOrganization;
return [
{
url: '/vmwareCloudDirector/organization/:id/virtualDataCenter',
response: isDatacentresKo
? {
message: 'Datacentres error',
}
: datacentreList.slice(0, nbDatacentres),
api: 'v2',
status: isDatacentresKo ? 500 : 200,
},
{
url: '/vmwareCloudDirector/organization/:id',
response: isOrganizationUpdateKo
? {
message: 'Organization update error',
}
: {},
method: 'put',
api: 'v2',
status: isOrganizationUpdateKo ? 500 : 200,
},
{
url: '/vmwareCloudDirector/organization/:id',
response: (_: unknown, params: PathParams) =>
findOrganizationById(params),
isOrganizationKo
? {
message: 'Organization error',
}
: findOrganizationById(params),
api: 'v2',
status: isOrganizationKo ? 500 : 200,
},
{
url: '/vmwareCloudDirector/organization',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ export const getVeeamBackupMocks = ({
}: GetVeeamBackupMocksParams): Handler[] => [
{
url: '/vmwareCloudDirector/backup/:id',
response: (_: unknown, params: PathParams) => findBackupById(params),
response: (_: unknown, params: PathParams) =>
isBackupKo
? {
message: 'Backup error',
}
: findBackupById(params),
status: isBackupKo ? 500 : 200,
api: 'v2',
},
Expand Down
1 change: 1 addition & 0 deletions packages/manager/apps/hpc-vmware-managed-vcd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@testing-library/dom": "^10.1.0",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^16.0.0",
"@testing-library/user-event": "^13.2.1",
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"@vitejs/plugin-react": "^4.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const getVcdOrganizationBackup = async (
organizationId: string,
): Promise<ApiResponse<IVcdOrganizationBackup>> =>
apiClient.v2.get(
`${VCD_ORGANIZATION_ROUTE}/backup/${organizationId}-veeam-backup`,
`/vmwareCloudDirector/backup/${organizationId}-veeam-backup`,
);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import userEvents from '@testing-library/user-event';
import { screen, waitFor } from '@testing-library/react';
import { renderTest, labels } from '../../../test-utils';
import { organizationList } from '../../../../mocks/vcd-organization/vcd-organization.mock';

describe('Organization Dashboard Page', () => {
it('display the dashboard page', async () => {
await renderTest();
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 },
);

expect(
screen.getByText(organizationList[0].currentState.description),
).toBeVisible();
});

it('display an error', async () => {
await renderTest({
initialRoute: `/${organizationList[0].id}`,
isOrganizationKo: true,
});
await waitFor(
() => expect(screen.getByText('Organization error')).toBeVisible(),
{ timeout: 30000 },
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import userEvents from '@testing-library/user-event';
import { screen, waitFor, fireEvent, within } from '@testing-library/react';
import { renderTest, labels } from '../../../../test-utils';
import { organizationList } from '../../../../../mocks/vcd-organization/vcd-organization.mock';

const changeInputAndSubmit = async () => {
const input = screen.getByLabelText('edit-input');
const event = new CustomEvent('odsValueChange');
Object.defineProperty(event, 'target', { value: { value: 'new name' } });
await waitFor(() => fireEvent(input, event));

const modifyButton = screen.getByText(
labels.dashboard.managed_vcd_dashboard_edit_modal_cta_edit,
{ exact: true },
);

return waitFor(() => userEvents.click(modifyButton));
};

const checkModal = async ({
container,
isVisible,
}: {
container: HTMLElement;
isVisible: boolean;
}) =>
waitFor(
() => {
const modal = container.querySelector('osds-modal');
isVisible

Check failure on line 30 in packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/organization/general-information/OrganizationGeneralInformation.spec.tsx

View workflow job for this annotation

GitHub Actions / Lint Code Base

Expected an assignment or function call and instead saw an expression
? expect(modal).toBeInTheDocument()
: expect(modal).not.toBeInTheDocument();
},
{ timeout: 30000 },
);

describe('Organization General Information Page', () => {
it('modify the name of the company', async () => {
const { container } = await renderTest({
initialRoute: `/${organizationList[1].id}`,
});

await waitFor(
() =>
expect(
screen.getByText(
labels.dashboard.managed_vcd_dashboard_data_protection,
),
).toBeVisible(),
{ timeout: 30000 },
);

let editButton: HTMLElement;
await waitFor(
() => {
editButton = screen.getAllByTestId('editIcon')[0];

Check failure on line 56 in packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/organization/general-information/OrganizationGeneralInformation.spec.tsx

View workflow job for this annotation

GitHub Actions / Lint Code Base

Use array destructuring
return expect(editButton).not.toHaveAttribute('disabled');
},
{ timeout: 30000 },
);
await waitFor(() => userEvents.click(editButton));

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

await changeInputAndSubmit();

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

expect(
screen.queryByText(
labels.dashboard.managed_vcd_dashboard_edit_name_modal_success,
),
).toBeVisible();
});

it('trying to update name displays an error if update organization service is KO', async () => {
const { container } = await renderTest({
initialRoute: `/${organizationList[0].id}/edit-name`,
isOrganizationUpdateKo: true,
});

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

await changeInputAndSubmit();

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

await waitFor(
() =>
expect(
within(
container.querySelector('osds-modal') as HTMLElement,
).getByText('Organization update error', { exact: false }),
).toBeVisible(),
{ timeout: 30000 },
);
});

it('modify the description of the company', async () => {
const { container } = await renderTest({
initialRoute: `/${organizationList[1].id}`,
});

await waitFor(
() =>
expect(
screen.getByText(
labels.dashboard.managed_vcd_dashboard_data_protection,
),
).toBeVisible(),
{ timeout: 30000 },
);

let editButton: HTMLElement;
await waitFor(
() => {
editButton = screen.getAllByTestId('editIcon')[1];

Check failure on line 117 in packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/organization/general-information/OrganizationGeneralInformation.spec.tsx

View workflow job for this annotation

GitHub Actions / Lint Code Base

Use array destructuring
return expect(editButton).not.toHaveAttribute('disabled');
},
{ timeout: 30000 },
);
await waitFor(() => userEvents.click(editButton));

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

await changeInputAndSubmit();

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

expect(
screen.queryByText(
labels.dashboard.managed_vcd_dashboard_edit_description_modal_success,
),
).toBeVisible();
});

it('trying to update description displays an error if update organization service is KO', async () => {
const { container } = await renderTest({
initialRoute: `/${organizationList[0].id}/edit-description`,
isOrganizationUpdateKo: true,
});

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

await changeInputAndSubmit();

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

await waitFor(
() =>
expect(
within(
container.querySelector('osds-modal') as HTMLElement,
).getByText('Organization update error', { exact: false }),
).toBeVisible(),
{ timeout: 30000 },
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import {
} from '@ovh-ux/manager-react-components';
import { OdsHTMLAnchorElementTarget } from '@ovhcloud/ods-common-core';

import DatagridContainer, {
TDatagridContainerProps,
} from '@/components/datagrid/container/DatagridContainer.component';
import DatagridContainer from '@/components/datagrid/container/DatagridContainer.component';
import { urls } from '@/routes/routes.constant';
import IVcdOrganization from '@/types/vcd-organization.interface';
import { VCD_ORGANIZATION_ROUTE } from '@/data/api/hpc-vmware-managed-vcd.constants';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { screen, waitFor } from '@testing-library/react';
import { renderTest, labels } from '../../../test-utils';
import { organizationList } from '../../../../mocks/vcd-organization/vcd-organization.mock';

describe('Organizations Listing Page', () => {
it('display the listing page', async () => {
await renderTest();
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 waitFor(() =>
expect(
screen.getByText(organizationList[0].currentState.fullName),
).toBeVisible(),
);
});
});
Loading

0 comments on commit fb5f369

Please sign in to comment.