diff --git a/package.json b/package.json index 95c68845..5035ea37 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "@redhat-cloud-services/frontend-components-config": "1.0.0", "@testing-library/react": "^11.0.4", "@testing-library/jest-dom": "^5.10.1", + "@testing-library/user-event": "^12.2.2", "babel-core": "^7.0.0-bridge.0", "babel-eslint": "^10.0.3", "babel-jest": "^26.1.0", diff --git a/src/SmartComponents/CreateImageWizard/CreateImageWizard.js b/src/SmartComponents/CreateImageWizard/CreateImageWizard.js index a73417a1..d8a21a86 100644 --- a/src/SmartComponents/CreateImageWizard/CreateImageWizard.js +++ b/src/SmartComponents/CreateImageWizard/CreateImageWizard.js @@ -58,17 +58,20 @@ const AmazonUploadComponent = (props) => { validated={ (props.errors['amazon-access-id'] && 'error') || 'default' }> props.setUploadOptions(Object.assign(props.upload.options, { access_key_id: value })) } /> props.setUploadOptions(Object.assign(props.upload.options, { secret_access_key: value })) } /> props.setUploadOptions(Object.assign(props.upload.options, { service: value })) }> { serviceOptions.map(option => ) } @@ -77,6 +80,7 @@ const AmazonUploadComponent = (props) => { helperTextInvalid={ (props.errors['amazon-region'] && props.errors['amazon-region'].value) || '' } validated={ (props.errors['amazon-region'] && 'error') || 'default' }> props.setUploadOptions(Object.assign(props.upload.options, { region: value })) } /> { props.upload.options.service === 's3' && @@ -84,6 +88,7 @@ const AmazonUploadComponent = (props) => { helperTextInvalid={ (props.errors['amazon-bucket'] && props.errors['amazon-bucket'].value) || '' } validated={ (props.errors['amazon-bucket'] && 'error') || 'default' }> props.setUploadOptions(Object.assign(props.upload.options, { bucket: value })) } /> } @@ -106,6 +111,7 @@ const UploadComponent = (props) => {
props.setUpload({ type: value, options: null }) } aria-label="Select upload destination"> { uploadTypes.map(type => ) } diff --git a/src/test/SmartComponents/CreateImageWizard/CreateImageWizard.test.js b/src/test/SmartComponents/CreateImageWizard/CreateImageWizard.test.js index 2acecac1..ddd85af4 100644 --- a/src/test/SmartComponents/CreateImageWizard/CreateImageWizard.test.js +++ b/src/test/SmartComponents/CreateImageWizard/CreateImageWizard.test.js @@ -2,6 +2,7 @@ import '@testing-library/jest-dom'; import React from 'react'; import { screen, getByText, waitFor, waitForElementToBeRemoved } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import { renderWithReduxRouter } from '../../testUtils'; import CreateImageWizard from '../../../SmartComponents/CreateImageWizard/CreateImageWizard'; @@ -77,6 +78,13 @@ describe('Step Release', () => { const [ , , cancel ] = verifyButtons(); verifyCancelButton(cancel); }); + + test('allows chosing a release', () => { + const release = screen.getByTestId('release-select'); + expect(release).toBeEnabled(); + + userEvent.selectOptions(release, [ 'rhel-8' ]); + }); }); describe('Step Target environment', () => { @@ -109,6 +117,66 @@ describe('Step Target environment', () => { const [ , , cancel ] = verifyButtons(); verifyCancelButton(cancel); }); + + test('choosing S3 shows region and bucket fields', () => { + // change the select to enable the bucket field + userEvent.selectOptions(screen.getByTestId('aws-service-select'), [ 's3' ]); + + const destination = screen.getByTestId('upload-destination'); + expect(destination).toBeEnabled(); + expect(destination).toBeRequired(); + + const accessKeyId = screen.getByTestId('aws-access-key'); + expect(accessKeyId).toHaveValue(''); + expect(accessKeyId).toBeEnabled(); + expect(accessKeyId).toBeRequired(); + + const secretAccessKey = screen.getByTestId('aws-secret-access-key'); + expect(secretAccessKey).toHaveValue(''); + expect(secretAccessKey).toBeEnabled(); + expect(secretAccessKey).toBeRequired(); + + const region = screen.getByTestId('aws-region'); + expect(region).toHaveValue('eu-west-2'); + expect(region).toBeEnabled(); + expect(region).toBeRequired(); + + const bucket = screen.getByTestId('aws-bucket'); + expect(bucket).toHaveValue(''); + expect(bucket).toBeEnabled(); + expect(bucket).toBeRequired(); + }); + + test('choosing EC2 shows region field', async () => { + // change the select to enable the bucket field + userEvent.selectOptions(screen.getByTestId('aws-service-select'), [ 's3' ]); + + const destination = screen.getByTestId('upload-destination'); + expect(destination).toBeEnabled(); + expect(destination).toBeRequired(); + + const accessKeyId = screen.getByTestId('aws-access-key'); + expect(accessKeyId).toHaveValue(''); + expect(accessKeyId).toBeEnabled(); + expect(accessKeyId).toBeRequired(); + + const secretAccessKey = screen.getByTestId('aws-secret-access-key'); + expect(secretAccessKey).toHaveValue(''); + expect(secretAccessKey).toBeEnabled(); + expect(secretAccessKey).toBeRequired(); + + const region = screen.getByTestId('aws-region'); + expect(region).toHaveValue('eu-west-2'); + expect(region).toBeEnabled(); + expect(region).toBeRequired(); + + // change the select to hide the bucket field + userEvent.selectOptions(screen.getByTestId('aws-service-select'), [ 'ec2' ]); + + waitForElementToBeRemoved(screen.queryByTestId('aws-bucket')).then(() => + expect(screen.queryByTestId('aws-bucket')).not.toBeInTheDocument() + ); + }); }); describe('Step Registration', () => { @@ -213,3 +281,41 @@ describe('Step Review', () => { verifyCancelButton(cancel); }); }); + +describe('Click through all steps', () => { + beforeEach(() => { + renderWithReduxRouter(); + }); + + test('with valid values', async () => { + const next = screen.getByRole('button', { name: /Next/ }); + + // select release + userEvent.selectOptions(screen.getByTestId('release-select'), [ 'rhel-8' ]); + next.click(); + + // select upload target + await screen.findByTestId('upload-destination'); + userEvent.selectOptions(screen.getByTestId('upload-destination'), [ 'aws' ]); + userEvent.type(screen.getByTestId('aws-access-key'), 'key'); + userEvent.type(screen.getByTestId('aws-secret-access-key'), 'secret'); + userEvent.selectOptions(screen.getByTestId('aws-service-select'), [ 's3' ]); + userEvent.type(screen.getByTestId('aws-region'), 'us-east-1'); + userEvent.type(screen.getByTestId('aws-bucket'), 'imagebuilder'); + next.click(); + + // registration + await screen.findByTestId('subscription-activation'); + screen + .getByLabelText('Embed an activation key and register systems on first boot') + .click(); + userEvent.type(screen.getByTestId('subscription-activation'), '1234567890'); + next.click(); + + await screen. + findByText('Review the information and click Create image to create the image using the following criteria.'); + await screen.findByText('rhel-8'); + await screen.findByText('aws'); + await screen.findByText('Register the system on first boot'); + }); +});