test: Update tests

This commit is contained in:
regexowl 2025-05-01 16:35:50 +02:00 committed by Lucas Garfield
parent c851fa9b8a
commit 9d8d6d1d99
2 changed files with 55 additions and 34 deletions

View file

@ -100,17 +100,11 @@ const getRows = async () => {
const comparePackageSearchResults = async () => {
const availablePackages = await getRows();
await waitFor(() => expect(availablePackages).toHaveLength(5));
await waitFor(() => expect(availablePackages).toHaveLength(3));
expect(availablePackages[0]).toHaveTextContent('test');
expect(availablePackages[1]).toHaveTextContent('test-lib');
expect(availablePackages[2]).toHaveTextContent('testPkg');
expect(availablePackages[3]).toHaveTextContent('testModule');
expect(availablePackages[4]).toHaveTextContent('testModule');
// Ensure both modules have one row
await screen.findByText('1.22');
await screen.findByText('1.24');
};
const clickFirstPackageCheckbox = async () => {
@ -174,7 +168,7 @@ const addAllRecommendations = async () => {
const deselectRecommendation = async () => {
const user = userEvent.setup();
const row1Checkbox = await screen.findByRole('checkbox', {
name: /select row 1/i,
name: /select row 0/i,
});
await waitFor(async () => user.click(row1Checkbox));
};
@ -411,26 +405,6 @@ describe('Step Packages', () => {
await within(pkgTable).findByText('recommendedPackage1');
});
test('only one stream gets selected, other should be disabled', async () => {
const user = userEvent.setup();
await renderCreateMode();
await goToPackagesStep();
await selectCustomRepo();
await typeIntoSearchBox('test');
const firstAppStreamRow = await screen.findByRole('checkbox', {
name: /select row 3/i,
});
await waitFor(() => user.click(firstAppStreamRow));
const secondAppStreamRow = await screen.findByRole('checkbox', {
name: /select row 4/i,
});
expect(secondAppStreamRow).toBeDisabled();
expect(secondAppStreamRow).not.toBeChecked();
});
test('revisit step button on Review works', async () => {
await renderCreateMode();
await goToPackagesStep();
@ -455,9 +429,9 @@ describe('Step Packages', () => {
// the pagination in the top right
const top = await screen.findByTestId('packages-pagination-top');
expect(top).toHaveTextContent('of 5');
expect(top).toHaveTextContent('of 3');
const bottom = await screen.findByTestId('packages-pagination-bottom');
expect(bottom).toHaveTextContent('of 5');
expect(bottom).toHaveTextContent('of 3');
});
test('itemcount correct after toggling selected', async () => {
@ -511,6 +485,47 @@ describe('Step Packages', () => {
await waitFor(() => expect(secondRowCells[0]).toHaveTextContent('fish2'));
});
});
describe('Modules', () => {
beforeEach(() => {
vi.clearAllMocks();
});
test('modules get rendered with one stream on each line', async () => {
await renderCreateMode();
await goToPackagesStep();
await selectCustomRepo();
await typeIntoSearchBox('testModule');
await screen.findByText('1.22');
const rows = await screen.findAllByRole('row');
rows.shift();
expect(rows).toHaveLength(2);
expect(rows[0]).toHaveTextContent('1.22');
expect(rows[1]).toHaveTextContent('1.24');
expect(rows[0]).toHaveTextContent('May 2025');
expect(rows[1]).toHaveTextContent('May 2027');
});
test('only one stream gets selected, other should be disabled', async () => {
const user = userEvent.setup();
await renderCreateMode();
await goToPackagesStep();
await selectCustomRepo();
await typeIntoSearchBox('testModule');
const firstAppStreamRow = await screen.findByRole('checkbox', {
name: /select row 0/i,
});
await waitFor(() => user.click(firstAppStreamRow));
const secondAppStreamRow = await screen.findByRole('checkbox', {
name: /select row 1/i,
});
expect(secondAppStreamRow).toBeDisabled();
expect(secondAppStreamRow).not.toBeChecked();
});
});
});
describe('Packages request generated correctly', () => {
@ -557,9 +572,9 @@ describe('Packages request generated correctly', () => {
test('with module', async () => {
await renderCreateMode();
await goToPackagesStep();
await typeIntoSearchBox('test'); // search for 'test' package
await typeIntoSearchBox('testModule'); // search for 'test' package
const moduleCheckbox = await screen.findByRole('checkbox', {
name: /select row 3/i,
name: /select row 0/i,
});
await waitFor(() => user.click(moduleCheckbox));
await goToReviewStep();
@ -579,9 +594,9 @@ describe('Packages request generated correctly', () => {
test('deselecting a module removes it from the request', async () => {
await renderCreateMode();
await goToPackagesStep();
await typeIntoSearchBox('test'); // search for 'test' package
await typeIntoSearchBox('testModule'); // search for 'test' package
const moduleCheckbox = await screen.findByRole('checkbox', {
name: /select row 3/i,
name: /select row 0/i,
});
await waitFor(() => user.click(moduleCheckbox)); // select
await toggleSelected();