Skip to content

Commit

Permalink
feat(vrack-services): subnets dissociate and create vs it (#14596)
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin Pavy <[email protected]>
  • Loading branch information
qpavy authored Dec 16, 2024
1 parent 84f7adb commit cba800d
Show file tree
Hide file tree
Showing 8 changed files with 550 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"productStatus": "DRAFT",
"subnets": [
{
"cidr": "192.168.0.0/16",
"cidr": "10.0.0.0/24",
"displayName": "My.Subnet",
"serviceEndpoints": [
{
Expand All @@ -54,7 +54,7 @@
}
],
"serviceRange": {
"cidr": "192.168.0.0/29",
"cidr": "10.0.0.0/29",
"remainingIps": 1,
"reservedIps": 5,
"usedIps": 2
Expand Down
10 changes: 5 additions & 5 deletions packages/manager/apps/vrack-services/mocks/vrack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getVrackMocks = ({
{
url: '/vrack/:id/task/:taskId',
response: vrackTaskKo ? { message: 'Task error' } : {},
status: vrackTaskKo ? 500 : 404,
status: vrackTaskKo ? 400 : 404,
api: 'v6',
},
{
Expand All @@ -35,7 +35,7 @@ export const getVrackMocks = ({
function: '',
id: 123456,
},
status: dissociateKo ? 500 : 200,
status: dissociateKo ? 400 : 200,
api: 'v6',
method: 'delete',
},
Expand All @@ -47,7 +47,7 @@ export const getVrackMocks = ({
}
: getAllowedServicesResponse(nbEligibleVrackServices),
api: 'v6',
status: getVrackEligibleServicesKo ? 500 : 200,
status: getVrackEligibleServicesKo ? 400 : 200,
},
{
url: '/vrack/:id/vrackServices',
Expand All @@ -60,7 +60,7 @@ export const getVrackMocks = ({
id: 123456,
},
method: 'post',
status: associationKo ? 500 : 200,
status: associationKo ? 400 : 200,
api: 'v6',
},
{
Expand All @@ -76,6 +76,6 @@ export const getVrackMocks = ({
}
: vrackList.slice(0, nbVrack),
api: 'v6',
status: getVrackKo ? 500 : 200,
status: getVrackKo ? 400 : 200,
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"modalDescriptionLine1": "Pour activer vRack Services, vous devez créer un vRack.",
"modalDescriptionLine2": "Souhaitez vous commander un vRack en parallèle de l'activation de vRack Services ?",
"modalDescriptionLine4": "Vous avez demandé la création d'un vRack lors de l'activation de vRack Services.",
"modalDescriptionLine5": "Pour finaliser l'activation de vRack Services, merci d'accepter les termes et conditions suivantes.",
"modalDescriptionLine5": "Pour finaliser l'activation de vRack Services, merci d'accepter les termes et conditions suivantes.",
"modalDescriptionLine3": "Prix du vRack : 0€",
"modalCancelButtonLabel": "Annuler",
"modalConfirmVrackButtonLabel": "Oui",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { describe, it } from 'vitest';
import '@testing-library/jest-dom';
import { assertTextVisibility } from '@ovh-ux/manager-core-test-utils';
import { waitFor, fireEvent } from '@testing-library/react';
import { ODS_BUTTON_VARIANT } from '@ovhcloud/ods-components';
import {
assertOsdFormInputInError,
changeInputValueByLabelText,
clickOnRadioByName,
getButtonByVariant,
labels,
renderTest,
} from '../../test-utils';
import vrackServicesList from '../../../mocks/vrack-services/get-vrack-services.json';
import { urls } from '@/routes/routes.constants';

describe('Vrack Services subnets page test suite', () => {
it('should create a subnet', async () => {
const { container } = await renderTest({
nbVs: 2,
initialRoute: urls.createSubnet.replace(':id', vrackServicesList[1].id),
});

await assertTextVisibility(labels.subnets.subnetNameLabel);

await changeInputValueByLabelText({
inputLabel: labels.subnets.cidrLabel,
value: '10.0.0.0/23',
});
await assertOsdFormInputInError({
inputLabel: labels.subnets.cidrLabel,
inError: true,
});

await changeInputValueByLabelText({
inputLabel: labels.subnets.cidrLabel,
value: '10.0.0.0/24',
});
await assertOsdFormInputInError({
inputLabel: labels.subnets.cidrLabel,
inError: false,
});
await getButtonByVariant({
container,
variant: ODS_BUTTON_VARIANT.flat,
disabled: false,
});

clickOnRadioByName({ container, name: 'hasVlan', value: 'vlanNumber' });
await getButtonByVariant({
container,
variant: ODS_BUTTON_VARIANT.flat,
disabled: true,
});
await changeInputValueByLabelText({
inputLabel: labels.subnets.vlanNumberLabel,
value: '20',
});
const submitButton = await getButtonByVariant({
container,
variant: ODS_BUTTON_VARIANT.flat,
disabled: false,
});

await waitFor(() => fireEvent.click(submitButton));

await assertTextVisibility(labels.subnets.subnetDatagridDisplayNameLabel);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import {
assertTextVisibility,
getButtonByLabel,
} from '@ovh-ux/manager-core-test-utils';
import { screen, waitFor, act } from '@testing-library/react';
import { screen, waitFor, act, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { labels, renderTest } from '../../test-utils';
import { assertModalTitle, labels, renderTest } from '../../test-utils';
import { urls } from '@/routes/routes.constants';

describe('Vrack Services create page test suite', () => {
it('should display the create form with regions', async () => {
Expand All @@ -35,9 +36,7 @@ describe('Vrack Services create page test suite', () => {
return regionRadioInput;
});

await act(() => {
user.click(regionRadio);
});
await waitFor(() => user.click(regionRadio));

await waitFor(() => {
expect(regionRadio.closest('osds-radio')).toHaveAttribute('checked');
Expand All @@ -53,8 +52,8 @@ describe('Vrack Services create page test suite', () => {
user.click(submitButton);
});

assertModalVisibility({ container, isVisible: true });
assertModalText({ container, text: labels.create.modalHeadline });
await assertModalVisibility({ container, isVisible: true });
await assertModalTitle({ container, title: labels.create.modalHeadline });
});

it('should redirect to listing page if user has no right to order vrs', async () => {
Expand All @@ -71,4 +70,61 @@ describe('Vrack Services create page test suite', () => {

await assertTextVisibility(labels.listing.listingDescription);
});

it('should display create with vRack', async () => {
const { container } = await renderTest({
initialRoute: urls.createConfirm.replace(':region', 'eu-west-rbx'),
nbVs: 1,
});

const createvrackButton = await getButtonByLabel({
container,
label: labels.create.modalConfirmVrackButtonLabel,
});

await waitFor(() => fireEvent.click(createvrackButton));

await assertModalText({
container,
text: labels.create.modalDescriptionLine4,
});
await assertModalText({
container,
text: labels.create.modalDescriptionLine5,
});

const cancelButton = await getButtonByLabel({
container,
label: labels.create.modalCancelButtonLabel,
});

await waitFor(() => fireEvent.click(cancelButton));

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

it('should display create without vRack', async () => {
const { container } = await renderTest({
initialRoute: urls.createConfirm.replace(':region', 'eu-west-rbx'),
nbVs: 1,
});

const createWithoutVrackButton = await getButtonByLabel({
container,
label: labels.create.modalNoVrackButtonLabel,
});

await waitFor(() => fireEvent.click(createWithoutVrackButton));

await waitFor(() => {
expect(
screen.queryByText(labels.create.modalDescriptionLine4),
).toBeNull();
});

await assertModalText({
container,
text: labels.create.modalDescriptionLine5,
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { describe, it } from 'vitest';
import '@testing-library/jest-dom';
import {
assertModalText,
assertModalVisibility,
getButtonByLabel,
} from '@ovh-ux/manager-core-test-utils';
import { waitFor, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { ODS_ICON_NAME } from '@ovhcloud/ods-components';
import {
assertModalTitle,
changeOdsSelectValueByTestId,
getButtonByIcon,
labels,
renderTest,
} from '../../test-utils';
import vrackServicesList from '../../../mocks/vrack-services/get-vrack-services.json';
import { urls } from '@/routes/routes.constants';
import { vrackList } from '../../../mocks/vrack/vrack';

describe('Vrack Services dissociate vrack test suite', () => {
it('from dashboard should dissociate vrack', async () => {
const { container } = await renderTest({
initialRoute: urls.overview.replace(':id', vrackServicesList[5].id),
nbVs: 6,
});

const actionMenuButton = await getButtonByIcon({
container,
iconName: ODS_ICON_NAME.ELLIPSIS,
});

await waitFor(() => fireEvent.click(actionMenuButton));

const dissociateLink = await getButtonByLabel({
container,
label: labels.common.vrackActionDissociate,
});

await waitFor(() => fireEvent.click(dissociateLink));

await assertModalVisibility({ container, isVisible: true });
await assertModalTitle({
container,
title: labels.dissociate.modalDissociateHeadline,
});

await assertModalText({
container,
text: labels.dissociate.modalDissociateDescription,
});

const dissociateButton = await getButtonByLabel({
container,
label: labels.dissociate.modalDissociateConfirmButton,
});

await waitFor(() => userEvent.click(dissociateButton));

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

it('from dashboard, should not display error if dissociate fails', async () => {
const { container } = await renderTest({
initialRoute: urls.overviewDissociate
.replace(':id', vrackServicesList[5].id)
.replace('vrackId', vrackServicesList[5].currentState.vrackId),
nbVs: 6,
dissociateKo: true,
});

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

const dissociateButton = await getButtonByLabel({
container,
label: labels.dissociate.modalDissociateConfirmButton,
});

await waitFor(() => userEvent.click(dissociateButton));

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

await assertModalText({
container,
text: labels.dissociate.modalDissociateError.replace(
'{{error}}',
'Update error',
),
});
});

// it('from dashboard, display error when get vrack is in error', async () => {
// const { container } = await renderTest({
// initialRoute: urls.overviewAssociateAnother.replace(
// ':id',
// vrackServicesList[5].id,
// ),
// nbVs: 6,
// getVrackKo: true,
// });

// await assertModalVisibility({ container, isVisible: true });
// await assertModalText({
// container,
// text: labels.associate.modalVrackAssociationError.replace(
// '{{error}}',
// 'Get vRack KO',
// ),
// });
// });
});
Loading

0 comments on commit cba800d

Please sign in to comment.