test: Cover the Create button with all valid values

This commit is contained in:
Aleksandar Todorov 2020-11-19 13:49:23 +02:00 committed by Sanne Raymaekers
parent 530988f1da
commit 0895a122f5

View file

@ -5,6 +5,7 @@ import { screen, getByText, waitFor, waitForElementToBeRemoved } from '@testing-
import userEvent from '@testing-library/user-event';
import { renderWithReduxRouter } from '../../testUtils';
import CreateImageWizard from '../../../SmartComponents/CreateImageWizard/CreateImageWizard';
import api from '../../../api.js';
function verifyButtons() {
// these buttons exist everywhere
@ -288,8 +289,6 @@ describe('Step Review', () => {
screen.getByRole('button', { name: /Cancel/ });
});
// todo: add test for the Create button
test('clicking Back loads Register', () => {
const back = screen.getByRole('button', { name: /Back/ });
back.click();
@ -338,6 +337,25 @@ describe('Click through all steps', () => {
await screen.findByText('rhel-8');
await screen.findByText('aws');
await screen.findByText('Register the system on first boot');
// mock the backend API
const composeImage = jest.spyOn(api, 'composeImage');
composeImage.mockImplementation(async () => ({ id: 'test-me' }));
const create = screen.getByRole('button', { name: /Create/ });
create.click();
// API request sent to backend
expect(composeImage).toHaveBeenCalled();
// todo: assertion fails, can't find the button and we don't know why !
// returns back to the landing page
// await waitFor(
// () => [
// screen.getByText('Create a new image'),
// screen.getByRole('button', { name: /Create image/ }),
// ]
// );
});
test('with missing values', async () => {