Skip to content

Commit 7cc24c2

Browse files
committed
fix: fixed webkit issue in header tests (#4080)
1 parent 264b3ee commit 7cc24c2

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

explorer/e2e/anvil/anvil-backpages.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,5 @@ test("Check that information on the backpages matches information in the data ta
2424
page,
2525
}) => {
2626
test.setTimeout(120000);
27-
const passed = await testBackpageDetails(page, anvilTabs.datasets);
28-
if (!passed) {
29-
test.fail();
30-
}
27+
await testBackpageDetails(page, anvilTabs.datasets);
3128
});

explorer/e2e/testFunctions.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ export async function testExportBackpage(
470470
});
471471
await expect(firstButtonLocator).toBeEnabled();
472472
// Select all checkboxes on the pages
473-
const checkboxes = await page.getByRole("checkbox").all();
474-
console.log(checkboxes);
475-
for (const checkboxLocator of checkboxes) {
473+
const checkboxLocators = await page.getByRole("checkbox").all();
474+
console.log(checkboxLocators);
475+
for (const checkboxLocator of checkboxLocators) {
476476
console.log(checkboxLocator);
477477
if (!(await checkboxLocator.isChecked())) {
478478
await checkboxLocator.click();
@@ -506,7 +506,7 @@ export async function testExportBackpage(
506506
})
507507
).toBeVisible({ timeout: 60000 });
508508
const secondButtonLocator = page.getByRole("button", {
509-
name: tab.backpageExportButtons?.secondButtonName ?? "",
509+
name: tab.backpageExportButtons?.secondButtonName ?? "ERROR",
510510
});
511511
await expect(secondButtonLocator).toBeEnabled();
512512
// Click the "Open Terra" Button and await a new browser tab
@@ -523,25 +523,30 @@ export async function testBackpageAccess(
523523
page: Page,
524524
tab: TabDescription
525525
): Promise<void> {
526+
if (tab.backpageExportButtons == null) {
527+
// Fail if this test is ran on a tab without defined backpages
528+
await expect(false);
529+
return;
530+
}
526531
// Goto the specified tab
527532
await page.goto(tab.url);
528533
// Check that the first "Granted" tab has access granted
529534
const grantedRowLocator = getRowLocatorByAccess(page, "Granted");
530535
await expect(grantedRowLocator).toBeVisible();
531536
await grantedRowLocator.dispatchEvent("click");
532537
await expect(
533-
page.getByText(tab.backpageExportButtons?.detailsName ?? "")
538+
page.getByText(tab.backpageExportButtons.detailsName)
534539
).toBeVisible();
535540
await expect(page.getByText("Access Granted")).toBeVisible();
536541
await page
537-
.getByText(tab.backpageExportButtons?.exportTabName ?? "ERROR", {
542+
.getByText(tab.backpageExportButtons.exportTabName, {
538543
exact: true,
539544
})
540545
.click();
541-
await expect(page).toHaveURL(tab.backpageExportButtons?.exportUrl ?? /ERROR/);
546+
await expect(page).toHaveURL(tab.backpageExportButtons.exportUrl);
542547
await expect(page.getByRole("checkbox").first()).toBeVisible();
543548
const requestLinkButtonLocator = page.getByRole("button", {
544-
name: tab.backpageExportButtons?.firstButtonName,
549+
name: tab.backpageExportButtons.firstButtonName,
545550
});
546551
await expect(requestLinkButtonLocator).toBeEnabled();
547552
// Go back to the table page
@@ -568,9 +573,10 @@ export async function testBackpageAccess(
568573
export async function testBackpageDetails(
569574
page: Page,
570575
tab: TabDescription
571-
): Promise<boolean> {
572-
if (tab?.backpageHeaders === undefined) {
573-
return false;
576+
): Promise<void> {
577+
if (tab.backpageHeaders == null) {
578+
await expect(false);
579+
return; // This is unreachable, but typescript doesn't know without it
574580
}
575581
await page.goto(tab.url);
576582
// Enable test columns
@@ -590,7 +596,7 @@ export async function testBackpageDetails(
590596
if (headerCorrespondingColumns.includes(headerColumnText)) {
591597
const headerEntryText = await getNthElementTextLocator(
592598
page,
593-
0,
599+
1,
594600
i
595601
).innerText();
596602
const correspondingHeaderName = tab.backpageHeaders.find(
@@ -599,27 +605,25 @@ export async function testBackpageDetails(
599605
)?.name;
600606
if (correspondingHeaderName === undefined) {
601607
// Fail the test, because this means there is an incorrect configuraiton in the tab definition
602-
return false;
608+
await expect(false);
609+
return;
603610
}
604611
headers.push({ header: correspondingHeaderName, value: headerEntryText });
605612
}
606613
}
607-
await getNthElementTextLocator(page, 0, 0).click();
614+
await getNthElementTextLocator(page, 1, 0).click();
608615
await expect(
609616
page.getByText(tab.backpageExportButtons?.detailsName ?? "ERROR")
610617
).toBeVisible();
611618
for (const headerValue of headers) {
612619
// 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
614620
await expect(
615621
page
616-
.locator(
617-
`:text('${headerValue.value}'):below(:text('${headerValue.header}'))`
618-
)
622+
.locator(`:below(:text('${headerValue.header}'))`)
623+
.getByText(headerValue.value)
619624
.first()
620625
).toBeVisible();
621626
}
622-
return true;
623627
}
624628

625629
/* eslint-enable sonarjs/no-duplicate-string -- Checking duplicate strings again*/

0 commit comments

Comments
 (0)