test: Enable tests
This enables test for the Repositories step.
This commit is contained in:
parent
c2363e3046
commit
c9e124b8c1
2 changed files with 302 additions and 289 deletions
|
|
@ -1,12 +1,12 @@
|
|||
// 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 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 CreateImageWizard from '../../../Components/CreateImageWizardV2/CreateImageWizard';
|
||||
// import ShareImageModal from '../../../Components/ShareImageModal/ShareImageModal';
|
||||
// import {
|
||||
// mockPkgResultAlpha,
|
||||
|
|
@ -14,49 +14,51 @@
|
|||
// mockPkgResultAll,
|
||||
// mockPkgResultPartial,
|
||||
// } from '../../fixtures/packages';
|
||||
// import {
|
||||
// clickBack,
|
||||
// clickNext,
|
||||
// renderCustomRoutesWithReduxRouter,
|
||||
// renderWithReduxRouter,
|
||||
// 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 />,
|
||||
// },
|
||||
// ];
|
||||
//
|
||||
// let router = undefined;
|
||||
//
|
||||
// jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
|
||||
// useChrome: () => ({
|
||||
// auth: {
|
||||
// getUser: () => {
|
||||
// return {
|
||||
// identity: {
|
||||
// internal: {
|
||||
// org_id: 5,
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
// },
|
||||
// },
|
||||
// isBeta: () => false,
|
||||
// isProd: () => true,
|
||||
// getEnvironment: () => 'prod',
|
||||
// }),
|
||||
// }));
|
||||
import {
|
||||
clickBack,
|
||||
clickNext,
|
||||
renderCustomRoutesWithReduxRouter,
|
||||
// renderWithReduxRouter,
|
||||
// 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 />,
|
||||
// },
|
||||
];
|
||||
|
||||
// The router is just initiliazed here, it's assigned a value in the tests
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
let router = undefined;
|
||||
|
||||
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();
|
||||
|
|
@ -77,27 +79,27 @@
|
|||
// }
|
||||
// };
|
||||
//
|
||||
// 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;
|
||||
// });
|
||||
//
|
||||
let mockContentSourcesEnabled: boolean;
|
||||
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('without Content Sources', () => {
|
||||
// const user = userEvent.setup();
|
||||
|
|
@ -821,214 +823,225 @@
|
|||
// });
|
||||
// });
|
||||
//
|
||||
// describe('Step Custom repositories', () => {
|
||||
// const user = userEvent.setup();
|
||||
// const setUp = async () => {
|
||||
// ({ router } = 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);
|
||||
// expect(firstRepoCheckbox.checked).toEqual(true);
|
||||
//
|
||||
// await clickNext();
|
||||
// clickBack();
|
||||
//
|
||||
// firstRepoCheckbox = await getFirstRepoCheckbox();
|
||||
// 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 \(1015 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.findByRole('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);
|
||||
//
|
||||
// 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('Step Custom repositories', () => {
|
||||
const user = userEvent.setup();
|
||||
const setUp = async () => {
|
||||
({ router } = await 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.findByRole('textbox', {
|
||||
name: '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 OpenSCAP
|
||||
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()) as HTMLInputElement;
|
||||
|
||||
expect(firstRepoCheckbox.checked).toEqual(false);
|
||||
await user.click(firstRepoCheckbox);
|
||||
expect(firstRepoCheckbox.checked).toEqual(true);
|
||||
|
||||
await clickNext();
|
||||
await clickBack();
|
||||
|
||||
firstRepoCheckbox = (await getFirstRepoCheckbox()) as HTMLInputElement;
|
||||
await waitFor(() => expect(firstRepoCheckbox.checked).toEqual(true));
|
||||
}, 30000);
|
||||
|
||||
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 \(1015 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 getRows = async () => await within(table).findAllByRole('row');
|
||||
|
||||
let rows = await 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 = await getRows();
|
||||
// remove first row from list since it is just header labels
|
||||
rows.shift();
|
||||
|
||||
await waitFor(() => expect(rows).toHaveLength(10));
|
||||
}, 30000);
|
||||
|
||||
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()) as HTMLInputElement;
|
||||
|
||||
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();
|
||||
await clickBack();
|
||||
await waitFor(() => 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()) as HTMLInputElement;
|
||||
|
||||
const getSecondRepoCheckbox = async () =>
|
||||
await screen.findByRole('checkbox', {
|
||||
name: /select row 1/i,
|
||||
});
|
||||
const secondRepoCheckbox =
|
||||
(await getSecondRepoCheckbox()) as HTMLInputElement;
|
||||
|
||||
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();
|
||||
await clickBack();
|
||||
|
||||
expect(firstRepoCheckbox.checked).toEqual(true);
|
||||
await waitFor(() => 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()) as HTMLInputElement;
|
||||
|
||||
const getNextPageButton = async () =>
|
||||
await screen.findByRole('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);
|
||||
|
||||
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);
|
||||
await waitFor(() => expect(firstRepoCheckbox.checked).toEqual(false));
|
||||
}, 30000);
|
||||
});
|
||||
//
|
||||
// describe('On Recreate', () => {
|
||||
// const user = userEvent.setup();
|
||||
|
|
@ -1116,3 +1129,4 @@
|
|||
// expect(unavailableRepoCheckbox).toBeDisabled();
|
||||
// });
|
||||
// });
|
||||
//
|
||||
|
|
|
|||
|
|
@ -120,9 +120,9 @@ describe('Create Image Wizard', () => {
|
|||
await screen.findByRole('button', { name: 'Image output' });
|
||||
await screen.findByRole('button', { name: 'Register' });
|
||||
// await screen.findByRole('button', { name: 'File system configuration' });
|
||||
// await screen.findByRole('button', { name: 'Content' });
|
||||
await screen.findByRole('button', { name: 'Content' });
|
||||
// await screen.findByRole('button', { name: 'Additional Red Hat packages' });
|
||||
// await screen.findByRole('button', { name: 'Custom repositories' });
|
||||
await screen.findByRole('button', { name: 'Custom repositories' });
|
||||
await screen.findByRole('button', { name: 'Details' });
|
||||
// await screen.findByRole('button', { name: 'Review' });
|
||||
});
|
||||
|
|
@ -868,14 +868,13 @@ describe('Step Upload to AWS', () => {
|
|||
await clickNext();
|
||||
// skip oscap
|
||||
await clickNext();
|
||||
// skip repositories
|
||||
await clickNext();
|
||||
// // skip fsc
|
||||
// await clickNext();
|
||||
// // skip packages
|
||||
// await clickNext();
|
||||
};
|
||||
// // skip fsc
|
||||
// await clickNext();
|
||||
// // skip packages
|
||||
// await clickNext();
|
||||
// // skip repositories
|
||||
// await clickNext();
|
||||
// };
|
||||
|
||||
test('image name invalid for more than 63 chars', async () => {
|
||||
await setUp();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue