8000 Wait for the row in the Admin UI E2E clickTableRowItem helper by ahus1 · Pull Request #55085 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
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
60 changes: 8 additions & 52 deletions js/apps/admin-ui/test/utils/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,6 @@ function escapeRegex(value: string) {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}

async function clickLinkWhenAvailable(link: Locator): Promise<boolean> {
const candidate = link.first();
if ((await candidate.count()) === 0) {
return false;
}

try {
await candidate.waitFor({ state: "visible", timeout: 500 });
await candidate.click({ timeout: 500 });
return true;
} catch {
return false;
}
}

export async function clickTableRowItem(page: Page, itemName: string) {
const tableBody = page.locator("table tbody");
await tableBody
Expand All @@ -48,45 +33,16 @@ export async function clickTableRowItem(page: Page, itemName: string) {
.waitFor({ state: "visible", timeout: TABLE_LOAD_TIMEOUT_MS });

const exactNameRegex = new RegExp(`^${escapeRegex(itemName)}$`, "i");
const anyMatch = tableBody.getByRole("link", { name: itemName }).first();

for (let attempt = 0; attempt < 6; attempt++) {
if (
await clickLinkWhenAvailable(
tableBody.getByRole("link", { name: itemName, exact: true }),
)
) {
return;
}

if (
await clickLinkWhenAvailable(
tableBody.getByRole("link", { name: exactNameRegex }),
)
) {
return;
}

if (
await clickLinkWhenAvailable(
tableBody
.locator("tr")
.filter({ has: page.getByRole("link", { name: exactNameRegex }) })
.getByRole("link", { name: exactNameRegex }),
)
) {
return;
}
// The row may render after the search or page load completes, so wait for it instead of checking once.
await anyMatch.waitFor({ state: "visible", timeout: TABLE_LOAD_TIMEOUT_MS });

if (
await clickLinkWhenAvailable(
tableBody.getByRole("link", { name: itemName }),
)
) {
return;
}
}

throw new Error(`Table row item "${itemName}" not found`);
const exactMatch = tableBody
.getByRole("link", { name: exactNameRegex })
.first();
const target = (await exactMatch.count()) > 0 ? exactMatch : anyMatch;
await target.click();
}

export function getRowByCellText(page: Page, cellText: string): Locator {
Expand Down
Loading
0