Skip to content

Commit

Permalink
test(kms): add create kms integration tests
Browse files Browse the repository at this point in the history
ref: MANAGER-15111

Signed-off-by: Romain Jamet <[email protected]>
  • Loading branch information
Romain Jamet authored and darsene committed Dec 3, 2024
1 parent 02973b4 commit c72767a
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const RegionSelector = ({
{orderCatalogOKMS && !isLoading && (
<OsdsSelect
inline
data-testid="select-region"
size={ODS_SELECT_SIZE.md}
onOdsValueChange={(v) => {
const value = v.detail.value.toString();
Expand All @@ -110,7 +111,11 @@ const RegionSelector = ({
{orderCatalogOKMS.plans[0].configurations[0].values.map(
(region) => {
return (
<OsdsSelectOption value={region} key={region}>
<OsdsSelectOption
value={region}
key={region}
data-testid={`select-region-option-${region}`}
>
<Region
mode={'region'}
name={region.toLowerCase().replaceAll('_', '-')}
Expand All @@ -123,7 +128,7 @@ const RegionSelector = ({
)}
</OsdsFormField>
</div>
<div className="flex flex-row mt-6">
<div className="flex flex-row mt-6 gap-4">
<OsdsButton
className="mr-1"
size={ODS_BUTTON_SIZE.sm}
Expand All @@ -146,7 +151,7 @@ const RegionSelector = ({
size={ODS_BUTTON_SIZE.sm}
variant={ODS_BUTTON_VARIANT.flat}
color={ODS_THEME_COLOR_INTENT.primary}
disabled={selectedRegion ? undefined : true}
disabled={!selectedRegion || undefined}
onClick={() => {
trackClick({
location: PageLocation.funnel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export const getOrderCatalogOKMS = async (
ovhSubsidiary: string,
): Promise<OKMSCatalog> => {
const { data } = await apiClient.v6.get<OKMSCatalog>(
`/order/catalog/public/okms?ovhSubsidiary=${ovhSubsidiary}`,
'/order/catalog/public/okms',
{ params: { ovhSubsidiary } },
);
return data;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Handler } from '../../../../../../../playwright-helpers';
import { catalogMock } from './catalog.mock';

export type GetCatalogKmsMocksParams = {
isCatalogOkmsKo?: boolean;
};

export const getCatalogKmsMocks = ({
isCatalogOkmsKo = false,
}: GetCatalogKmsMocksParams): Handler[] => {
return [
{
url: '/order/catalog/public/okms',
response: isCatalogOkmsKo
? {
message: 'catalog error',
}
: catalogMock,
status: isCatalogOkmsKo ? 500 : 200,
api: 'v6',
},
];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { OKMSCatalog } from '@/types/orderCatalogOKMS.type';

export const catalogMock: OKMSCatalog = {
plans: [
{
configurations: [
{
name: 'region',
isCustom: false,
isMandatory: true,
values: ['EU_WEST_RBX', 'EU_WEST_SBG'],
},
],
},
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
import { act, screen, waitFor } from '@testing-library/react';
import { vi } from 'vitest';
import userEvent from '@testing-library/user-event';
import { renderTestApp } from '@/utils/tests/renderTestApp';
import '@testing-library/jest-dom';
import { labels } from '@/utils/tests/init.i18n';
import { ROUTES_URLS } from '@/routes/routes.constants';
import { catalogMock } from '@/mocks/catalog/catalog.mock';
import * as getKMSExpressOrderLink from '../../components/layout-helpers/Create/order-utils';

Object.assign(window, {
open: vi.fn().mockImplementation(() => Promise.resolve()),
});

const mockedUrl = 'mocked-url';
vi.spyOn(getKMSExpressOrderLink, 'getKMSExpressOrderLink').mockReturnValue(
mockedUrl,
);

describe('KMS creation page test suite', () => {
it('should display the KMS creation page', async () => {
await renderTestApp(`/${ROUTES_URLS.createKeyManagementService}`);

await waitFor(
() =>
expect(
screen.getByText(
labels.create.key_management_service_create_subtitle,
),
).toBeVisible(),

{ timeout: 30_000 },
);

expect(
screen.getByText(
labels.create.key_management_service_create_region_title,
),
).toBeVisible();

expect(
screen.getByText(
labels.create.key_management_service_create_region_description,
),
).toBeVisible();

await waitFor(
() =>
expect(
screen.getByText(
labels.create.key_management_service_create_select_placeholder,
),
).toBeVisible(),

{ timeout: 10_000 },
);

expect(
screen.getByText(labels.create.key_management_service_create_cta_cancel),
).toBeEnabled();

expect(
screen.getByText(labels.create.key_management_service_create_cta_order),
).toBeDisabled();
});

it(`should navigate back to the list on click on ${labels.create.key_management_service_create_cta_cancel}`, async () => {
await renderTestApp(`/${ROUTES_URLS.createKeyManagementService}`);

await waitFor(
() =>
expect(
screen.getByText(
labels.create.key_management_service_create_cta_cancel,
),
).toBeEnabled(),
{
timeout: 10_000,
},
);

await userEvent.click(
screen.getByText(labels.create.key_management_service_create_cta_cancel),
);

await waitFor(
() =>
expect(
screen.getByText(labels.listing.key_management_service_listing_title),
).toBeVisible(),
{ timeout: 10_000 },
);
});

it('should display an error if the API is KO', async () => {
await renderTestApp(`/${ROUTES_URLS.createKeyManagementService}`, {
isCatalogOkmsKo: true,
});

await waitFor(
() => expect(screen.getByAltText('OOPS')).toBeInTheDocument(),
{
timeout: 10_000,
},
);
});

it('should activate order button on region select', async () => {
await renderTestApp(`/${ROUTES_URLS.createKeyManagementService}`);

await waitFor(
() =>
expect(
screen.getByText(
labels.create.key_management_service_create_select_placeholder,
),
).toBeVisible(),
{
timeout: 10_000,
},
);

await act(() => userEvent.click(screen.getByTestId('select-region')));

await userEvent.click(
screen.getByTestId(
`select-region-option-${catalogMock.plans[0].configurations[0].values[0]}`,
),
);

await waitFor(
() =>
expect(
screen.getByText(
labels.create.key_management_service_create_cta_order,
),
).toBeEnabled(),
{ timeout: 10_000 },
);
});
});

describe('order KMS test suite', () => {
beforeEach(async () => {
await renderTestApp(`/${ROUTES_URLS.createKeyManagementService}`);

await waitFor(
() =>
expect(
screen.getByText(
labels.create.key_management_service_create_select_placeholder,
),
).toBeVisible(),
{
timeout: 10_000,
},
);

await act(() => userEvent.click(screen.getByTestId('select-region')));

await act(() =>
userEvent.click(
screen.getByTestId(
`select-region-option-${catalogMock.plans[0].configurations[0].values[0]}`,
),
),
);

expect(
screen.getByText(labels.create.key_management_service_create_cta_order),
).toBeEnabled();

await act(() =>
userEvent.click(
screen.getByText(labels.create.key_management_service_create_cta_order),
),
);
});

it('should open the order page on a new tab on page load', async () => {
expect(window.open).toHaveBeenCalledWith(
mockedUrl,
'_blank',
'noopener,noreferrer',
);
});

it('should display the order confirmation page', async () => {
expect(
screen.getByText(
labels.create.key_management_service_create_order_initiated_title,
),
).toBeVisible();

expect(
screen.getByText(
labels.create.key_management_service_create_order_initiated_subtitle,
),
).toBeVisible();

expect(screen.getByText(mockedUrl)).toBeVisible();

expect(
screen.getByText(
labels.create.key_management_service_create_order_initiated_info,
),
).toBeVisible();

expect(
screen.getByText(
labels.create.key_management_service_create_order_initiated_cta_done,
),
).toBeVisible();
});

it('should open the order page on link click', async () => {
expect(screen.getByText(mockedUrl)).toBeVisible();

await userEvent.click(screen.getByText(mockedUrl));

expect(window.open).toHaveBeenCalledWith(
mockedUrl,
'_blank',
'noopener,noreferrer',
);
});

it(`should redirect to the listing page on click on ${labels.create.key_management_service_create_order_initiated_cta_done}`, async () => {
expect(
screen.getByText(
labels.create.key_management_service_create_order_initiated_cta_done,
),
).toBeEnabled();

await act(() =>
userEvent.click(
screen.getByText(
labels.create.key_management_service_create_order_initiated_cta_done,
),
),
);

await waitFor(
() =>
expect(
screen.getByText(labels.listing.key_management_service_listing_title),
).toBeVisible(),
{ timeout: 10_000 },
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import {
GetFeatureAvailabilituMocksParams,
getFeatureAvailabilityMocks,
} from '@/mocks/feature-availability/feature-availability.handler';
import {
getCatalogKmsMocks,
GetCatalogKmsMocksParams,
} from '@/mocks/catalog/catalog.handler';

let context: ShellContextType;
let i18nValue: i18n;
Expand All @@ -44,6 +48,7 @@ export const renderTestApp = async (
GetCredentialsMockParams &
GetServicesMocksParams &
GetFeatureAvailabilituMocksParams &
GetCatalogKmsMocksParams &
GetIamAuthorizationMockParams = {},
) => {
global.server?.resetHandlers(
Expand All @@ -55,6 +60,7 @@ export const renderTestApp = async (
...getIamMocks(mockParams),
...getCredentialsMock(mockParams),
...getFeatureAvailabilityMocks(mockParams),
...getCatalogKmsMocks(mockParams),
]),
);

Expand Down

0 comments on commit c72767a

Please sign in to comment.