Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ms2: removed flaky e2e test #426

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 0 additions & 112 deletions tests/ms2/processes/process-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,118 +476,6 @@ test('create a new folder and process, move process to folder and then delete bo
await expect(folderRow).not.toBeVisible();
});

test('sorting process list columns', async ({ processListPage }) => {
// NOTE: screen height is very important for this test, as with a small height
// and too many elements, the elements will use multiple pages

const names = ['a', 'b', 'c'];
const { page } = processListPage;

for (const folderName of names)
await processListPage.createFolder({ folderName: '0' + folderName }); // 0 prefix so that folders come first

const processIds: string[] = [];
for (const processName of names) {
// 1 prefix so that folders come first
processIds.push(await processListPage.createProcess({ processName: '1' + processName }));
await processListPage.goto();
}

// make hidden columns visible
await page
.getByRole('columnheader', { name: 'more' })
.getByRole('button', { name: 'more' })
.click();

for (const column of ['Created On', 'File Size', 'Owner']) {
const checkbox = page.getByRole('checkbox', { name: column });

expect(checkbox).toBeVisible();
if (!(await checkbox.isChecked())) await checkbox.click();
await expect(page.getByRole('columnheader', { name: column })).toBeVisible();
}

async function getColumnValues(col: number) {
const tableRows = await page.locator('tbody>tr:not(.ant-table-measure-row)').all();
const rowNames: { text: string; ariaLabel: string }[] = [];
for (const row of tableRows) {
const icon = row.locator('td').nth(2).locator('span').first();

const ariaLabel = await icon.evaluate((el) => el.getAttribute('aria-label'));

const text = await row.locator('td').nth(col).textContent();
rowNames.push({
text,
ariaLabel,
});
}
return rowNames;
}

function isSorted<T>(values: T[], aShouldBeBeforeB: (a: T, b: T) => boolean) {
for (let i = 0; i < values.length - 1; i++) {
if (!aShouldBeBeforeB(values[i], values[i + 1])) return false;
}
return true;
}

// // NOTE: the generateDateString uses the en-UK locale, if this changes this could break
// function parseLocaleDateString(str: string) {
// // format: day/month/year, hours:minutes
// const parts = str.split(/\/|:|,/);
// const day = parseInt(parts[0], 10);
// const month = parseInt(parts[1], 10) - 1; // Months are 0-indexed
// const year = parseInt(parts[2], 10);
// const hours = parseInt(parts[3], 10);
// const minutes = parseInt(parts[4], 10);
// return new Date(year, month, day, hours, minutes);
// }

function textSort(a: any, b: any, descending: boolean) {
if (a.ariaLabel === 'folder' && b.ariaLabel !== 'folder') return true;
if (b.ariaLabel === 'folder' && a.ariaLabel !== 'folder') return false;
if (descending) return a.text.localeCompare(b.text) <= 0;
return a.text.localeCompare(b.text) >= 0;
}

// function dateSort(a: any, b: any, descending: boolean) {
// if (a.ariaLabel === 'folder' && b.ariaLabel !== 'folder') return true;
// if (b.ariaLabel === 'folder' && a.ariaLabel !== 'folder') return false;
//
// const aDate = parseLocaleDateString(a.text);
// const bDate = parseLocaleDateString(b.text);
//
// if (descending) return aDate >= bDate;
// return aDate <= bDate;
// }

const sortableColumns = [
{ columnName: 'Name', sortFunction: textSort, offset: 2 },
/* TODO: */
// { columnName: 'Last Edited', sortFunction: dateSort, offset: 4 },
// { columnName: 'Created On', sortFunction: dateSort, offset: 5 },
// { columnName: 'File Size', sortFunction: textSort, offset: 6 },
{ columnName: 'Owner', sortFunction: textSort, offset: 7 },
];

for (const column of sortableColumns) {
const columnHeader = page
.getByRole('columnheader', { name: column.columnName })
.locator('div')
.first();

// First click sets it to descending order
await columnHeader.click();
const descendingValues = await getColumnValues(column.offset);
expect(isSorted(descendingValues, (a, b) => column.sortFunction(a, b, true))).toBeTruthy();

// Second click sets it to ascending order
await columnHeader.click();
const ascendingValues = await getColumnValues(column.offset);
expect(isSorted(ascendingValues, (a, b) => column.sortFunction(a, b, false))).toBeTruthy();
}
});

test.describe('shortcuts in process-list', () => {
/* Create Process - ctrl / meta + enter */
test('create and submit a new process with shortcuts', async ({ processListPage }) => {
Expand Down