-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref: MANAGER-16104 Signed-off-by: Quentin Pavy <[email protected]>
- Loading branch information
Quentin Pavy
committed
Dec 16, 2024
1 parent
086e32a
commit fdb82d7
Showing
4 changed files
with
369 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/manager/apps/vrack-services/src/pages/create-subnet/subnetCreate.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
231 changes: 231 additions & 0 deletions
231
packages/manager/apps/vrack-services/src/pages/subnets/SubnetsTab.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
import { describe, it } from 'vitest'; | ||
import '@testing-library/jest-dom'; | ||
import { | ||
assertModalVisibility, | ||
assertTextVisibility, | ||
getButtonByLabel, | ||
} from '@ovh-ux/manager-core-test-utils'; | ||
import { waitFor, fireEvent, screen } from '@testing-library/react'; | ||
import { ODS_BUTTON_VARIANT, ODS_ICON_NAME } from '@ovhcloud/ods-components'; | ||
import { | ||
assertModalTitle, | ||
assertOsdFormInputInError, | ||
changeInputValueByLabelText, | ||
getButtonByIcon, | ||
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 display the subnets onboarding if no subnet exist', async () => { | ||
await renderTest({ | ||
nbVs: 1, | ||
initialRoute: urls.overview.replace(':id', vrackServicesList[0].id), | ||
}); | ||
|
||
const subnetTab = await waitFor(() => | ||
screen.getByText(labels.dashboard.subnetsTabLabel), | ||
); | ||
|
||
await waitFor(() => fireEvent.click(subnetTab)); | ||
|
||
await assertTextVisibility(labels.subnets.subnetsOnboardingTitle); | ||
}); | ||
|
||
it('should display the subnets listing if subnet exist', async () => { | ||
await renderTest({ | ||
nbVs: 2, | ||
initialRoute: urls.overview.replace(':id', vrackServicesList[1].id), | ||
}); | ||
|
||
const subnetTab = await waitFor(() => | ||
screen.getByText(labels.dashboard.subnetsTabLabel), | ||
); | ||
|
||
await waitFor(() => fireEvent.click(subnetTab)); | ||
|
||
await assertTextVisibility(labels.subnets.subnetDatagridDisplayNameLabel); | ||
await assertTextVisibility( | ||
vrackServicesList[1].currentState.subnets[0].displayName, | ||
); | ||
await assertTextVisibility( | ||
vrackServicesList[1].currentState.subnets[0].serviceRange.cidr, | ||
); | ||
}); | ||
|
||
it('should limit the subnets to 1', async () => { | ||
const { container } = await renderTest({ | ||
nbVs: 2, | ||
initialRoute: urls.subnetsListing.replace(':id', vrackServicesList[1].id), | ||
}); | ||
|
||
await assertTextVisibility(labels.subnets.betaSubnetLimitMessage); | ||
await getButtonByLabel({ | ||
container, | ||
label: labels.subnets.createSubnetButtonLabel, | ||
disabled: true, | ||
}); | ||
}); | ||
|
||
it('should edit a subnet', async () => { | ||
const { container } = await renderTest({ | ||
nbVs: 2, | ||
initialRoute: urls.subnetsListing.replace(':id', vrackServicesList[1].id), | ||
}); | ||
|
||
const actionMenuButton = await getButtonByIcon({ | ||
container, | ||
iconName: ODS_ICON_NAME.ELLIPSIS, | ||
}); | ||
|
||
await waitFor(() => fireEvent.click(actionMenuButton)); | ||
|
||
const editLink = await getButtonByLabel({ | ||
container, | ||
label: labels.subnets['action-editSubnet'], | ||
}); | ||
|
||
await waitFor(() => fireEvent.click(editLink)); | ||
|
||
await assertModalTitle({ | ||
container, | ||
title: labels.subnets.modalSubnetUpdateHeadline, | ||
}); | ||
|
||
// not /24 | ||
await changeInputValueByLabelText({ | ||
inputLabel: labels.subnets.cidrLabel, | ||
value: '10.0.0.0/23', | ||
}); | ||
await assertOsdFormInputInError({ | ||
inputLabel: labels.subnets.cidrLabel, | ||
inError: true, | ||
}); | ||
|
||
// didn't change | ||
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: true, | ||
}); | ||
|
||
// new value is correct | ||
await changeInputValueByLabelText({ | ||
inputLabel: labels.subnets.cidrLabel, | ||
value: '11.0.0.0/24', | ||
}); | ||
await assertOsdFormInputInError({ | ||
inputLabel: labels.subnets.cidrLabel, | ||
inError: false, | ||
}); | ||
const submitButton = await getButtonByVariant({ | ||
container, | ||
variant: ODS_BUTTON_VARIANT.flat, | ||
disabled: false, | ||
}); | ||
|
||
await waitFor(() => fireEvent.click(submitButton)); | ||
|
||
await assertModalVisibility({ container, isVisible: false }); | ||
}); | ||
|
||
it('should display an error if api fail to edit a subnet', async () => { | ||
const { container } = await renderTest({ | ||
nbVs: 2, | ||
initialRoute: urls.subnetsListing.replace(':id', vrackServicesList[1].id), | ||
updateKo: true, | ||
}); | ||
|
||
const actionMenuButton = await getButtonByIcon({ | ||
container, | ||
iconName: ODS_ICON_NAME.ELLIPSIS, | ||
}); | ||
|
||
await waitFor(() => fireEvent.click(actionMenuButton)); | ||
|
||
const editLink = await getButtonByLabel({ | ||
container, | ||
label: labels.subnets['action-editSubnet'], | ||
}); | ||
|
||
await waitFor(() => fireEvent.click(editLink)); | ||
|
||
// new value is correct | ||
await changeInputValueByLabelText({ | ||
inputLabel: labels.subnets.cidrLabel, | ||
value: '11.0.0.0/24', | ||
}); | ||
await assertOsdFormInputInError({ | ||
inputLabel: labels.subnets.cidrLabel, | ||
inError: false, | ||
}); | ||
const submitButton = await getButtonByVariant({ | ||
container, | ||
variant: ODS_BUTTON_VARIANT.flat, | ||
disabled: false, | ||
}); | ||
|
||
await waitFor(() => fireEvent.click(submitButton)); | ||
|
||
await assertModalVisibility({ container, isVisible: true }); | ||
await assertTextVisibility( | ||
labels.subnets.subnetUpdateError.replace('{{error}}', 'Update vs error'), | ||
); | ||
}); | ||
|
||
it('should delete a subnet', async () => { | ||
const { container } = await renderTest({ | ||
nbVs: 2, | ||
initialRoute: urls.subnetsListing.replace(':id', vrackServicesList[1].id), | ||
}); | ||
|
||
const actionMenuButton = await getButtonByIcon({ | ||
container, | ||
iconName: ODS_ICON_NAME.ELLIPSIS, | ||
}); | ||
|
||
await waitFor(() => fireEvent.click(actionMenuButton)); | ||
|
||
const editLink = await getButtonByLabel({ | ||
container, | ||
label: labels.subnets['action-deleteSubnet'], | ||
}); | ||
|
||
await waitFor(() => fireEvent.click(editLink)); | ||
|
||
await assertModalTitle({ | ||
container, | ||
title: labels.subnets.modalDeleteSubnetHeadline, | ||
}); | ||
await getButtonByVariant({ | ||
container, | ||
variant: ODS_BUTTON_VARIANT.flat, | ||
disabled: true, | ||
}); | ||
await changeInputValueByLabelText({ | ||
inputLabel: labels.subnets.modalDeleteSubnetInputLabel, | ||
value: 'TERMINATE', | ||
}); | ||
|
||
const submitButton = await getButtonByVariant({ | ||
container, | ||
variant: ODS_BUTTON_VARIANT.flat, | ||
disabled: false, | ||
}); | ||
|
||
await waitFor(() => fireEvent.click(submitButton)); | ||
|
||
await assertModalVisibility({ container, isVisible: false }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters