Wizard: Drop the WizardV1

This commit is contained in:
Ondrej Ezr 2024-06-12 15:04:19 +02:00 committed by Klara Simickova
parent 54d09d636e
commit 5fcc80d2db
75 changed files with 103 additions and 11588 deletions

View file

@ -1,258 +0,0 @@
import React from 'react';
import '@testing-library/jest-dom';
import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { rest } from 'msw';
import CreateImageWizard from '../../../Components/CreateImageWizard/CreateImageWizard';
import ShareImageModal from '../../../Components/ShareImageModal/ShareImageModal';
import { PROVISIONING_API } from '../../../constants';
import { server } from '../../mocks/server';
import {
clickBack,
clickNext,
getNextButton,
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: () => false,
isProd: () => true,
getEnvironment: () => 'prod',
}),
}));
let router = undefined;
beforeAll(() => {
// scrollTo is not defined in jsdom
window.HTMLElement.prototype.scrollTo = function () {};
});
afterEach(() => {
jest.clearAllMocks();
router = undefined;
server.resetHandlers();
});
const getSourceDropdown = async () => {
const sourceDropdown = await screen.findByRole('textbox', {
name: /select source/i,
});
// Wait for isSuccess === true, dropdown is disabled while isSuccess === false
await waitFor(() => expect(sourceDropdown).toBeEnabled());
return sourceDropdown;
};
describe('Step Upload to Azure', () => {
const user = userEvent.setup();
const setUp = async () => {
({ router } = await renderCustomRoutesWithReduxRouter(
'imagewizard',
{},
routes
));
// select Azure as upload destination
await user.click(await screen.findByTestId('upload-azure'));
await clickNext();
await screen.findByRole('heading', {
name: 'Target environment - Microsoft Azure',
});
};
test('clicking Next loads Registration', async () => {
await setUp();
await user.click(await screen.findByTestId('azure-radio-manual'));
// Randomly generated GUID
await user.type(
await screen.findByTestId('azure-tenant-id-manual'),
'b8f86d22-4371-46ce-95e7-65c415f3b1e2'
);
await user.type(
await screen.findByTestId('azure-subscription-id-manual'),
'60631143-a7dc-4d15-988b-ba83f3c99711'
);
await user.type(
await screen.findByTestId('azure-resource-group-manual'),
'testResourceGroup'
);
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-azure');
});
test('clicking Cancel loads landing page', async () => {
await setUp();
await verifyCancelButton(router);
});
test('azure step basics works', async () => {
await setUp();
const nextButton = await getNextButton();
expect(nextButton).toHaveClass('pf-m-disabled');
expect(await screen.findByTestId('azure-radio-source')).toBeChecked();
await user.click(await screen.findByTestId('azure-radio-manual'));
expect(await screen.findByTestId('azure-radio-manual')).toBeChecked();
expect(nextButton).toHaveClass('pf-m-disabled');
const tenantId = await screen.findByTestId('azure-tenant-id-manual');
expect(tenantId).toHaveValue('');
expect(tenantId).toBeEnabled();
await user.type(tenantId, 'c983c2cd-94d7-44e1-9c6e-9cfa3a40995f');
const subscription = await screen.findByTestId(
'azure-subscription-id-manual'
);
expect(subscription).toHaveValue('');
expect(subscription).toBeEnabled();
await user.type(subscription, 'f8f200aa-6234-4bfb-86c2-163d33dffc0c');
const resourceGroup = await screen.findByTestId(
'azure-resource-group-manual'
);
expect(resourceGroup).toHaveValue('');
expect(resourceGroup).toBeEnabled();
await user.type(resourceGroup, 'testGroup');
expect(nextButton).not.toHaveClass('pf-m-disabled');
await user.click(await screen.findByTestId('azure-radio-source'));
await waitFor(() => expect(nextButton).toHaveClass('pf-m-disabled'));
const sourceDropdown = await getSourceDropdown();
// manual values should be cleared out
expect(await screen.findByTestId('azure-tenant-id-source')).toHaveValue('');
expect(
await screen.findByTestId('azure-subscription-id-source')
).toHaveValue('');
await user.click(sourceDropdown);
await user.click(
await screen.findByRole('option', {
name: /azureSource1/i,
})
);
// wait for fetching the upload info
await waitFor(() =>
expect(screen.getByTestId('azure-tenant-id-source')).not.toHaveValue('')
);
await user.click(
await screen.findByRole('textbox', {
name: /select resource group/i,
})
);
const groups = screen.getAllByLabelText(/^Resource group/);
expect(groups).toHaveLength(2);
await user.click(
await screen.findByLabelText('Resource group myResourceGroup1')
);
expect(nextButton).not.toHaveClass('pf-m-disabled');
}, 10000);
test('handles change of selected Source', async () => {
await setUp();
const sourceDropdown = await getSourceDropdown();
await user.click(sourceDropdown);
await user.click(
await screen.findByRole('option', {
name: /azureSource1/i,
})
);
await waitFor(() =>
expect(screen.getByTestId('azure-tenant-id-source')).not.toHaveValue('')
);
await user.click(sourceDropdown);
await user.click(
await screen.findByRole('option', {
name: /azureSource2/i,
})
);
await waitFor(() => {
expect(screen.getByTestId('azure-tenant-id-source')).toHaveValue(
'73d5694c-7a28-417e-9fca-55840084f508'
);
});
await user.click(
await screen.findByRole('textbox', {
name: /select resource group/i,
})
);
const groups = await screen.findByLabelText(/^Resource group/);
expect(groups).toBeInTheDocument();
expect(
await screen.findByLabelText('Resource group theirGroup2')
).toBeVisible();
});
test('component renders error state correctly', async () => {
server.use(
rest.get(`${PROVISIONING_API}/sources`, (req, res, ctx) =>
res(ctx.status(500))
)
);
await setUp();
await screen.findByText(
/Sources cannot be reached, try again later or enter an account info for upload manually\./i
);
});
// set test timeout to 15 seconds
}, 15000);

View file

@ -1,211 +0,0 @@
import React from 'react';
import '@testing-library/jest-dom';
import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import CreateImageWizard from '../../../Components/CreateImageWizard/CreateImageWizard';
import ShareImageModal from '../../../Components/ShareImageModal/ShareImageModal';
import {
clickNext,
renderCustomRoutesWithReduxRouter,
renderWithReduxRouter,
} 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: () => false,
getEnvironment: () => 'stage',
}),
}));
jest.mock('@unleash/proxy-client-react', () => ({
useUnleashContext: () => jest.fn(),
useFlag: jest.fn((flag) =>
flag === 'image-builder.wizard.oscap.enabled' ? true : false
),
}));
beforeAll(() => {
// scrollTo is not defined in jsdom
window.HTMLElement.prototype.scrollTo = function () {};
});
afterEach(() => {
jest.clearAllMocks();
});
describe('Step Compliance', () => {
const user = userEvent.setup();
const setup = async () => {
renderCustomRoutesWithReduxRouter('imagewizard', {}, routes);
};
test('create an image with None oscap profile', async () => {
await setup();
// select aws as upload destination
await user.click(await screen.findByTestId('upload-aws'));
await clickNext();
// aws step
await user.click(
await screen.findByRole('radio', {
name: /manually enter an account id\./i,
})
);
await user.type(
await screen.findByTestId('aws-account-id'),
'012345678901'
);
await clickNext();
// skip registration
await user.click(await screen.findByLabelText('Register later'));
await clickNext();
// Now we should be in the Compliance step
await screen.findByRole('heading', { name: /OpenSCAP/i });
await user.click(
await screen.findByRole('textbox', { name: /select a profile/i })
);
await user.click(await screen.findByText(/none/i));
// check that the FSC does not contain a /tmp partition
await clickNext();
await screen.findByRole('heading', { name: /File system configuration/i });
expect(
screen.queryByRole('cell', {
name: /tmp/i,
})
).not.toBeInTheDocument();
// check that there are no Packages contained when selecting the "None" profile option
await clickNext();
await screen.findByRole('heading', {
name: /Additional Red Hat packages/i,
});
await screen.findByText(/no packages added/i);
});
test('create an image with an oscap profile', async () => {
await setup();
// select aws as upload destination
await user.click(await screen.findByTestId('upload-aws'));
await clickNext();
// aws step
await user.click(
await screen.findByRole('radio', {
name: /manually enter an account id\./i,
})
);
await user.type(
await screen.findByTestId('aws-account-id'),
'012345678901'
);
await clickNext();
// skip registration
await user.click(await screen.findByLabelText('Register later'));
await clickNext();
// Now we should be at the OpenSCAP step
await screen.findByRole('heading', { name: /OpenSCAP/i });
await user.click(
await screen.findByRole('textbox', {
name: /select a profile/i,
})
);
await user.click(
await screen.findByText(
/cis red hat enterprise linux 8 benchmark for level 1 - workstation/i
)
);
await screen.findByText(/kernel arguments:/i);
await screen.findByText(/audit_backlog_limit=8192 audit=1/i);
await screen.findByText(/disabled services:/i);
await screen.findByText(/nfs-server/i);
await screen.findByText(/enabled services:/i);
await screen.findByText(/crond/i);
// check that the FSC contains a /tmp partition
await clickNext();
await screen.findByRole('heading', { name: /File system configuration/i });
await screen.findByText(/tmp/i);
// check that the Packages contains correct packages
await clickNext();
await screen.findByRole('heading', {
name: /Additional Red Hat packages/i,
});
await screen.findByText(/aide/i);
await screen.findByText(/neovim/i);
});
});
describe('On Recreate', () => {
const setup = async () => {
renderWithReduxRouter('imagewizard/1679d95b-8f1d-4982-8c53-8c2afa4ab04c');
};
test('with oscap profile', async () => {
const user = userEvent.setup();
await setup();
await screen.findByRole('button', {
name: /review/i,
});
const createImageButton = await screen.findByRole('button', {
name: /create image/i,
});
await waitFor(() => expect(createImageButton).toBeEnabled());
// check that the FSC contains a /tmp partition
// There are two buttons with the same name but cannot easily select the DDF rendered sidenav.
// The sidenav will be the first node found out of all buttons.
const buttonsFSC = await screen.findAllByRole('button', {
name: /file system configuration/i,
});
await user.click(buttonsFSC[0]);
await screen.findByRole('heading', { name: /file system configuration/i });
await screen.findByText('/tmp');
// check that the Packages contain a nftable package
await clickNext();
await screen.findByRole('heading', {
name: /Additional Red Hat packages/i,
});
await screen.findByText('nftables');
});
});

View file

@ -1,676 +0,0 @@
import React from 'react';
import '@testing-library/jest-dom';
import { screen, waitFor, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import api from '../../../api.js';
import CreateImageWizard from '../../../Components/CreateImageWizard/CreateImageWizard';
import ShareImageModal from '../../../Components/ShareImageModal/ShareImageModal';
import { mockPkgResultAlphaContentSources } from '../../fixtures/packages';
import {
clickBack,
clickNext,
renderCustomRoutesWithReduxRouter,
renderWithReduxRouter,
} 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: () => false,
isProd: () => true,
getEnvironment: () => 'prod',
}),
}));
const searchForAvailablePackages = async (searchbox, searchTerm) => {
const user = userEvent.setup();
await user.type(searchbox, searchTerm);
await user.click(
await screen.findByRole('button', {
name: /search button for available packages/i,
})
);
};
const searchForChosenPackages = async (searchbox, searchTerm) => {
const user = userEvent.setup();
if (!searchTerm) {
await user.clear(searchbox);
} else {
await user.type(searchbox, searchTerm);
}
};
let mockContentSourcesEnabled;
jest.mock('@unleash/proxy-client-react', () => ({
useUnleashContext: () => jest.fn(),
useFlag: jest.fn((flag) =>
flag === 'image-builder.enable-content-sources'
? mockContentSourcesEnabled
: false
),
}));
beforeAll(() => {
// scrollTo is not defined in jsdom
window.HTMLElement.prototype.scrollTo = function () {};
mockContentSourcesEnabled = true;
});
afterEach(() => {
jest.clearAllMocks();
mockContentSourcesEnabled = true;
});
describe('Step Packages', () => {
describe('with Content Sources', () => {
const user = userEvent.setup();
const setUp = async () => {
renderCustomRoutesWithReduxRouter('imagewizard', {}, routes);
// select aws as upload destination
await waitFor(
async () => await user.click(await screen.findByTestId('upload-aws'))
);
await clickNext();
// aws step
await user.click(
await screen.findByRole('radio', {
name: /manually enter an account id\./i,
})
);
await user.type(
await screen.findByTestId('aws-account-id'),
'012345678901'
);
await clickNext();
// skip registration
await screen.findByRole('textbox', {
name: 'Select activation key',
});
const registerLaterRadio = await screen.findByTestId(
'registration-radio-later'
);
await user.click(registerLaterRadio);
await clickNext();
// skip fsc
await clickNext();
};
test('search results should be sorted with most relevant results first', async () => {
await setUp();
const view = await screen.findByTestId('search-available-pkgs-input');
const searchbox = await within(view).findByRole('textbox', {
name: /search input/i,
});
await waitFor(() => expect(searchbox).toBeEnabled());
await user.click(searchbox);
await searchForAvailablePackages(searchbox, 'test');
const availablePackagesList = await screen.findByTestId(
'available-pkgs-list'
);
const availablePackagesItems = await within(
availablePackagesList
).findAllByRole('option');
expect(availablePackagesItems).toHaveLength(3);
const [firstItem, secondItem, thirdItem] = availablePackagesItems;
expect(firstItem).toHaveTextContent('testsummary for test package');
expect(secondItem).toHaveTextContent('testPkgtest package summary');
expect(thirdItem).toHaveTextContent('lib-testlib-test package summary');
});
test('search results should be sorted after selecting them and then deselecting them', async () => {
await setUp();
const searchbox = screen.getAllByRole('textbox')[0]; // searching by id doesn't update the input ref
await waitFor(() => expect(searchbox).toBeEnabled());
await user.click(searchbox);
await searchForAvailablePackages(searchbox, 'test');
await user.click(await screen.findByTestId('available-pkgs-testPkg'));
await user.click(
await screen.findByRole('button', { name: /Add selected/ })
);
await user.click(await screen.findByTestId('selected-pkgs-testPkg'));
await user.click(
await screen.findByRole('button', { name: /Remove selected/ })
);
const availablePackagesList = await screen.findByTestId(
'available-pkgs-list'
);
const availablePackagesItems = within(availablePackagesList).getAllByRole(
'option'
);
expect(availablePackagesItems).toHaveLength(3);
const [firstItem, secondItem, thirdItem] = availablePackagesItems;
expect(firstItem).toHaveTextContent('testsummary for test package');
expect(secondItem).toHaveTextContent('testPkgtest package summary');
expect(thirdItem).toHaveTextContent('lib-testlib-test package summary');
});
test('search results should be sorted after adding and then removing all packages', async () => {
await setUp();
const searchbox = screen.getAllByRole('textbox')[0]; // searching by id doesn't update the input ref
await waitFor(() => expect(searchbox).toBeEnabled());
await user.click(searchbox);
await searchForAvailablePackages(searchbox, 'test');
await user.click(await screen.findByRole('button', { name: /Add all/ }));
await user.click(
await screen.findByRole('button', { name: /Remove all/ })
);
const availablePackagesList = await screen.findByTestId(
'available-pkgs-list'
);
const availablePackagesItems = await within(
availablePackagesList
).findAllByRole('option');
expect(availablePackagesItems).toHaveLength(3);
const [firstItem, secondItem, thirdItem] = availablePackagesItems;
expect(firstItem).toHaveTextContent('testsummary for test package');
// TODO
expect(thirdItem).toHaveTextContent('lib-testlib-test package summary');
expect(secondItem).toHaveTextContent('testPkgtest package summary');
});
test('removing a single package updates the state correctly', async () => {
await setUp();
const searchbox = screen.getAllByRole('textbox')[0]; // searching by id doesn't update the input ref
await waitFor(() => expect(searchbox).toBeEnabled());
await user.click(searchbox);
await searchForAvailablePackages(searchbox, 'test');
await user.click(await screen.findByRole('button', { name: /Add all/ }));
// remove a single package
await user.click(await screen.findByTestId('selected-pkgs-lib-test'));
await user.click(
await screen.findByRole('button', { name: /Remove selected/ })
);
// skip Custom repositories page
clickNext();
// skip name page
clickNext();
// review page
clickNext();
const chosen = await screen.findByTestId('chosen-packages-count');
expect(chosen).toHaveTextContent('2');
});
test('should display empty available state on failed search', async () => {
await setUp();
const searchbox = screen.getAllByRole('textbox')[0]; // searching by id doesn't update the input ref
await waitFor(() => expect(searchbox).toBeEnabled());
await user.click(searchbox);
await searchForAvailablePackages(searchbox, 'asdf');
await screen.findByText('No results found');
});
test('should display empty chosen state on failed search', async () => {
await setUp();
const searchboxAvailable = screen.getAllByRole('textbox')[0]; // searching by id doesn't update the input ref
const searchboxChosen = screen.getAllByRole('textbox')[1];
await waitFor(() => expect(searchboxAvailable).toBeEnabled());
await user.click(searchboxAvailable);
await searchForAvailablePackages(searchboxAvailable, 'test');
await user.click(await screen.findByRole('button', { name: /Add all/ }));
await user.click(searchboxChosen);
await user.type(searchboxChosen, 'asdf');
expect(await screen.findByText('No packages found')).toBeInTheDocument();
// We need to clear this input in order to not have sideeffects on other tests
await searchForChosenPackages(searchboxChosen, '');
});
test('search results should be sorted alphabetically', async () => {
await setUp();
const searchbox = screen.getAllByRole('textbox')[0]; // searching by id doesn't update the input ref
await waitFor(() => expect(searchbox).toBeEnabled());
await user.click(searchbox);
const getPackages = jest
.spyOn(api, 'getPackagesContentSources')
.mockImplementation(() =>
Promise.resolve(mockPkgResultAlphaContentSources)
);
await searchForAvailablePackages(searchbox, 'test');
await waitFor(() => expect(getPackages).toHaveBeenCalledTimes(1));
const availablePackagesList = await screen.findByTestId(
'available-pkgs-list'
);
const availablePackagesItems = within(availablePackagesList).getAllByRole(
'option'
);
expect(availablePackagesItems).toHaveLength(3);
const [firstItem, secondItem, thirdItem] = availablePackagesItems;
expect(firstItem).toHaveTextContent('testsummary for test package');
expect(secondItem).toHaveTextContent('lib-testlib-test package summary');
expect(thirdItem).toHaveTextContent('Z-testZ-test package summary');
});
test('available packages can be reset', async () => {
await setUp();
const searchbox = screen.getAllByRole('textbox')[0];
await waitFor(() => expect(searchbox).toBeEnabled());
await user.click(searchbox);
await searchForAvailablePackages(searchbox, 'test');
const availablePackagesList = await screen.findByTestId(
'available-pkgs-list'
);
const availablePackagesItems = await within(
availablePackagesList
).findAllByRole('option');
expect(availablePackagesItems).toHaveLength(3);
await user.click(
await screen.findByRole('button', {
name: /clear available packages search/i,
})
);
await screen.findByText(
'Search above to add additionalpackages to your image'
);
});
test('chosen packages can be reset after filtering', async () => {
await setUp();
const availableSearchbox = screen.getAllByRole('textbox')[0];
await waitFor(() => expect(availableSearchbox).toBeEnabled());
await user.click(availableSearchbox);
await searchForAvailablePackages(availableSearchbox, 'test');
const availablePackagesList = await screen.findByTestId(
'available-pkgs-list'
);
const availablePackagesItems = await within(
availablePackagesList
).findAllByRole('option');
expect(availablePackagesItems).toHaveLength(3);
await user.click(await screen.findByRole('button', { name: /Add all/ }));
const chosenPackagesList = await screen.findByTestId('chosen-pkgs-list');
let chosenPackagesItems = await within(chosenPackagesList).findAllByRole(
'option'
);
expect(chosenPackagesItems).toHaveLength(3);
const chosenSearchbox = screen.getAllByRole('textbox')[1];
await user.click(chosenSearchbox);
await searchForChosenPackages(chosenSearchbox, 'lib');
chosenPackagesItems = within(chosenPackagesList).getAllByRole('option');
expect(chosenPackagesItems).toHaveLength(1);
await user.click(
await screen.findByRole('button', {
name: /clear chosen packages search/i,
})
);
chosenPackagesItems = await within(chosenPackagesList).findAllByRole(
'option'
);
await waitFor(() => expect(chosenPackagesItems).toHaveLength(3));
});
});
});
describe('Step Custom repositories', () => {
const user = userEvent.setup();
const setUp = async () => {
renderCustomRoutesWithReduxRouter('imagewizard', {}, routes);
// select aws as upload destination
await user.click(await screen.findByTestId('upload-aws'));
await clickNext();
// aws step
await user.click(
await screen.findByRole('radio', {
name: /manually enter an account id\./i,
})
);
await user.type(
await screen.findByTestId('aws-account-id'),
'012345678901'
);
await clickNext();
// skip registration
await screen.findByRole('textbox', {
name: 'Select activation key',
});
await user.click(await screen.findByLabelText('Register later'));
await clickNext();
// skip fsc
await clickNext();
// skip packages
await clickNext();
};
test('selected repositories stored in and retrieved from form state', async () => {
await setUp();
const getFirstRepoCheckbox = async () =>
await screen.findByRole('checkbox', {
name: /select row 0/i,
});
let firstRepoCheckbox = await getFirstRepoCheckbox();
expect(firstRepoCheckbox.checked).toEqual(false);
await user.click(firstRepoCheckbox);
await waitFor(() => expect(firstRepoCheckbox.checked).toEqual(true));
await clickNext();
await clickBack();
firstRepoCheckbox = await getFirstRepoCheckbox();
await waitFor(() => expect(firstRepoCheckbox.checked).toEqual(true));
});
test('correct number of repositories is fetched', async () => {
await setUp();
await user.click(
await screen.findByRole('button', {
name: /^select$/i,
})
);
await screen.findByText(/select all \(1016 items\)/i);
});
test('filter works', async () => {
await setUp();
await user.type(
await screen.findByRole('textbox', { name: /search repositories/i }),
'2zmya'
);
const table = await screen.findByTestId('repositories-table');
const { getAllByRole } = within(table);
const getRows = () => getAllByRole('row');
let rows = getRows();
// remove first row from list since it is just header labels
rows.shift();
expect(rows).toHaveLength(1);
// clear filter
await user.click(await screen.findByRole('button', { name: /reset/i }));
rows = getRows();
// remove first row from list since it is just header labels
rows.shift();
await waitFor(() => expect(rows).toHaveLength(10));
});
test('press on Selected button to see selected repositories list', async () => {
await setUp();
const getFirstRepoCheckbox = async () =>
await screen.findByRole('checkbox', {
name: /select row 0/i,
});
const firstRepoCheckbox = await getFirstRepoCheckbox();
expect(firstRepoCheckbox.checked).toEqual(false);
await user.click(firstRepoCheckbox);
expect(firstRepoCheckbox.checked).toEqual(true);
const getSelectedButton = async () =>
await screen.findByRole('button', {
name: /selected repositories/i,
});
const selectedButton = await getSelectedButton();
await user.click(selectedButton);
expect(firstRepoCheckbox.checked).toEqual(true);
await clickNext();
clickBack();
expect(firstRepoCheckbox.checked).toEqual(true);
});
test('press on All button to see all repositories list', async () => {
await setUp();
const getFirstRepoCheckbox = async () =>
await screen.findByRole('checkbox', {
name: /select row 0/i,
});
const firstRepoCheckbox = await getFirstRepoCheckbox();
const getSecondRepoCheckbox = async () =>
await screen.findByRole('checkbox', {
name: /select row 1/i,
});
const secondRepoCheckbox = await getSecondRepoCheckbox();
expect(firstRepoCheckbox.checked).toEqual(false);
expect(secondRepoCheckbox.checked).toEqual(false);
await user.click(firstRepoCheckbox);
expect(firstRepoCheckbox.checked).toEqual(true);
expect(secondRepoCheckbox.checked).toEqual(false);
const getAllButton = async () =>
await screen.findByRole('button', {
name: /all repositories/i,
});
const allButton = await getAllButton();
await user.click(allButton);
expect(firstRepoCheckbox.checked).toEqual(true);
expect(secondRepoCheckbox.checked).toEqual(false);
await clickNext();
clickBack();
expect(firstRepoCheckbox.checked).toEqual(true);
expect(secondRepoCheckbox.checked).toEqual(false);
});
test('press on Selected button to see selected repositories list at the second page and filter checked repo', async () => {
await setUp();
const getFirstRepoCheckbox = async () =>
await screen.findByRole('checkbox', {
name: /select row 0/i,
});
const firstRepoCheckbox = await getFirstRepoCheckbox();
const getNextPageButton = async () =>
await screen.findAllByRole('button', {
name: /go to next page/i,
});
const nextPageButton = await getNextPageButton();
expect(firstRepoCheckbox.checked).toEqual(false);
await user.click(firstRepoCheckbox);
expect(firstRepoCheckbox.checked).toEqual(true);
await user.click(nextPageButton[0]);
const getSelectedButton = async () =>
await screen.findByRole('button', {
name: /selected repositories/i,
});
const selectedButton = await getSelectedButton();
await user.click(selectedButton);
expect(firstRepoCheckbox.checked).toEqual(true);
await user.type(
await screen.findByRole('textbox', { name: /search repositories/i }),
'13lk3'
);
expect(firstRepoCheckbox.checked).toEqual(true);
await clickNext();
clickBack();
expect(firstRepoCheckbox.checked).toEqual(true);
await user.click(firstRepoCheckbox);
expect(firstRepoCheckbox.checked).toEqual(false);
});
});
describe('On Recreate', () => {
const user = userEvent.setup();
const setUp = async () => {
renderWithReduxRouter('imagewizard/hyk93673-8dcc-4a61-ac30-e9f4940d8346');
};
const setUpUnavailableRepo = async () => {
renderWithReduxRouter('imagewizard/b7193673-8dcc-4a5f-ac30-e9f4940d8346');
};
test('with valid repositories', async () => {
await setUp();
await screen.findByRole('heading', { name: /review/i });
expect(
screen.queryByText('Previously added custom repository unavailable')
).not.toBeInTheDocument();
const createImageButton = await screen.findByRole('button', {
name: /create image/i,
});
await waitFor(() => expect(createImageButton).toBeEnabled());
await user.click(
await screen.findByRole('button', { name: /custom repositories/i })
);
await screen.findByRole('heading', { name: /custom repositories/i });
expect(
screen.queryByText('Previously added custom repository unavailable')
).not.toBeInTheDocument();
const table = await screen.findByTestId('repositories-table');
const { getAllByRole } = within(table);
const rows = getAllByRole('row');
const availableRepo = rows[1].cells[1];
expect(availableRepo).toHaveTextContent(
'13lk3http://yum.theforeman.org/releases/3.4/el8/x86_64/'
);
const availableRepoCheckbox = await screen.findByRole('checkbox', {
name: /select row 0/i,
});
await waitFor(() => expect(availableRepoCheckbox).toBeEnabled());
});
test('with repositories that are no longer available', async () => {
await setUpUnavailableRepo();
await screen.findByRole('heading', { name: /review/i });
await screen.findByText('Previously added custom repository unavailable');
const createImageButton = await screen.findByRole('button', {
name: /create image/i,
});
expect(createImageButton).toBeDisabled();
await user.click(
await screen.findByRole('button', { name: /custom repositories/i })
);
await screen.findByRole('heading', { name: /custom repositories/i });
await screen.findByText('Previously added custom repository unavailable');
const table = await screen.findByTestId('repositories-table');
const { getAllByRole } = within(table);
const rows = getAllByRole('row');
const unavailableRepo = rows[1].cells[1];
expect(unavailableRepo).toHaveTextContent(
'Repository with the following url is no longer available:http://unreachable.link.to.repo.org/x86_64/'
);
const unavailableRepoCheckbox = await screen.findByRole('checkbox', {
name: /select row 0/i,
});
expect(unavailableRepoCheckbox).toBeDisabled();
});
});

File diff suppressed because it is too large Load diff

View file

@ -1,260 +0,0 @@
import React from 'react';
import '@testing-library/jest-dom';
import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import CreateImageWizard from '../../../../Components/CreateImageWizard/CreateImageWizard';
import { AARCH64, RHEL_8, RHEL_9, X86_64 } from '../../../../constants';
import { mockArchitecturesByDistro } from '../../../fixtures/architectures';
import { server } from '../../../mocks/server';
import { renderCustomRoutesWithReduxRouter } from '../../../testUtils';
const routes = [
{
path: 'insights/image-builder/imagewizard/:composeId?',
element: <CreateImageWizard />,
},
];
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
useChrome: () => ({
auth: {
getUser: () => {
return {
identity: {
internal: {
org_id: 5,
},
},
};
},
},
isBeta: () => true,
isProd: () => true,
getEnvironment: () => 'prod',
}),
}));
beforeAll(() => {
// scrollTo is not defined in jsdom
window.HTMLElement.prototype.scrollTo = function () {};
});
afterEach(() => {
jest.clearAllMocks();
server.resetHandlers();
});
describe('Check that the target filtering is in accordance to mock content', () => {
test('rhel9 x86_64', async () => {
const user = userEvent.setup();
await renderCustomRoutesWithReduxRouter('imagewizard', {}, routes);
// select x86_64
const archMenu = screen.getAllByRole('button', {
name: /options menu/i,
})[1];
await user.click(archMenu);
await user.click(await screen.findByRole('option', { name: 'x86_64' }));
// make sure this test is in SYNC with the mocks
let images_types = [];
mockArchitecturesByDistro(RHEL_9).forEach((elem) => {
if (elem.arch === X86_64) {
images_types = elem.image_types;
}
});
expect(images_types).toContain('aws');
expect(images_types).toContain('gcp');
expect(images_types).toContain('azure');
expect(images_types).toContain('guest-image');
expect(images_types).toContain('image-installer');
expect(images_types).toContain('vsphere');
expect(images_types).toContain('vsphere-ova');
expect(images_types).not.toContain('wsl');
// make sure the UX conforms to the mocks
await waitFor(async () => await screen.findByTestId('upload-aws'));
await screen.findByTestId('upload-google');
await screen.findByTestId('upload-azure');
await screen.findByTestId('checkbox-guest-image');
await screen.findByTestId('checkbox-image-installer');
await screen.findByText(/vmware vsphere/i);
await screen.findByText(/open virtualization format \(\.ova\)/i);
expect(
screen.queryByText(/wsl - windows subsystem for linux \(\.tar\.gz\)/i)
).not.toBeInTheDocument();
});
test('rhel8 x86_64', async () => {
const user = userEvent.setup();
await renderCustomRoutesWithReduxRouter('imagewizard', {}, routes);
// select rhel8
const releaseMenu = screen.getAllByRole('button', {
name: /options menu/i,
})[0];
await user.click(releaseMenu);
await user.click(
await screen.findByRole('option', {
name: /Red Hat Enterprise Linux \(RHEL\) 8/,
})
);
// select x86_64
const archMenu = screen.getAllByRole('button', {
name: /options menu/i,
})[1];
await user.click(archMenu);
await user.click(await screen.findByRole('option', { name: 'x86_64' }));
// make sure this test is in SYNC with the mocks
let images_types = [];
mockArchitecturesByDistro(RHEL_8).forEach((elem) => {
if (elem.arch === X86_64) {
images_types = elem.image_types;
}
});
expect(images_types).toContain('aws');
expect(images_types).toContain('gcp');
expect(images_types).toContain('azure');
expect(images_types).toContain('guest-image');
expect(images_types).toContain('image-installer');
expect(images_types).toContain('vsphere');
expect(images_types).toContain('vsphere-ova');
expect(images_types).toContain('wsl');
// make sure the UX conforms to the mocks
await waitFor(async () => await screen.findByTestId('upload-aws'));
await screen.findByTestId('upload-google');
await screen.findByTestId('upload-azure');
await screen.findByTestId('checkbox-guest-image');
await screen.findByTestId('checkbox-image-installer');
await screen.findByText(/vmware vsphere/i);
await screen.findByText(/open virtualization format \(\.ova\)/i);
await screen.findByText(/wsl - windows subsystem for linux \(\.tar\.gz\)/i);
});
test('rhel9 aarch64', async () => {
const user = userEvent.setup();
await renderCustomRoutesWithReduxRouter('imagewizard', {}, routes);
// select aarch64
const archMenu = screen.getAllByRole('button', {
name: /options menu/i,
})[1];
await user.click(archMenu);
await user.click(await screen.findByRole('option', { name: 'aarch64' }));
// make sure this test is in SYNC with the mocks
let images_types = [];
mockArchitecturesByDistro(RHEL_9).forEach((elem) => {
if (elem.arch === AARCH64) {
images_types = elem.image_types;
}
});
expect(images_types).toContain('aws');
expect(images_types).not.toContain('gcp');
expect(images_types).not.toContain('azure');
expect(images_types).toContain('guest-image');
expect(images_types).toContain('image-installer');
expect(images_types).not.toContain('vsphere');
expect(images_types).not.toContain('vsphere-ova');
expect(images_types).not.toContain('wsl');
// make sure the UX conforms to the mocks
await waitFor(async () => await screen.findByTestId('upload-aws'));
expect(screen.queryByTestId('upload-google')).not.toBeInTheDocument();
expect(screen.queryByTestId('upload-azure')).not.toBeInTheDocument();
await screen.findByTestId('checkbox-guest-image');
await screen.findByTestId('checkbox-image-installer');
expect(screen.queryByText(/vmware vsphere/i)).not.toBeInTheDocument();
expect(
screen.queryByText(/open virtualization format \(\.ova\)/i)
).not.toBeInTheDocument();
expect(
screen.queryByText(/wsl - windows subsystem for linux \(\.tar\.gz\)/i)
).not.toBeInTheDocument();
});
test('rhel8 aarch64', async () => {
const user = userEvent.setup();
await renderCustomRoutesWithReduxRouter('imagewizard', {}, routes);
// select rhel8
const releaseMenu = screen.getAllByRole('button', {
name: /options menu/i,
})[0];
await user.click(releaseMenu);
await user.click(
await screen.findByRole('option', {
name: /Red Hat Enterprise Linux \(RHEL\) 8/,
})
);
// select x86_64
const archMenu = screen.getAllByRole('button', {
name: /options menu/i,
})[1];
await user.click(archMenu);
await user.click(await screen.findByRole('option', { name: 'aarch64' }));
// make sure this test is in SYNC with the mocks
let images_types = [];
mockArchitecturesByDistro(RHEL_8).forEach((elem) => {
if (elem.arch === AARCH64) {
images_types = elem.image_types;
}
});
expect(images_types).toContain('aws');
expect(images_types).not.toContain('gcp');
expect(images_types).not.toContain('azure');
expect(images_types).toContain('guest-image');
expect(images_types).toContain('image-installer');
expect(images_types).not.toContain('vsphere');
expect(images_types).not.toContain('vsphere-ova');
expect(images_types).not.toContain('wsl');
// make sure the UX conforms to the mocks
await waitFor(async () => await screen.findByTestId('upload-aws'));
expect(screen.queryByTestId('upload-google')).not.toBeInTheDocument();
expect(screen.queryByTestId('upload-azure')).not.toBeInTheDocument();
await screen.findByTestId('checkbox-guest-image');
await screen.findByTestId('checkbox-image-installer');
expect(screen.queryByText(/vmware vsphere/i)).not.toBeInTheDocument();
expect(
screen.queryByText(/open virtualization format \(\.ova\)/i)
).not.toBeInTheDocument();
expect(
screen.queryByText(/wsl - windows subsystem for linux \(\.tar\.gz\)/i)
).not.toBeInTheDocument();
});
});
describe('Check step consistency', () => {
test('going back and forth with selected options only keeps the one compatible', async () => {
const user = userEvent.setup();
await renderCustomRoutesWithReduxRouter('imagewizard', {}, routes);
// select x86_64
const archMenu = screen.getAllByRole('button', {
name: /options menu/i,
})[1];
await user.click(archMenu);
await user.click(await screen.findByRole('option', { name: 'x86_64' }));
await waitFor(async () => await screen.findByTestId('upload-aws'));
// select GCP, it's available for x86_64
await user.click(await screen.findByTestId('upload-google'));
const next = await screen.findByRole('button', { name: /Next/ });
await waitFor(() => expect(next).toBeEnabled());
// Change to aarch
await user.click(archMenu);
await user.click(await screen.findByRole('option', { name: 'aarch64' }));
await waitFor(async () => await screen.findByTestId('upload-aws'));
// GCP not being compatible with arch, the next button is disabled
await waitFor(() => expect(next).toBeDisabled());
// clicking on AWS the user can go next
await user.click(await screen.findByTestId('upload-aws'));
await waitFor(() => expect(next).toBeEnabled());
// and going back to x86_64 the user should keep the next button visible
await user.click(archMenu);
await user.click(await screen.findByRole('option', { name: 'x86_64' }));
await waitFor(() => expect(next).toBeEnabled());
});
});

View file

@ -1066,7 +1066,7 @@ describe('Step Review', () => {
test('has 3 buttons', async () => {
await setUp();
await screen.findByRole('button', { name: /Create/ });
await screen.findByRole('button', { name: /Create blueprint/ });
await screen.findByRole('button', { name: /Back/ });
await screen.findByRole('button', { name: /Cancel/ });
});

View file

@ -23,10 +23,6 @@ jest.mock('@unleash/proxy-client-react', () => ({
switch (flag) {
case 'edgeParity.image-list':
return false;
case 'image-builder.new-wizard.enabled':
return false;
case 'image-builder.new-wizard.stable':
return false;
default:
return true;
}
@ -60,8 +56,9 @@ describe('Images Table', () => {
expect(headerCells[2]).toHaveTextContent('Updated');
expect(headerCells[3]).toHaveTextContent('OS');
expect(headerCells[4]).toHaveTextContent('Target');
expect(headerCells[5]).toHaveTextContent('Status');
expect(headerCells[6]).toHaveTextContent('Instance');
expect(headerCells[5]).toHaveTextContent('Version');
expect(headerCells[6]).toHaveTextContent('Status');
expect(headerCells[7]).toHaveTextContent('Instance');
const imageNameValues = mockComposes.map((compose) =>
compose.image_name ? compose.image_name : compose.id
@ -79,34 +76,6 @@ describe('Images Table', () => {
// TODO Test remaining table content.
});
test('check recreate action', async () => {
const { router } = await renderWithReduxRouter('', {});
// get rows
const table = await screen.findByTestId('images-table');
const { findAllByRole } = within(table);
const rows = await findAllByRole('row');
const actionsButton = await within(rows[1]).findByRole('button', {
name: 'Kebab toggle',
});
expect(actionsButton).toBeEnabled();
await user.click(actionsButton);
const recreateButton = await screen.findByRole('menuitem', {
name: 'Recreate image',
});
await user.click(recreateButton);
await waitFor(() =>
expect(router.state.location.pathname).toBe(
'/insights/image-builder/imagewizard/1579d95b-8f1d-4982-8c53-8c2afa4ab04c'
)
);
});
test('check download compose request action', async () => {
await renderWithReduxRouter('', {});

View file

@ -20,8 +20,6 @@ jest.mock('@unleash/proxy-client-react', () => ({
switch (flag) {
case 'edgeParity.image-list':
return false;
case 'image-builder.new-wizard.stable':
return false;
default:
return true;
}
@ -33,7 +31,8 @@ describe('Landing Page', () => {
renderWithReduxRouter('', {});
// check heading
await screen.findByRole('heading', { name: /Images/i });
const heading = await screen.findByText('Images');
expect(heading).toHaveRole('heading');
});
test('renders EmptyState child component', async () => {
@ -44,9 +43,6 @@ describe('Landing Page', () => {
);
renderWithReduxRouter('', {});
// check action loads
await screen.findByTestId('create-image-action-empty-state');
// check table loads
await screen.findByTestId('empty-state');
});