Skip to content

Commit 264b3ee

Browse files
committed
fix: cleanup for backpage tests, still fails on webkit (#4080)
1 parent 1cc23bd commit 264b3ee

File tree

3 files changed

+106
-41
lines changed

3 files changed

+106
-41
lines changed

explorer/e2e/anvil/anvil-tabs.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ export const anvilTabs: AnvilCMGTabCollection = {
7070
url: "/biosamples",
7171
},
7272
datasets: {
73+
backpageExportButtons: {
74+
accessNotGrantedMessage:
75+
"To export this dataset, please sign in and, if necessary, request access.",
76+
detailsName: "Dataset Details",
77+
exportTabName: "Export",
78+
exportUrl: /\.*\/export-to-terra/,
79+
firstButtonName: "Request Link",
80+
firstLoadingMessage: "Your link will be ready shortly...",
81+
newTabMessage:
82+
"If you are a new user or returning user, click sign in to continue.",
83+
secondButtonName: "Open Terra",
84+
secondLandingMessage: "Your Terra Workspace Link is Ready",
85+
},
7386
backpageHeaders: [
7487
{
7588
name: "Dataset ID",

explorer/e2e/testFunctions.ts

Lines changed: 80 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ const getRowLocatorByAccess = (page: Page, access: string): Locator =>
438438
.filter({ has: page.getByRole("cell", { name: access }) })
439439
.first()
440440
.getByRole("cell")
441-
.first();
441+
.first()
442+
.getByRole("link");
442443

443444
// Backpages tests
444445
export async function testExportBackpage(
@@ -448,51 +449,73 @@ export async function testExportBackpage(
448449
): Promise<void> {
449450
// Goto the specified tab
450451
await page.goto(tab.url);
451-
await expect(getFirstElementTextLocator(page, 1)).toBeVisible();
452452
// Expect to find row with a granted status indicator
453-
const granted_row_locator = getRowLocatorByAccess(page, "Granted");
454-
await expect(granted_row_locator).toBeVisible();
453+
const grantedRowLocator = getRowLocatorByAccess(page, "Granted");
454+
await expect(grantedRowLocator).toBeVisible();
455455
// Click into the selected row
456-
await granted_row_locator.click();
456+
await grantedRowLocator.dispatchEvent("click"); //TODO: this is sometimes unreliable and changes the url without changing the tab.
457+
await expect(
458+
page.getByText(tab.backpageExportButtons?.detailsName ?? "")
459+
).toBeVisible();
457460
// Click the "Export" tab
458-
await page.getByText("Export", { exact: true }).click();
459-
await expect(page).toHaveURL(/\.*\/export-to-terra/);
461+
await page
462+
.getByText(tab.backpageExportButtons?.exportTabName ?? "ERROR", {
463+
exact: true,
464+
})
465+
.click();
466+
await expect(page).toHaveURL(tab.backpageExportButtons?.exportUrl ?? "");
460467
await expect(page.getByRole("checkbox").first()).toBeVisible();
461-
const requestLinkButtonLocator = page.getByRole("button", {
468+
const firstButtonLocator = page.getByRole("button", {
462469
name: "Request Link",
463470
});
464-
await expect(requestLinkButtonLocator).toBeEnabled();
465-
// Select all checkboxes on the page
471+
await expect(firstButtonLocator).toBeEnabled();
472+
// Select all checkboxes on the pages
466473
const checkboxes = await page.getByRole("checkbox").all();
467474
console.log(checkboxes);
468-
for (const checkbox of checkboxes) {
469-
console.log(checkbox);
470-
if (!(await checkbox.isChecked())) {
471-
await checkbox.click();
472-
await expect(checkbox).toBeChecked();
473-
await expect(checkbox).toBeEnabled({ timeout: 10000 });
475+
for (const checkboxLocator of checkboxes) {
476+
console.log(checkboxLocator);
477+
if (!(await checkboxLocator.isChecked())) {
478+
await checkboxLocator.click();
479+
await expect(checkboxLocator).toBeChecked();
480+
await expect(checkboxLocator).toBeEnabled({ timeout: 10000 });
481+
}
482+
}
483+
await expect(firstButtonLocator).toBeEnabled({ timeout: 10000 });
484+
// Uncheck all checkboxes except one in each table, to reduce overhead
485+
for (const tableLocator of await page.getByRole("table").all()) {
486+
const checkboxLocatorsInTable = await tableLocator
487+
.getByRole("checkbox")
488+
.all();
489+
for (const checkboxLocator of checkboxLocatorsInTable.slice(2)) {
490+
await checkboxLocator.click();
491+
await expect(checkboxLocator).not.toBeChecked();
492+
await expect(checkboxLocator).toBeEnabled({ timeout: 10000 });
474493
}
475494
}
476495
// Click the "Request Link" button
477-
await expect(requestLinkButtonLocator).toBeEnabled({ timeout: 10000 });
478-
await requestLinkButtonLocator.click();
496+
await expect(firstButtonLocator).toBeEnabled({ timeout: 10000 });
497+
await firstButtonLocator.click();
479498
await expect(
480-
page.getByText("Your link will be ready shortly...", { exact: true })
499+
page.getByText(tab.backpageExportButtons?.firstLoadingMessage ?? "ERROR", {
500+
exact: true,
501+
})
481502
).toBeVisible();
482503
await expect(
483-
page.getByText("Your Terra Workspace Link is Ready", { exact: true })
504+
page.getByText(tab.backpageExportButtons?.secondLandingMessage ?? "ERROR", {
505+
exact: true,
506+
})
484507
).toBeVisible({ timeout: 60000 });
485-
const openTerraButton = page.getByRole("button", { name: "Open Terra" });
486-
await expect(openTerraButton).toBeEnabled();
508+
const secondButtonLocator = page.getByRole("button", {
509+
name: tab.backpageExportButtons?.secondButtonName ?? "",
510+
});
511+
await expect(secondButtonLocator).toBeEnabled();
487512
// Click the "Open Terra" Button and await a new browser tab
488-
const pagePromise = context.waitForEvent("page");
489-
await openTerraButton.click();
490-
const newPage = await pagePromise;
513+
const newPagePromise = context.waitForEvent("page");
514+
await secondButtonLocator.click();
515+
const newPage = await newPagePromise;
491516
// Expect the new browser tab to look like the Terra page
492517
await expect(
493-
newPage.getByText(
494-
"If you are a new user or returning user, click sign in to continue."
495-
)
518+
newPage.getByText(tab.backpageExportButtons?.newTabMessage ?? "ERROR")
496519
).toBeVisible();
497520
}
498521

@@ -505,27 +528,38 @@ export async function testBackpageAccess(
505528
// Check that the first "Granted" tab has access granted
506529
const grantedRowLocator = getRowLocatorByAccess(page, "Granted");
507530
await expect(grantedRowLocator).toBeVisible();
508-
await grantedRowLocator.click();
531+
await grantedRowLocator.dispatchEvent("click");
532+
await expect(
533+
page.getByText(tab.backpageExportButtons?.detailsName ?? "")
534+
).toBeVisible();
509535
await expect(page.getByText("Access Granted")).toBeVisible();
510-
await page.getByText("Export", { exact: true }).click();
511-
await expect(page).toHaveURL(/\.*\/export-to-terra/);
536+
await page
537+
.getByText(tab.backpageExportButtons?.exportTabName ?? "ERROR", {
538+
exact: true,
539+
})
540+
.click();
541+
await expect(page).toHaveURL(tab.backpageExportButtons?.exportUrl ?? /ERROR/);
512542
await expect(page.getByRole("checkbox").first()).toBeVisible();
513543
const requestLinkButtonLocator = page.getByRole("button", {
514-
name: "Request Link",
544+
name: tab.backpageExportButtons?.firstButtonName,
515545
});
516546
await expect(requestLinkButtonLocator).toBeEnabled();
517547
// Go back to the table page
518-
await page.getByRole("link", { name: "Datasets" }).click();
548+
await page.getByRole("link", { name: tab.tabName }).click();
519549
// Check that the first "Required" tab does not have access granted
520550
const requiredRowLocator = getRowLocatorByAccess(page, "Required");
521551
await expect(requiredRowLocator).toBeVisible();
522552
await requiredRowLocator.click();
523553
await expect(page.getByText("Access Required")).toBeVisible();
524-
await page.getByText("Export", { exact: true }).click();
525-
await expect(page).toHaveURL(/\.*\/export-to-terra/);
554+
await page
555+
.getByText(tab.backpageExportButtons?.exportTabName ?? "ERROR", {
556+
exact: true,
557+
})
558+
.click();
559+
await expect(page).toHaveURL(tab.backpageExportButtons?.exportUrl ?? /ERROR/);
526560
await expect(
527561
page.getByText(
528-
"To export this dataset, please sign in and, if necessary, request access.",
562+
tab.backpageExportButtons?.accessNotGrantedMessage ?? "ERROR",
529563
{ exact: true }
530564
)
531565
).toBeVisible();
@@ -540,38 +574,43 @@ export async function testBackpageDetails(
540574
}
541575
await page.goto(tab.url);
542576
// Enable test columns
543-
await testSelectableColumns(page, tab); //TODO: check if this funtion breaks if selectable columns don't load in order
577+
await testSelectableColumns(page, tab); //TODO: check if this function breaks if selectable columns don't load in order
544578
const headers: { header: string; value: string }[] = [];
545579
const combinedColumns = tab.preselectedColumns.concat(tab.selectableColumns);
546580
const filterString = (x: string | undefined): x is string => x !== undefined;
581+
// Get the columns that correspond with a header on the backpage details
547582
const headerCorrespondingColumns: string[] = tab.backpageHeaders
548583
.map((header) => header?.correspondingColumn?.name)
549584
.filter(filterString)
550585
.map((x) => x.trim());
551-
console.log(headerCorrespondingColumns);
552586
for (let i = 0; i < combinedColumns.length; i++) {
553587
const headerColumnText = (
554588
await page.getByRole("columnheader").nth(i).innerText()
555589
).trim();
556590
if (headerCorrespondingColumns.includes(headerColumnText)) {
557591
const headerEntryText = await getNthElementTextLocator(
558592
page,
559-
2,
593+
0,
560594
i
561595
).innerText();
562596
const correspondingHeaderName = tab.backpageHeaders.find(
563597
(header: backpageHeader) =>
564598
header?.correspondingColumn?.name === headerColumnText
565599
)?.name;
566600
if (correspondingHeaderName === undefined) {
601+
// Fail the test, because this means there is an incorrect configuraiton in the tab definition
567602
return false;
568603
}
569604
headers.push({ header: correspondingHeaderName, value: headerEntryText });
570605
}
571606
}
572-
await getNthElementTextLocator(page, 2, 0).click();
573-
await expect(page.getByText("Dataset Details")).toBeVisible();
607+
await getNthElementTextLocator(page, 0, 0).click();
608+
await expect(
609+
page.getByText(tab.backpageExportButtons?.detailsName ?? "ERROR")
610+
).toBeVisible();
574611
for (const headerValue of headers) {
612+
// Expect the correct value to be below the correct header in the dataset values table
613+
// TODO: this locator does not appear to work on Webkit
575614
await expect(
576615
page
577616
.locator(

explorer/e2e/testInterfaces.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface TabDescription {
2+
backpageExportButtons?: backpageExportButtons;
23
backpageHeaders?: backpageHeader[];
34
emptyFirstColumn: boolean;
45
preselectedColumns: columnDescription[];
@@ -32,3 +33,15 @@ export interface backpageHeader {
3233
correspondingColumn?: columnDescription;
3334
name: string;
3435
}
36+
37+
export interface backpageExportButtons {
38+
accessNotGrantedMessage: string;
39+
detailsName: string;
40+
exportTabName: string;
41+
exportUrl: RegExp;
42+
firstButtonName: string;
43+
firstLoadingMessage: string;
44+
newTabMessage: string;
45+
secondButtonName: string;
46+
secondLandingMessage: string;
47+
}

0 commit comments

Comments
 (0)