wizard/tests: add integration and unit tests

Add integration and unit tests for the wizard. The integration testing
is making sure that the wizard holds up together, is navigable and has
at least a happy path tested.
The unit test of the ImageOuput tests more combinations of clicks on the
interface and make sure the inner logic is sound.

The intersection of the two tests brings us confidence that the UX will
work according to spec.
This commit is contained in:
Thomas Lavocat 2023-11-08 09:34:30 +01:00 committed by Klara Simickova
parent 2173545f60
commit c7ffde49ae
2 changed files with 407 additions and 0 deletions

View file

@ -0,0 +1,145 @@
import React from 'react';
import '@testing-library/jest-dom';
import { screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import CreateImageWizard from '../../../Components/CreateImageWizardV2/CreateImageWizard';
import ShareImageModal from '../../../Components/ShareImageModal/ShareImageModal';
import { server } from '../../mocks/server.js';
import {
clickNext,
renderCustomRoutesWithReduxRouter,
verifyCancelButton,
} from '../../testUtils';
const routes = [
{
path: 'insights/image-builder/*',
element: <div />,
},
{
path: 'insights/image-builder/imagewizard/:composeId?',
element: <CreateImageWizard />,
},
{
path: 'insights/image-builder/share /:composeId',
element: <ShareImageModal />,
},
];
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
useChrome: () => ({
auth: {
getUser: () => {
return {
identity: {
internal: {
org_id: 5,
},
},
};
},
},
isBeta: () => true,
isProd: () => true,
getEnvironment: () => 'prod',
}),
}));
jest.mock('@unleash/proxy-client-react', () => ({
useUnleashContext: () => jest.fn(),
useFlag: jest.fn((flag) =>
flag === 'image-builder.enable-content-sources' ? true : false
),
}));
beforeAll(() => {
// scrollTo is not defined in jsdom
window.HTMLElement.prototype.scrollTo = function () {};
});
afterEach(() => {
jest.clearAllMocks();
server.resetHandlers();
});
describe('Create Image Wizard', () => {
test('renders component', () => {
renderCustomRoutesWithReduxRouter('imagewizard', {}, routes);
// check heading
screen.getByRole('heading', { name: /Image Builder/ });
screen.getByRole('button', { name: 'Image output' });
});
});
describe('Step Image output', () => {
test('clicking Next loads the review step with correct information about the image output', async () => {
const user = userEvent.setup();
await renderCustomRoutesWithReduxRouter('imagewizard', {}, routes);
// select aws as upload destination
await user.click(await screen.findByTestId('upload-aws'));
await screen.findByRole('heading', { name: 'Image output' });
await clickNext();
await screen.findByRole('heading', { name: 'Review' });
const view = screen.getByTestId('image-output-expandable');
await user.click(await within(view).findByText(/image output/i));
expect(await screen.findByText(/x86_64/i)).not.toBeNaN();
expect(
await screen.findByText(/red hat enterprise linux \(rhel\) 9/i)
).not.toBeNaN();
});
test('selecting rhel8 and aarch64 shows accordingly in the review step', async () => {
const user = userEvent.setup();
await renderCustomRoutesWithReduxRouter('imagewizard', {}, routes);
// select rhel8
const releaseMenu = screen.getAllByRole('button', {
name: 'Red Hat Enterprise Linux (RHEL) 9',
})[0];
await user.click(releaseMenu);
await user.click(
await screen.findByRole('option', {
name: 'Red Hat Enterprise Linux (RHEL) 8',
})
);
// Change to aarch
await user.selectOptions(
await screen.findByRole('combobox', {
name: /architecture/i,
}),
'aarch64'
);
// select aws as upload destination
await user.click(await screen.findByTestId('upload-aws'));
await clickNext();
await screen.findByRole('heading', { name: 'Review' });
const view = screen.getByTestId('image-output-expandable');
await user.click(await within(view).findByText(/image output/i));
expect(await screen.findByText(/aarch64/i)).not.toBeNaN();
expect(
await screen.findByText(/red hat enterprise linux \(rhel\) 8/i)
).not.toBeNaN();
});
test('clicking Cancel loads landing page', async () => {
const { router } = await renderCustomRoutesWithReduxRouter(
'imagewizard',
{},
routes
);
await clickNext();
await verifyCancelButton(router);
});
});