-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V2Wizard/Registration: Add request assertion tests
We need to start using `undefined` as the default state for when a value has not been defined. Previously we had used things like `’’` for string typed values. But this causes problems later when generating the request we send to image-builder. Using `undefined` is explicit and will make generating the requests much easier (as we don’t need to check for `’’`, determine the intent, and convert it to undefined if necessary). Explicit is better than implicit. With that in mind, tests have been added to ensure that the correct request is sent to the API for every option on the Registration step. This is facilitated using a new `spyOnRequest()` function. In the future, we will have similar tests for the rest of the steps. A few other minor things: 1. We need to get the `store` using `useStore()` for when we later call `store.getState()` because the tests use a different store that is configured in the renderer than the one we were importing. 2. In the wizardSlice, a new type RegistrationType is added that provides additional type safety instead of using `string`.
- Loading branch information
1 parent
841edd1
commit 8c31e6f
Showing
7 changed files
with
320 additions
and
16 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
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
207 changes: 207 additions & 0 deletions
207
src/test/Components/CreateImageWizardV2/steps/Registration/Registration.test.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,207 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { userEvent } from '@testing-library/user-event'; | ||
|
||
import { CREATE_BLUEPRINT } from '../../../../../constants'; | ||
import { | ||
CreateBlueprintRequest, | ||
ImageRequest, | ||
} from '../../../../../store/imageBuilderApi'; | ||
import { clickNext } from '../../../../testUtils'; | ||
import { | ||
enterBlueprintName, | ||
render, | ||
saveBlueprint, | ||
spyOnRequest, | ||
} from '../../wizardTestUtils'; | ||
|
||
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({ | ||
useChrome: () => ({ | ||
auth: { | ||
getUser: () => { | ||
return { | ||
identity: { | ||
internal: { | ||
org_id: 5, | ||
}, | ||
}, | ||
}; | ||
}, | ||
}, | ||
isBeta: () => false, | ||
isProd: () => true, | ||
getEnvironment: () => 'prod', | ||
}), | ||
})); | ||
|
||
const goToRegistrationStep = async () => { | ||
const bareMetalCheckBox = await screen.findByRole('checkbox', { | ||
name: /bare metal installer checkbox/i, | ||
}); | ||
await userEvent.click(bareMetalCheckBox); | ||
await clickNext(); | ||
}; | ||
|
||
const selectActivationKey = async () => { | ||
const activationKeyDropdown = await screen.findByRole('textbox', { | ||
name: 'Select activation key', | ||
}); | ||
await userEvent.click(activationKeyDropdown); | ||
const activationKey = await screen.findByRole('option', { | ||
name: 'name0', | ||
}); | ||
await userEvent.click(activationKey); | ||
}; | ||
|
||
const clickShowAdditionalConnectionOptions = async () => { | ||
const link = await screen.findByText('Show additional connection options'); | ||
await userEvent.click(link); | ||
}; | ||
|
||
const deselectEnableRemoteRemediations = async () => { | ||
const checkBox = await screen.findByRole('checkbox', { | ||
name: 'Enable remote remediations and system management with automation', | ||
}); | ||
await userEvent.click(checkBox); | ||
}; | ||
|
||
const deselectPredictiveAnalytics = async () => { | ||
const checkBox = await screen.findByRole('checkbox', { | ||
name: 'Enable predictive analytics and management capabilities', | ||
}); | ||
await userEvent.click(checkBox); | ||
}; | ||
|
||
const clickRegisterLater = async () => { | ||
const radioButton = await screen.findByRole('radio', { | ||
name: 'Register later', | ||
}); | ||
await userEvent.click(radioButton); | ||
}; | ||
|
||
const goToReviewStep = async () => { | ||
await clickNext(); | ||
await clickNext(); | ||
await clickNext(); | ||
await enterBlueprintName(); | ||
await clickNext(); | ||
}; | ||
|
||
describe('registration request generated correctly', () => { | ||
const imageRequest: ImageRequest = { | ||
architecture: 'x86_64', | ||
image_type: 'image-installer', | ||
upload_request: { | ||
options: {}, | ||
type: 'aws.s3', | ||
}, | ||
}; | ||
|
||
const blueprintRequest: CreateBlueprintRequest = { | ||
name: 'Red Velvet', | ||
description: '', | ||
distribution: 'rhel-93', | ||
image_requests: [imageRequest], | ||
customizations: {}, | ||
}; | ||
|
||
test('register + insights + rhc', async () => { | ||
await render(); | ||
await goToRegistrationStep(); | ||
await selectActivationKey(); | ||
await goToReviewStep(); | ||
|
||
const receivedRequestPromise = spyOnRequest(CREATE_BLUEPRINT); | ||
await saveBlueprint(); | ||
const receivedRequest = await receivedRequestPromise; | ||
|
||
const expectedSubscription = { | ||
'activation-key': 'name0', | ||
insights: true, | ||
rhc: true, | ||
organization: 5, | ||
'server-url': 'subscription.rhsm.redhat.com', | ||
'base-url': 'https://cdn.redhat.com/', | ||
}; | ||
const expectedRequest = { | ||
...blueprintRequest, | ||
customizations: { subscription: expectedSubscription }, | ||
}; | ||
|
||
expect(receivedRequest).toEqual(expectedRequest); | ||
}); | ||
|
||
test('register + insights', async () => { | ||
await render(); | ||
await goToRegistrationStep(); | ||
await clickShowAdditionalConnectionOptions(); | ||
await deselectEnableRemoteRemediations(); | ||
await selectActivationKey(); | ||
await goToReviewStep(); | ||
|
||
const receivedRequestPromise = spyOnRequest(CREATE_BLUEPRINT); | ||
await saveBlueprint(); | ||
const receivedRequest = await receivedRequestPromise; | ||
|
||
const expectedSubscription = { | ||
'activation-key': 'name0', | ||
insights: true, | ||
rhc: false, | ||
organization: 5, | ||
'server-url': 'subscription.rhsm.redhat.com', | ||
'base-url': 'https://cdn.redhat.com/', | ||
}; | ||
const expectedRequest = { | ||
...blueprintRequest, | ||
customizations: { subscription: expectedSubscription }, | ||
}; | ||
|
||
expect(receivedRequest).toEqual(expectedRequest); | ||
}); | ||
|
||
test('register', async () => { | ||
await render(); | ||
await goToRegistrationStep(); | ||
await clickShowAdditionalConnectionOptions(); | ||
await deselectPredictiveAnalytics(); | ||
await selectActivationKey(); | ||
await goToReviewStep(); | ||
|
||
const receivedRequestPromise = spyOnRequest(CREATE_BLUEPRINT); | ||
await saveBlueprint(); | ||
const receivedRequest = await receivedRequestPromise; | ||
|
||
const expectedSubscription = { | ||
'activation-key': 'name0', | ||
insights: false, | ||
rhc: false, | ||
organization: 5, | ||
'server-url': 'subscription.rhsm.redhat.com', | ||
'base-url': 'https://cdn.redhat.com/', | ||
}; | ||
const expectedRequest = { | ||
...blueprintRequest, | ||
customizations: { subscription: expectedSubscription }, | ||
}; | ||
|
||
expect(receivedRequest).toEqual(expectedRequest); | ||
}); | ||
|
||
test('register Later', async () => { | ||
await render(); | ||
await goToRegistrationStep(); | ||
await clickShowAdditionalConnectionOptions(); | ||
await clickRegisterLater(); | ||
await goToReviewStep(); | ||
|
||
const receivedRequestPromise = spyOnRequest(CREATE_BLUEPRINT); | ||
await saveBlueprint(); | ||
const receivedRequest = await receivedRequestPromise; | ||
|
||
const expectedRequest = { | ||
...blueprintRequest, | ||
customizations: {}, | ||
}; | ||
|
||
expect(receivedRequest).toEqual(expectedRequest); | ||
}); | ||
}); |
Oops, something went wrong.