Skip to content

Commit 4abe3b4

Browse files
committed
fix: removed all hardcoded constants from backpages tests (#4080)
1 parent 406f860 commit 4abe3b4

File tree

3 files changed

+69
-33
lines changed

3 files changed

+69
-33
lines changed

explorer/e2e/anvil/anvil-tabs.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,18 @@ export const anvilTabs: AnvilCMGTabCollection = {
8686
url: "/biosamples",
8787
},
8888
datasets: {
89+
backpageAccessTags: {
90+
deniedLongName: "Access Required",
91+
deniedShortName: "Required",
92+
grantedLongName: "Access Granted",
93+
grantedShortName: "Granted",
94+
},
8995
backpageExportButtons: {
9096
accessNotGrantedMessage:
9197
"To export this dataset, please sign in and, if necessary, request access.",
9298
detailsName: "Dataset Details",
9399
exportTabName: "Export",
94-
exportUrl: /\.*\/export-to-terra/,
100+
exportUrlRegExp: /\.*\/export-to-terra/,
95101
firstButtonName: "Request Link",
96102
firstLoadingMessage: "Your link will be ready shortly...",
97103
newTabMessage:

explorer/e2e/testFunctions.ts

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -451,26 +451,34 @@ export async function testExportBackpage(
451451
page: Page,
452452
tab: TabDescription
453453
): Promise<void> {
454+
if (tab.backpageExportButtons == null || tab.backpageAccessTags == null) {
455+
// Fail if this test is ran on a tab without defined backpages
456+
await expect(false);
457+
return;
458+
}
454459
// Goto the specified tab
455460
await page.goto(tab.url);
456461
// Expect to find row with a granted status indicator
457-
const grantedRowLocator = getRowLocatorByAccess(page, "Granted");
462+
const grantedRowLocator = getRowLocatorByAccess(
463+
page,
464+
tab.backpageAccessTags.grantedShortName
465+
);
458466
await expect(grantedRowLocator).toBeVisible();
459467
// Click into the selected row
460-
await grantedRowLocator.dispatchEvent("click"); //TODO: this is sometimes unreliable and changes the url without changing the tab.
468+
await grantedRowLocator.dispatchEvent("click");
461469
await expect(
462-
page.getByText(tab.backpageExportButtons?.detailsName ?? "")
470+
page.getByText(tab.backpageExportButtons.detailsName)
463471
).toBeVisible();
464472
// Click the "Export" tab
465473
await page
466-
.getByText(tab.backpageExportButtons?.exportTabName ?? "ERROR", {
474+
.getByText(tab.backpageExportButtons.exportTabName, {
467475
exact: true,
468476
})
469477
.click();
470-
await expect(page).toHaveURL(tab.backpageExportButtons?.exportUrl ?? "");
478+
await expect(page).toHaveURL(tab.backpageExportButtons.exportUrlRegExp);
471479
await expect(page.getByRole("checkbox").first()).toBeVisible();
472480
const firstButtonLocator = page.getByRole("button", {
473-
name: "Request Link",
481+
name: tab.backpageExportButtons.firstButtonName,
474482
});
475483
await expect(firstButtonLocator).toBeEnabled();
476484
// Select all checkboxes on the pages
@@ -498,17 +506,17 @@ export async function testExportBackpage(
498506
await expect(firstButtonLocator).toBeEnabled({ timeout: 10000 });
499507
await firstButtonLocator.click();
500508
await expect(
501-
page.getByText(tab.backpageExportButtons?.firstLoadingMessage ?? "ERROR", {
509+
page.getByText(tab.backpageExportButtons.firstLoadingMessage, {
502510
exact: true,
503511
})
504512
).toBeVisible();
505513
await expect(
506-
page.getByText(tab.backpageExportButtons?.secondLandingMessage ?? "ERROR", {
514+
page.getByText(tab.backpageExportButtons.secondLandingMessage, {
507515
exact: true,
508516
})
509517
).toBeVisible({ timeout: 60000 });
510518
const secondButtonLocator = page.getByRole("button", {
511-
name: tab.backpageExportButtons?.secondButtonName ?? "ERROR",
519+
name: tab.backpageExportButtons?.secondButtonName,
512520
});
513521
await expect(secondButtonLocator).toBeEnabled();
514522
// Click the "Open Terra" Button and await a new browser tab
@@ -517,35 +525,40 @@ export async function testExportBackpage(
517525
const newPage = await newPagePromise;
518526
// Expect the new browser tab to look like the Terra page
519527
await expect(
520-
newPage.getByText(tab.backpageExportButtons?.newTabMessage ?? "ERROR")
528+
newPage.getByText(tab.backpageExportButtons?.newTabMessage)
521529
).toBeVisible();
522530
}
523531

524532
export async function testBackpageAccess(
525533
page: Page,
526534
tab: TabDescription
527535
): Promise<void> {
528-
if (tab.backpageExportButtons == null) {
536+
if (tab.backpageExportButtons == null || tab.backpageAccessTags == null) {
529537
// Fail if this test is ran on a tab without defined backpages
530538
await expect(false);
531539
return;
532540
}
533541
// Goto the specified tab
534542
await page.goto(tab.url);
535543
// Check that the first "Granted" tab has access granted
536-
const grantedRowLocator = getRowLocatorByAccess(page, "Granted");
544+
const grantedRowLocator = getRowLocatorByAccess(
545+
page,
546+
tab.backpageAccessTags.grantedShortName
547+
);
537548
await expect(grantedRowLocator).toBeVisible();
538549
await grantedRowLocator.dispatchEvent("click");
539550
await expect(
540551
page.getByText(tab.backpageExportButtons.detailsName)
541552
).toBeVisible();
542-
await expect(page.getByText("Access Granted")).toBeVisible();
553+
await expect(
554+
page.getByText(tab.backpageAccessTags.grantedLongName)
555+
).toBeVisible();
543556
await page
544557
.getByText(tab.backpageExportButtons.exportTabName, {
545558
exact: true,
546559
})
547560
.click();
548-
await expect(page).toHaveURL(tab.backpageExportButtons.exportUrl);
561+
await expect(page).toHaveURL(tab.backpageExportButtons.exportUrlRegExp);
549562
await expect(page.getByRole("checkbox").first()).toBeVisible();
550563
const requestLinkButtonLocator = page.getByRole("button", {
551564
name: tab.backpageExportButtons.firstButtonName,
@@ -554,21 +567,25 @@ export async function testBackpageAccess(
554567
// Go back to the table page
555568
await page.getByRole("link", { name: tab.tabName }).click();
556569
// Check that the first "Required" tab does not have access granted
557-
const requiredRowLocator = getRowLocatorByAccess(page, "Required");
558-
await expect(requiredRowLocator).toBeVisible();
559-
await requiredRowLocator.click();
560-
await expect(page.getByText("Access Required")).toBeVisible();
570+
const deniedRowLocator = getRowLocatorByAccess(
571+
page,
572+
tab.backpageAccessTags.deniedShortName
573+
);
574+
await expect(deniedRowLocator).toBeVisible();
575+
await deniedRowLocator.dispatchEvent("click");
576+
await expect(
577+
page.getByText(tab.backpageAccessTags.deniedLongName)
578+
).toBeVisible();
561579
await page
562-
.getByText(tab.backpageExportButtons?.exportTabName ?? "ERROR", {
580+
.getByText(tab.backpageExportButtons.exportTabName, {
563581
exact: true,
564582
})
565583
.click();
566-
await expect(page).toHaveURL(tab.backpageExportButtons?.exportUrl ?? /ERROR/);
584+
await expect(page).toHaveURL(tab.backpageExportButtons.exportUrlRegExp);
567585
await expect(
568-
page.getByText(
569-
tab.backpageExportButtons?.accessNotGrantedMessage ?? "ERROR",
570-
{ exact: true }
571-
)
586+
page.getByText(tab.backpageExportButtons.accessNotGrantedMessage, {
587+
exact: true,
588+
})
572589
).toBeVisible();
573590
}
574591

@@ -584,19 +601,23 @@ const hoverAndGetText = async (
584601
columnPosition
585602
);
586603
const cellText = await cellLocator.innerText();
587-
604+
// Check if the cell appears to be an Ntag cell
588605
if (
589606
columnDescription != undefined &&
590607
columnDescription.pluralizedLabel != undefined &&
591608
RegExp("\\s*[0-9]+ " + columnDescription.pluralizedLabel + "\\s*").test(
592609
cellText
593610
)
594611
) {
612+
// Hover over the text of the NTag cell
595613
await cellLocator.locator("*").last().hover();
614+
// Read the tooltip
596615
await page.getByRole("tooltip").waitFor();
597616
const outputText = (await page.getByRole("tooltip").innerText()).trim();
617+
// Hover over a different part of the page to ensure that the tooltip disappears
598618
await page.getByRole("columnheader").first().hover();
599619
await expect(page.getByRole("tooltip")).toHaveCount(0);
620+
// Return the tooltip contents
600621
return outputText;
601622
}
602623
return cellText.trim();
@@ -606,13 +627,14 @@ export async function testBackpageDetails(
606627
page: Page,
607628
tab: TabDescription
608629
): Promise<void> {
609-
if (tab.backpageHeaders == null) {
630+
if (tab.backpageHeaders == null || tab.backpageExportButtons == null) {
631+
// If the tab is not set up with backpage info, fail the test
610632
await expect(false);
611-
return; // This is unreachable due to the expect, but typescript doesn't know
633+
return;
612634
}
613635
await page.goto(tab.url);
614636
// Enable test columns
615-
await testSelectableColumns(page, tab); //TODO: check if this function breaks if selectable columns don't load in order
637+
await testSelectableColumns(page, tab);
616638
const headers: { header: string; value: string }[] = [];
617639
const combinedColumns = tab.preselectedColumns.concat(tab.selectableColumns);
618640
const filterString = (x: string | undefined): x is string => x !== undefined;
@@ -628,7 +650,7 @@ export async function testBackpageDetails(
628650
).trim();
629651
// If the selected column has an entry on the backpage
630652
if (backpageCorrespondingColumns.includes(columnHeaderName)) {
631-
// Get the object of the current column (we have to do it this way, because the combinedColumn list is not ordered)
653+
// Get the object representing the current column
632654
const columnObject = combinedColumns.find(
633655
(x) => x.name == columnHeaderName
634656
);
@@ -639,7 +661,7 @@ export async function testBackpageDetails(
639661
(header: BackpageHeader) =>
640662
header?.correspondingColumn?.name === columnHeaderName
641663
)?.name;
642-
if (correspondingHeaderName === undefined) {
664+
if (correspondingHeaderName == null) {
643665
// Fail the test, because this means there is an incorrect configuraiton in the tab definition
644666
await expect(false);
645667
return;
@@ -651,7 +673,7 @@ export async function testBackpageDetails(
651673
await getNthElementTextLocator(page, 0, 0).click();
652674
// Expect the details name to be visible
653675
await expect(
654-
page.getByText(tab.backpageExportButtons?.detailsName ?? "ERROR")
676+
page.getByText(tab.backpageExportButtons.detailsName)
655677
).toBeVisible();
656678
for (const headerValue of headers) {
657679
// Expect the correct value to be below the correct header in the dataset values table

explorer/e2e/testInterfaces.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface TabDescription {
2+
backpageAccessTags?: BackpageAccessTags;
23
backpageExportButtons?: BackpageExportButtons;
34
backpageHeaders?: BackpageHeader[];
45
emptyFirstColumn: boolean;
@@ -35,11 +36,18 @@ export interface BackpageHeader {
3536
name: string;
3637
}
3738

39+
export interface BackpageAccessTags {
40+
deniedLongName: string;
41+
deniedShortName: string;
42+
grantedLongName: string;
43+
grantedShortName: string;
44+
}
45+
3846
export interface BackpageExportButtons {
3947
accessNotGrantedMessage: string;
4048
detailsName: string;
4149
exportTabName: string;
42-
exportUrl: RegExp;
50+
exportUrlRegExp: RegExp;
4351
firstButtonName: string;
4452
firstLoadingMessage: string;
4553
newTabMessage: string;

0 commit comments

Comments
 (0)