Skip to content

Commit 8c9475b

Browse files
committed
test: fixed comment and readme typos, revised backpage tests (#4080)
1 parent 12f4473 commit 8c9475b

File tree

5 files changed

+98
-51
lines changed

5 files changed

+98
-51
lines changed

explorer/e2e/anvil/anvil-tabs-buttons.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { test } from "@playwright/test";
22
import { testTab } from "../testFunctions";
33
import { anvilTabs } from "./anvil-tabs";
44

5-
test("Expect clicking the activities tab to go to the correct url and to show all of the relevant columns when selected", async ({
5+
test("Expect clicking the datasets tab to go to the correct url and to show all of the relevant columns when selected", async ({
66
page,
77
}) => {
88
await page.goto(anvilTabs.activities.url);
99
await testTab(page, anvilTabs.datasets);
1010
});
1111

12-
test("Expect clicking the datasets tab to go to the correct url and to show all of the relevant columns when selected", async ({
12+
test("Expect clicking the activities tab to go to the correct url and to show all of the relevant columns when selected", async ({
1313
page,
1414
}) => {
1515
await page.goto(anvilTabs.datasets.url);
@@ -34,5 +34,5 @@ test("Expect clicking the biosamples tab to go to the correct url and to show al
3434
page,
3535
}) => {
3636
await page.goto(anvilTabs.datasets.url);
37-
await testTab(page, anvilTabs.datasets);
37+
await testTab(page, anvilTabs.biosamples);
3838
});

explorer/e2e/anvil/anvil-tabs.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ export const anvilTabs: AnvilCMGTabCollection = {
109109
accessNotGrantedMessage:
110110
"To export this dataset, please sign in and, if necessary, request access.",
111111
detailsName: "Dataset Details",
112+
exportActionButtonText: "Open Terra",
113+
exportRequestButtonText: "Request Link",
112114
exportTabName: "Export",
113115
exportUrlRegExp: /\.*\/export-to-terra/,
114-
firstButtonName: "Request Link",
115116
firstLoadingMessage: "Your link will be ready shortly...",
116117
newTabMessage:
117118
"If you are a new user or returning user, click sign in to continue.",
118-
secondButtonName: "Open Terra",
119119
secondLandingMessage: "Your Terra Workspace Link is Ready",
120120
},
121121
backpageHeaders: [

explorer/e2e/testFunctions.ts

+88-41
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ export async function testFilterPersistence(
363363
const filterNameMatch = (await filterToSelectLocator.innerText())
364364
.trim()
365365
.match(/^\S*/);
366-
if (filterNameMatch == null) {
366+
if (!filterNameMatch) {
367367
// This means that the selected filter did not have any non-whitespace text
368368
// associated with it, making the test impossible to complete.
369369
console.log("ERROR: Filter name is blank, so the test cannot continue");
@@ -542,7 +542,13 @@ export async function testClearAll(
542542
}
543543
}
544544

545-
const getRowLocatorByAccess = (page: Page, access: string): Locator =>
545+
/**
546+
* Get the first link to a backpage with specified backpage access
547+
* @param page - a Playright page locator
548+
* @param access - the string denoting the level of access desired
549+
* @returns a Pla
550+
*/
551+
const getBackpageLinkLocatorByAccess = (page: Page, access: string): Locator =>
546552
page
547553
.getByRole("row")
548554
.filter({ has: page.getByRole("cell", { name: access }) })
@@ -551,21 +557,29 @@ const getRowLocatorByAccess = (page: Page, access: string): Locator =>
551557
.first()
552558
.getByRole("link");
553559

554-
// Backpages tests
560+
/**
561+
* Test the export process for the specified tab
562+
* @param context - a Playwright browser context object
563+
* @param page - a Playwright page object
564+
* @param tab - the tab to test on
565+
*/
555566
export async function testExportBackpage(
556567
context: BrowserContext,
557568
page: Page,
558569
tab: TabDescription
559570
): Promise<void> {
560-
if (tab.backpageExportButtons == null || tab.backpageAccessTags == null) {
571+
if (
572+
tab.backpageExportButtons === undefined ||
573+
tab.backpageAccessTags === undefined
574+
) {
561575
// Fail if this test is ran on a tab without defined backpages
562576
await expect(false);
563577
return;
564578
}
565579
// Goto the specified tab
566580
await page.goto(tab.url);
567581
// Expect to find row with a granted status indicator
568-
const grantedRowLocator = getRowLocatorByAccess(
582+
const grantedRowLocator = getBackpageLinkLocatorByAccess(
569583
page,
570584
tab.backpageAccessTags.grantedShortName
571585
);
@@ -583,34 +597,41 @@ export async function testExportBackpage(
583597
.click();
584598
await expect(page).toHaveURL(tab.backpageExportButtons.exportUrlRegExp);
585599
await expect(page.getByRole("checkbox").first()).toBeVisible();
586-
const firstButtonLocator = page.getByRole("button", {
587-
name: tab.backpageExportButtons.firstButtonName,
600+
const exportRequestButtonLocator = page.getByRole("button", {
601+
name: tab.backpageExportButtons.exportRequestButtonText,
588602
});
589-
await expect(firstButtonLocator).toBeEnabled();
590-
// Select all checkboxes on the pages
591-
const checkboxLocators = await page.getByRole("checkbox").all();
592-
for (const checkboxLocator of checkboxLocators) {
593-
if (!(await checkboxLocator.isChecked())) {
594-
await checkboxLocator.click();
595-
await expect(checkboxLocator).toBeChecked();
596-
await expect(checkboxLocator).toBeEnabled({ timeout: 10000 });
597-
}
603+
await expect(exportRequestButtonLocator).toBeEnabled();
604+
// Select all checkboxes that are not in a table
605+
const allNonTableCheckboxLocators = await page
606+
.locator("input[type='checkbox']:not(table input[type='checkbox'])")
607+
.all();
608+
for (const checkboxLocator of allNonTableCheckboxLocators) {
609+
await checkboxLocator.click();
610+
await expect(checkboxLocator).toBeChecked();
611+
await expect(checkboxLocator).toBeEnabled({ timeout: 10000 });
598612
}
599-
await expect(firstButtonLocator).toBeEnabled({ timeout: 10000 });
600-
// Uncheck all checkboxes except one in each table, to reduce overhead
613+
// Check one checkbox in each table
601614
for (const tableLocator of await page.getByRole("table").all()) {
602-
const checkboxLocatorsInTable = await tableLocator
615+
const allInTableCheckboxLocators = await tableLocator
603616
.getByRole("checkbox")
604617
.all();
605-
for (const checkboxLocator of checkboxLocatorsInTable.slice(2)) {
606-
await checkboxLocator.click();
607-
await expect(checkboxLocator).not.toBeChecked();
608-
await expect(checkboxLocator).toBeEnabled({ timeout: 10000 });
618+
const secondCheckboxInTableLocator = allInTableCheckboxLocators[1];
619+
await secondCheckboxInTableLocator.click();
620+
await expect(secondCheckboxInTableLocator).toBeChecked();
621+
await expect(secondCheckboxInTableLocator).toBeEnabled({ timeout: 10000 });
622+
const otherInTableCheckboxLocators = [
623+
allInTableCheckboxLocators[0],
624+
...allInTableCheckboxLocators.slice(2),
625+
];
626+
// Make sure that no other checkboxes are selected
627+
for (const otherCheckboxLocator of otherInTableCheckboxLocators) {
628+
await expect(otherCheckboxLocator).not.toBeChecked();
629+
await expect(otherCheckboxLocator).toBeEnabled();
609630
}
610631
}
611-
// Click the "Request Link" button
612-
await expect(firstButtonLocator).toBeEnabled({ timeout: 10000 });
613-
await firstButtonLocator.click();
632+
// Click the Export Request button
633+
await expect(exportRequestButtonLocator).toBeEnabled({ timeout: 10000 });
634+
await exportRequestButtonLocator.click();
614635
await expect(
615636
page.getByText(tab.backpageExportButtons.firstLoadingMessage, {
616637
exact: true,
@@ -621,33 +642,42 @@ export async function testExportBackpage(
621642
exact: true,
622643
})
623644
).toBeVisible({ timeout: 60000 });
624-
const secondButtonLocator = page.getByRole("button", {
625-
name: tab.backpageExportButtons?.secondButtonName,
645+
const exportActionButtonLocator = page.getByRole("button", {
646+
name: tab.backpageExportButtons?.exportActionButtonText,
626647
});
627-
await expect(secondButtonLocator).toBeEnabled();
628-
// Click the "Open Terra" Button and await a new browser tab
648+
await expect(exportActionButtonLocator).toBeEnabled();
649+
// Click the Export Action Button and await a new browser tab
629650
const newPagePromise = context.waitForEvent("page");
630-
await secondButtonLocator.click();
651+
await exportActionButtonLocator.click();
631652
const newPage = await newPagePromise;
632-
// Expect the new browser tab to look like the Terra page
653+
// Expect the new browser tab to display the new tab content
633654
await expect(
634655
newPage.getByText(tab.backpageExportButtons?.newTabMessage)
635656
).toBeVisible();
636657
}
637658

659+
/**
660+
* Test that export access is available on entries where access shows as available
661+
* and is not on entries where access shows as unavailable
662+
* @param page - a Playwright page objext
663+
* @param tab - the Tab to test on
664+
*/
638665
export async function testBackpageAccess(
639666
page: Page,
640667
tab: TabDescription
641668
): Promise<void> {
642-
if (tab.backpageExportButtons == null || tab.backpageAccessTags == null) {
669+
if (
670+
tab.backpageExportButtons === undefined ||
671+
tab.backpageAccessTags === undefined
672+
) {
643673
// Fail if this test is ran on a tab without defined backpages
644674
await expect(false);
645675
return;
646676
}
647677
// Goto the specified tab
648678
await page.goto(tab.url);
649679
// Check that the first "Granted" tab has access granted
650-
const grantedRowLocator = getRowLocatorByAccess(
680+
const grantedRowLocator = getBackpageLinkLocatorByAccess(
651681
page,
652682
tab.backpageAccessTags.grantedShortName
653683
);
@@ -667,13 +697,13 @@ export async function testBackpageAccess(
667697
await expect(page).toHaveURL(tab.backpageExportButtons.exportUrlRegExp);
668698
await expect(page.getByRole("checkbox").first()).toBeVisible();
669699
const requestLinkButtonLocator = page.getByRole("button", {
670-
name: tab.backpageExportButtons.firstButtonName,
700+
name: tab.backpageExportButtons.exportRequestButtonText,
671701
});
672702
await expect(requestLinkButtonLocator).toBeEnabled();
673703
// Go back to the table page
674704
await page.getByRole("link", { name: tab.tabName }).click();
675705
// Check that the first "Required" tab does not have access granted
676-
const deniedRowLocator = getRowLocatorByAccess(
706+
const deniedRowLocator = getBackpageLinkLocatorByAccess(
677707
page,
678708
tab.backpageAccessTags.deniedShortName
679709
);
@@ -695,6 +725,15 @@ export async function testBackpageAccess(
695725
).toBeVisible();
696726
}
697727

728+
/**
729+
* Get the text from a cell by reading the tooltip if it appears to be an N-tag
730+
* cell or by reading the text if it does not appear to be
731+
* @param page - a Playwright Page object
732+
* @param columnDescription - a columnDescription object for the column
733+
* @param rowPosition - the zero-indexed position of the row
734+
* @param columnPosition - the zero-indexed position of the column
735+
* @returns - a Promise with the cell's text
736+
*/
698737
const hoverAndGetText = async (
699738
page: Page,
700739
columnDescription: ColumnDescription | undefined,
@@ -709,8 +748,8 @@ const hoverAndGetText = async (
709748
const cellText = await cellLocator.innerText();
710749
// Check if the cell appears to be an Ntag cell
711750
if (
712-
columnDescription != undefined &&
713-
columnDescription.pluralizedLabel != undefined &&
751+
!columnDescription !== undefined &&
752+
columnDescription?.pluralizedLabel !== undefined &&
714753
RegExp("\\s*[0-9]+ " + columnDescription.pluralizedLabel + "\\s*").test(
715754
cellText
716755
)
@@ -729,11 +768,19 @@ const hoverAndGetText = async (
729768
return cellText.trim();
730769
};
731770

771+
/**
772+
* Check that the details in the backpage sidebar match information in the data table
773+
* @param page - a Playwright page object
774+
* @param tab - the tab to test on
775+
*/
732776
export async function testBackpageDetails(
733777
page: Page,
734778
tab: TabDescription
735779
): Promise<void> {
736-
if (tab.backpageHeaders == null || tab.backpageExportButtons == null) {
780+
if (
781+
tab.backpageHeaders === undefined ||
782+
tab.backpageExportButtons === undefined
783+
) {
737784
// If the tab is not set up with backpage info, fail the test
738785
await expect(false);
739786
return;
@@ -767,8 +814,8 @@ export async function testBackpageDetails(
767814
(header: BackpageHeader) =>
768815
header?.correspondingColumn?.name === columnHeaderName
769816
)?.name;
770-
if (correspondingHeaderName == null) {
771-
// Fail the test, because this means there is an incorrect configuraiton in the tab definition
817+
if (correspondingHeaderName === undefined) {
818+
// Fail the test, because this means there is an incorrect configuration in the tab definition
772819
await expect(false);
773820
return;
774821
}

explorer/e2e/testInterfaces.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ export interface BackpageAccessTags {
4747
export interface BackpageExportButtons {
4848
accessNotGrantedMessage: string;
4949
detailsName: string;
50+
exportActionButtonText: string;
51+
exportRequestButtonText: string;
5052
exportTabName: string;
5153
exportUrlRegExp: RegExp;
52-
firstButtonName: string;
5354
firstLoadingMessage: string;
5455
newTabMessage: string;
55-
secondButtonName: string;
5656
secondLandingMessage: string;
5757
}

explorer/e2e/testReadme.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ through the actions taken as part of the test and view the impact on the web pag
7272
- All tests rely on correct lists of tabs, columns, and filters in `anvil-tabs.ts`
7373
- Backpages (`anvil-backpages.spec.ts`)
7474
- Test the export process on the "Datasets" tab
75-
- Select the first dataset that does not have access control enabled and go to the export tab on its backpage. Select a one filter checkbox for each category then select the "Export to Terra" button
76-
- Check that buttons, text, and loading text appears as expected, and that a new tab appears when the "Export to Terra" button is pressed
75+
- Selects the first dataset that does not have access control enabled and go to the export tab on its backpage. Then, selects one filter checkbox for each category, then finally selects the "Export to Terra" button
76+
- Checks that buttons, text, and loading text appears as expected, and that a new tab appears when the "Export to Terra" button is pressed
7777
- Relevant text constants are stored in `anvil-tabs.ts`
7878
- Currently disabled as the export button is disabled
7979
- Test that access control works properly on the "Datasets" tab
80-
- Select a non access controlled tab and check that text associataed with access being granted is present, then repeat for an access controleld tab
80+
- Selects a non-access-controlled tab and check that text associated with access being granted is present, then repeats for an access-controlled tab
8181
- Relevant text constants are stored in `anvil-tabs.ts`
8282
- Currently disabled as the export button is disabled
8383
- Test that data in the sidebar of the "Datasets" tab is the same as the text displayed in the main tab le

0 commit comments

Comments
 (0)