-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(kms): add create kms integration tests
ref: MANAGER-15111 Signed-off-by: Romain Jamet <[email protected]>
- Loading branch information
Showing
6 changed files
with
306 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
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
23 changes: 23 additions & 0 deletions
23
packages/manager/apps/key-management-service/src/mocks/catalog/catalog.handler.ts
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,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', | ||
}, | ||
]; | ||
}; |
16 changes: 16 additions & 0 deletions
16
packages/manager/apps/key-management-service/src/mocks/catalog/catalog.mock.ts
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,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'], | ||
}, | ||
], | ||
}, | ||
], | ||
}; |
251 changes: 251 additions & 0 deletions
251
packages/manager/apps/key-management-service/src/pages/create/createKms.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,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 }, | ||
); | ||
}); | ||
}); |
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