test: move relevant test from createImageWizard to targetEnvironment test file

this commit move relvant test from creatreImageWizrad to targetEnvironment test file
This commit is contained in:
Michal Gold 2024-08-11 16:26:40 +03:00 committed by Klara Simickova
parent 4795fd5ea1
commit c4bbd413b3
4 changed files with 496 additions and 429 deletions

View file

@ -3,23 +3,16 @@ import React from 'react';
import type { Router as RemixRouter } from '@remix-run/router';
import { screen, waitFor, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import {
enterBlueprintName,
openAndDismissSaveAndBuildModal,
} from './wizardTestUtils';
import {
clickBack,
clickNext,
getNextButton,
verifyCancelButton,
enterBlueprintName,
} from './wizardTestUtils';
import CreateImageWizard from '../../../Components/CreateImageWizard/CreateImageWizard';
import ShareImageModal from '../../../Components/ShareImageModal/ShareImageModal';
import { PROVISIONING_API } from '../../../constants';
import { server } from '../../mocks/server';
import { renderCustomRoutesWithReduxRouter } from '../../testUtils';
const routes = [
@ -79,419 +72,6 @@ describe('Create Image Wizard', () => {
});
});
describe('Step Image output', () => {
beforeEach(() => {
vi.clearAllMocks();
router = undefined;
});
const user = userEvent.setup();
const setUp = async () => {
({ router } = await renderCustomRoutesWithReduxRouter(
'imagewizard',
{},
routes
));
// select aws as upload destination
const uploadAws = await screen.findByTestId('upload-aws');
user.click(uploadAws);
await screen.findByRole('heading', { name: 'Image output' });
};
test('clicking Next loads Upload to AWS', async () => {
await setUp();
await clickNext();
await switchToAWSManual();
await screen.findByText('AWS account ID');
});
test('clicking Cancel loads landing page', async () => {
await setUp();
await clickNext();
await verifyCancelButton(router);
});
test('target environment is required', async () => {
await setUp();
const destination = await screen.findByTestId('target-select');
const required = await within(destination).findByText('*');
expect(destination).toBeEnabled();
expect(destination).toContainElement(required);
});
test('selecting and deselecting a tile disables the next button', async () => {
await setUp();
const nextButton = await getNextButton();
const awsTile = await screen.findByTestId('upload-aws');
// this has already been clicked once in the setup function
user.click(awsTile); // deselect
const googleTile = await screen.findByTestId('upload-google');
user.click(googleTile); // select
user.click(googleTile); // deselect
const azureTile = await screen.findByTestId('upload-azure');
user.click(azureTile); // select
user.click(azureTile); // deselect
await waitFor(() => expect(nextButton).toBeDisabled());
});
test('expect only RHEL releases before expansion', async () => {
await setUp();
const releaseMenu = screen.getAllByRole('button', {
name: /options menu/i,
})[0];
user.click(releaseMenu);
await screen.findByRole('option', {
name: /Red Hat Enterprise Linux \(RHEL\) 8/,
});
await screen.findByRole('option', {
name: /Red Hat Enterprise Linux \(RHEL\) 9/,
});
await screen.findByRole('button', {
name: 'Show options for further development of RHEL',
});
user.click(releaseMenu);
});
test('expect all releases after expansion', async () => {
await setUp();
const releaseMenu = screen.getAllByRole('button', {
name: /options menu/i,
})[0];
user.click(releaseMenu);
const showOptionsButton = await screen.findByRole('button', {
name: 'Show options for further development of RHEL',
});
user.click(showOptionsButton);
await screen.findByRole('option', {
name: /Red Hat Enterprise Linux \(RHEL\) 8/,
});
await screen.findByRole('option', {
name: /Red Hat Enterprise Linux \(RHEL\) 9/,
});
await screen.findByRole('option', {
name: 'CentOS Stream 9',
});
expect(showOptionsButton).not.toBeInTheDocument();
user.click(releaseMenu);
});
test('release lifecycle chart appears only when RHEL 8 is chosen', async () => {
await setUp();
const releaseMenu = await screen.findAllByRole('button', {
name: /options menu/i,
});
user.click(releaseMenu[0]);
const rhel8Option = await screen.findByRole('option', {
name: /Red Hat Enterprise Linux \(RHEL\) 8/,
});
user.click(rhel8Option);
await screen.findByTestId('release-lifecycle-chart');
user.click(releaseMenu[0]);
const rhel9Option = await screen.findByRole('option', {
name: /Red Hat Enterprise Linux \(RHEL\) 9/,
});
user.click(rhel9Option);
await waitFor(() =>
expect(
screen.queryByTestId('release-lifecycle-chart')
).not.toBeInTheDocument()
);
});
test('CentOS acknowledgement appears', async () => {
await setUp();
const releaseMenu = screen.getAllByRole('button', {
name: /options menu/i,
})[0];
user.click(releaseMenu);
const showOptionsButton = await screen.findByRole('button', {
name: 'Show options for further development of RHEL',
});
user.click(showOptionsButton);
const centOSButton = await screen.findByRole('option', {
name: 'CentOS Stream 9',
});
user.click(centOSButton);
await screen.findByText(
'CentOS Stream builds are intended for the development of future versions of RHEL and are not supported for production workloads or other use cases.'
);
});
});
describe('Step Upload to AWS', () => {
beforeEach(() => {
vi.clearAllMocks();
router = undefined;
});
const user = userEvent.setup();
const setUp = async () => {
({ router } = await renderCustomRoutesWithReduxRouter(
'imagewizard',
{},
routes
));
// select aws as upload destination
const uploadAws = await screen.findByTestId('upload-aws');
user.click(uploadAws);
await clickNext();
await screen.findByRole('heading', {
name: 'Target environment - Amazon Web Services',
});
};
test('clicking Next loads Registration', async () => {
await setUp();
await switchToAWSManual();
const awsAccountId = await screen.findByRole('textbox', {
name: 'aws account id',
});
await waitFor(async () => user.type(awsAccountId, '012345678901'));
await clickNext();
await screen.findByRole('textbox', {
name: 'Select activation key',
});
await screen.findByText(
'Automatically register and enable advanced capabilities'
);
});
test('clicking Back loads Release', async () => {
await setUp();
await clickBack();
await screen.findByTestId('upload-aws');
});
test('clicking Cancel loads landing page', async () => {
await setUp();
await verifyCancelButton(router);
});
test('component renders error state correctly', async () => {
server.use(
http.get(`${PROVISIONING_API}/sources`, () => {
return new HttpResponse(null, { status: 500 });
})
);
await setUp();
await screen.findByText(
/sources cannot be reached, try again later or enter an aws account id manually\./i
);
});
test('validation works', async () => {
await setUp();
const nextButton = await getNextButton();
expect(nextButton).toHaveClass('pf-m-disabled');
const manualOption = await screen.findByRole('radio', {
name: /manually enter an account id\./i,
});
await waitFor(async () => user.click(manualOption));
expect(nextButton).toHaveClass('pf-m-disabled');
const awsAccId = await screen.findByRole('textbox', {
name: 'aws account id',
});
expect(awsAccId).toHaveValue('');
expect(awsAccId).toBeEnabled();
await waitFor(() => user.type(awsAccId, '012345678901'));
expect(nextButton).not.toHaveClass('pf-m-disabled');
const sourceRadio = await screen.findByRole('radio', {
name: /use an account configured from sources\./i,
});
user.click(sourceRadio);
await waitFor(() => expect(nextButton).toHaveClass('pf-m-disabled'));
const sourceDropdown = await getSourceDropdown();
user.click(sourceDropdown);
const source = await screen.findByRole('option', {
name: /my_source/i,
});
user.click(source);
await waitFor(() => expect(nextButton).not.toHaveClass('pf-m-disabled'));
});
test('compose request share_with_sources field is correct', async () => {
await setUp();
const sourceDropdown = await getSourceDropdown();
user.click(sourceDropdown);
const source = await screen.findByRole('option', {
name: /my_source/i,
});
user.click(source);
await clickNext();
// registration
await screen.findByRole('textbox', {
name: 'Select activation key',
});
const registerLaterRadio = await screen.findByLabelText('Register later');
user.click(registerLaterRadio);
// click through to review step
await clickNext();
await clickNext();
await clickNext();
await clickNext();
await clickNext();
await clickNext();
await clickNext();
await enterBlueprintName();
await clickNext();
// informational modal pops up in the first test only as it's tied
// to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage
await openAndDismissSaveAndBuildModal();
const createBlueprintBtn = await screen.findByRole('button', {
name: /Create blueprint/,
});
user.click(createBlueprintBtn);
// returns back to the landing page
await waitFor(() =>
expect(router?.state.location.pathname).toBe('/insights/image-builder')
);
// set test timeout of 10 seconds
}, 10000);
});
describe('Step Upload to Google', () => {
beforeEach(() => {
vi.clearAllMocks();
router = undefined;
});
const user = userEvent.setup();
const setUp = async () => {
({ router } = await renderCustomRoutesWithReduxRouter(
'imagewizard',
{},
routes
));
// select gcp as upload destination
const uploadGcp = await screen.findByTestId('upload-google');
user.click(uploadGcp);
await clickNext();
await screen.findByRole('heading', {
name: 'Target environment - Google Cloud Platform',
});
};
test('clicking Next loads Registration', async () => {
await setUp();
const shareRadioButton = await screen.findByText(
/share image with a google account/i
);
user.click(shareRadioButton);
const googleEmailInput = await screen.findByTestId('principal');
await waitFor(() => user.type(googleEmailInput, 'test@test.com'));
await clickNext();
await screen.findByRole('textbox', {
name: 'Select activation key',
});
await screen.findByText(
'Automatically register and enable advanced capabilities'
);
});
test('clicking Back loads Release', async () => {
await setUp();
await clickBack();
await screen.findByTestId('upload-google');
});
test('clicking Cancel loads landing page', async () => {
await setUp();
await verifyCancelButton(router);
});
test('the google account id field is shown and required', async () => {
await setUp();
const principalInput = await screen.findByTestId('principal');
expect(principalInput).toHaveValue('');
expect(principalInput).toBeEnabled();
});
test('the google email field must be a valid email', async () => {
await setUp();
await waitFor(async () =>
user.type(await screen.findByTestId('principal'), 'a')
);
expect(await getNextButton()).toHaveClass('pf-m-disabled');
expect(await getNextButton()).toBeDisabled();
await waitFor(async () =>
user.type(await screen.findByTestId('principal'), 'test@test.com')
);
expect(await getNextButton()).not.toHaveClass('pf-m-disabled');
expect(await getNextButton()).toBeEnabled();
});
});
//describe('Step Details', () => {
// beforeEach(() => {
// vi.clearAllMocks();