Skip to content

Commit

Permalink
test: cleaned up test code (#4117)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpaten committed Nov 8, 2024
1 parent 8e6da72 commit 2629723
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 51 deletions.
14 changes: 12 additions & 2 deletions explorer/e2e/anvil/anvil-backpages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,24 @@ test.skip("Smoke test `Export to Terra` button on the first available dataset",
page,
}) => {
test.setTimeout(120000);
await testExportBackpage(context, page, ANVIL_TABS.DATASETS);
const testResult = await testExportBackpage(
context,
page,
ANVIL_TABS.DATASETS
);
if (!testResult) {
test.fail();
}
});

test.skip("Check access controls on the datasets backpages work for the first two tabs", async ({
page,
}) => {
test.setTimeout(120000);
await testBackpageAccess(page, ANVIL_TABS.DATASETS);
const testResult = await testBackpageAccess(page, ANVIL_TABS.DATASETS);
if (!testResult) {
test.fail();
}
});

test("Check that information on the backpages matches information in the data tables", async ({
Expand Down
15 changes: 12 additions & 3 deletions explorer/e2e/anvil/anvil-index-export-button.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import test from "@playwright/test";
import {
testBulkDownloadIndexExportWorkflow,
testIndexExportSummary,
testIndexExportWorkflow,
} from "../testFunctions";
import { ANVIL_TABS } from "./anvil-tabs";

test("Smoke test File Manifest Request index export workflow on the Files tab", async ({
page,
}) => {
await testIndexExportWorkflow(page, ANVIL_TABS.FILES);
const testResult = await testBulkDownloadIndexExportWorkflow(
page,
ANVIL_TABS.FILES
);
if (!testResult) {
test.fail();
}
});

test("Check that figures in the Selected Data Summary tab on the index export page matches figures on the index page on the BioSamples tab", async ({
page,
}) => {
await testIndexExportSummary(page, ANVIL_TABS.BIOSAMPLES);
const testResult = await testIndexExportSummary(page, ANVIL_TABS.BIOSAMPLES);
if (!testResult) {
test.fail();
}
});
24 changes: 12 additions & 12 deletions explorer/e2e/anvil/anvil-tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,22 @@ export const REPORTED_ETHNICITY_INDEX = 10;

const ANVIL_CMG_SEARCH_FILTERS_PLACEHOLDER_TEXT = "Search all filters...";

export const anvilIndexExportButtons: IndexExportButtons = {
export const ANVIL_INDEX_EXPORT_BUTTONS: IndexExportButtons = {
actionLandingMessage: "Confirm Organism Type and Manifest File Formats",
detailsName: "Selected Data Summary",
detailsToCheck: ["BioSamples", "Donors", "Files"],
exportActionButtonText: "Download Manifest",
exportOptionButtonText: "Request File Manifest",
exportRequestButtonText: "Prepare Manifest",
firstLandingMessage:
"Download a File Manifest with Metadata for the Selected Data",
indexExportButtonText: "Export",
secondLandingMessage: "Confirm Organism Type and Manifest File Formats",
secondLoadingMessage: "Your manifest will be ready shortly...",
requestLandingMessage:
"Download a File Manifest with Metadata for the Selected Data",
};

export const ANVIL_TABS: AnvilCMGTabCollection = {
ACTIVITIES: {
emptyFirstColumn: false,
indexExportPage: anvilIndexExportButtons,
indexExportPage: ANVIL_INDEX_EXPORT_BUTTONS,
maxPages: 25,
preselectedColumns: ANVIL_ACTIVITIES_PRESELECTED_COLUMNS_BY_NAME,
searchFiltersPlaceholderText: ANVIL_CMG_SEARCH_FILTERS_PLACEHOLDER_TEXT,
Expand All @@ -72,7 +71,7 @@ export const ANVIL_TABS: AnvilCMGTabCollection = {
},
BIOSAMPLES: {
emptyFirstColumn: false,
indexExportPage: anvilIndexExportButtons,
indexExportPage: ANVIL_INDEX_EXPORT_BUTTONS,
maxPages: 25,
preselectedColumns: ANVIL_BIOSAMPLES_PRESELECTED_COLUMNS_BY_NAME,
searchFiltersPlaceholderText: ANVIL_CMG_SEARCH_FILTERS_PLACEHOLDER_TEXT,
Expand All @@ -90,15 +89,16 @@ export const ANVIL_TABS: AnvilCMGTabCollection = {
backpageExportButtons: {
accessNotGrantedMessage:
"To export this dataset, please sign in and, if necessary, request access.",
actionLandingMessage: "Your Terra Workspace Link is Ready",
detailsName: "Dataset Details",
exportActionButtonText: "Open Terra",
exportRequestButtonText: "Request Link",
exportTabName: "Export",
exportUrlRegExp: /\.*\/export-to-terra/,
firstLoadingMessage: "Your link will be ready shortly...",
newTabMessage:
"If you are a new user or returning user, click sign in to continue.",
secondLandingMessage: "Your Terra Workspace Link is Ready",
requestLandingMessage:
"Terra is a biomedical research platform to analyze data using workflows, Jupyter Notebooks, RStudio, and Galaxy.",
},
backpageHeaders: [
{
Expand Down Expand Up @@ -148,7 +148,7 @@ export const ANVIL_TABS: AnvilCMGTabCollection = {
},
],
emptyFirstColumn: false,
indexExportPage: anvilIndexExportButtons,
indexExportPage: ANVIL_INDEX_EXPORT_BUTTONS,
maxPages: 25,
preselectedColumns: ANVIL_DATASETS_PRESELECTED_COLUMNS_BY_NAME,
searchFiltersPlaceholderText: ANVIL_CMG_SEARCH_FILTERS_PLACEHOLDER_TEXT,
Expand All @@ -158,7 +158,7 @@ export const ANVIL_TABS: AnvilCMGTabCollection = {
},
DONORS: {
emptyFirstColumn: false,
indexExportPage: anvilIndexExportButtons,
indexExportPage: ANVIL_INDEX_EXPORT_BUTTONS,
maxPages: 25,
preselectedColumns: ANVIL_DONORS_PRESELECTED_COLUMNS_BY_NAME,
searchFiltersPlaceholderText: ANVIL_CMG_SEARCH_FILTERS_PLACEHOLDER_TEXT,
Expand All @@ -168,7 +168,7 @@ export const ANVIL_TABS: AnvilCMGTabCollection = {
},
FILES: {
emptyFirstColumn: true,
indexExportPage: anvilIndexExportButtons,
indexExportPage: ANVIL_INDEX_EXPORT_BUTTONS,
maxPages: 25,
preselectedColumns: ANVIL_FILES_PRESELECTED_COLUMNS_BY_NAME,
searchFiltersPlaceholderText: ANVIL_CMG_SEARCH_FILTERS_PLACEHOLDER_TEXT,
Expand Down
78 changes: 49 additions & 29 deletions explorer/e2e/testFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ export async function testSortCatalog(
const columnNameArray = (
await page.getByRole("columnheader").allInnerTexts()
).map((entry) => entry.trim());
console.log(columnNameArray);
const columnObjectArray = Array.from(Object.values(tab.preselectedColumns));
for (
let columnPosition = 0;
Expand Down Expand Up @@ -424,7 +423,6 @@ export const getFirstFilterOptionLocator = (page: Page): Locator => {
export const getFilterOptionName = async (
firstFilterOptionLocator: Locator
): Promise<string> => {
console.log(await firstFilterOptionLocator.innerText());
// Filter options display as "[text]\n[number]" , sometimes with extra whitespace, so we split on newlines and take the first non-empty string
return (
(await firstFilterOptionLocator.innerText())
Expand Down Expand Up @@ -756,12 +754,17 @@ const getBackpageLinkLocatorByAccess = (page: Page, access: string): Locator =>
.first()
.getByRole("link");

/**
* Make an export request that leaves only the minimal number of checkboxes selected
* @param page - a Playwright page object
* @param exportRequestButtonLocator - a Playwright locator to the button to click after the export request is completed
*/
const makeMinimalExportRequest = async (
page: Page,
exportRequestButtonLocator: Locator
): Promise<void> => {
await expect(exportRequestButtonLocator).toBeEnabled();
// Expect there to be exactly one table on the backpage
// Expect there to be exactly one table on the export page
await expect(page.getByRole("table")).toHaveCount(1);
// Select all checkboxes that are not in a table
const allNonTableCheckboxLocators = await page
Expand Down Expand Up @@ -801,21 +804,19 @@ const makeMinimalExportRequest = async (
* @param context - a Playwright browser context object
* @param page - a Playwright page object
* @param tab - the tab to test on
* @returns - true if the test passes, false if the test fails but does not fail an assertion
*/
export async function testExportBackpage(
context: BrowserContext,
page: Page,
tab: TabDescription
): Promise<void> {
): Promise<boolean> {
if (
tab.backpageExportButtons === undefined ||
tab.backpageAccessTags === undefined ||
tab.backpageExportButtons?.firstLoadingMessage === undefined ||
tab.backpageExportButtons?.secondLandingMessage === undefined
tab.backpageAccessTags === undefined
) {
// Fail if this test is ran on a tab without defined backpages
await expect(false);
return;
// Fail if this test u on a tab without defined backpages
return false;
}
// Goto the specified tab
await page.goto(tab.url);
Expand All @@ -836,6 +837,9 @@ export async function testExportBackpage(
exact: true,
})
.click();
await expect(
page.getByText(tab.backpageExportButtons.requestLandingMessage)
).toBeVisible();
await expect(page).toHaveURL(tab.backpageExportButtons.exportUrlRegExp);
await expect(page.getByRole("checkbox").first()).toBeVisible();
const exportRequestButtonLocator = page.getByRole("button", {
Expand All @@ -844,12 +848,7 @@ export async function testExportBackpage(
// Complete the export request form
await makeMinimalExportRequest(page, exportRequestButtonLocator);
await expect(
page.getByText(tab.backpageExportButtons.firstLoadingMessage, {
exact: true,
})
).toBeVisible();
await expect(
page.getByText(tab.backpageExportButtons.secondLandingMessage, {
page.getByText(tab.backpageExportButtons.actionLandingMessage, {
exact: true,
})
).toBeVisible({ timeout: 60000 });
Expand All @@ -865,25 +864,26 @@ export async function testExportBackpage(
await expect(
newPage.getByText(tab.backpageExportButtons?.newTabMessage)
).toBeVisible();
return true;
}

/**
* Test that export access is available on entries where access shows as available
* and is not on entries where access shows as unavailable
* @param page - a Playwright page objext
* @param tab - the tab object to test on
* @returns - true if the test passes, false if the test fails but does not fail an assertion
*/
export async function testBackpageAccess(
page: Page,
tab: TabDescription
): Promise<void> {
): Promise<boolean> {
if (
tab.backpageExportButtons === undefined ||
tab.backpageAccessTags === undefined
) {
// Fail if this test is ran on a tab without defined backpages
await expect(false);
return;
// Fail if this test is run on a tab without defined backpages
return false;
}
// Goto the specified tab
await page.goto(tab.url);
Expand Down Expand Up @@ -934,6 +934,7 @@ export async function testBackpageAccess(
exact: true,
})
).toBeVisible();
return true;
}

/**
Expand Down Expand Up @@ -1064,13 +1065,19 @@ export async function testBackpageDetails(
return true;
}

export async function testIndexExportWorkflow(
/**
* Test that the Bulk Download index export workflow can be initiated and results in a download on the specified tab
* @param page - a Playwright page object
* @param tab - the tab to run the test on
* @returns - true if the test passes, false if the test fails but does not fail an assertion
*/
export async function testBulkDownloadIndexExportWorkflow(
page: Page,
tab: TabDescription
): Promise<boolean> {
if (tab?.indexExportPage === undefined) {
console.log(
"testIndexExportWorkflow Error: indexExportPage not specified for given tab, so test cannot run"
"testBulkIndexExportWorkflow Error: indexExportPage not specified for given tab, so test cannot run"
);
return false;
}
Expand All @@ -1081,7 +1088,7 @@ export async function testIndexExportWorkflow(
await expect(exportButtonLocator).toBeVisible();
await exportButtonLocator.click();
await expect(
page.getByText(tab.indexExportPage.firstLandingMessage ?? "")
page.getByText(tab.indexExportPage.requestLandingMessage ?? "")
).toBeVisible();
await expect(
page.getByRole("link", {
Expand Down Expand Up @@ -1109,18 +1116,23 @@ export async function testIndexExportWorkflow(
return true;
}

/**
* Check that the summary box on the "Choose Export Method" page has numbers that match those on the index page
* @param page - a Playwright page object
* @param tab - the tab to test on
* @returns - true if the test passes, false if it should fail but does not fail an assertion
*/
export async function testIndexExportSummary(
page: Page,
tab: TabDescription
): Promise<boolean> {
if (tab?.indexExportPage === undefined) {
console.log(
"testIndexExportDetails Error: indexExportPage not specified for given tab, so test cannot run"
"testIndexExportSummmary Error: indexExportPage not specified for given tab, so test cannot run"
);
return false;
}
await page.goto(tab.url);
//await expect(getFirstRowNthColumnCellLocator(page, 0)).toBeVisible();
const headers: { header: string; value: string }[] = [];
const indexExportButtonLocator = page.getByRole("link", {
name: tab.indexExportPage.indexExportButtonText,
Expand All @@ -1129,13 +1141,21 @@ export async function testIndexExportSummary(
for (const detail of tab.indexExportPage.detailsToCheck) {
// This Regexp gets a decimal number, some whitespace, then the name of the detail, matching how the detail box appears to Playwright.
const detailBoxRegexp = RegExp(`^([0-9]+\\.[0-9]+k)\\s*${detail}$`);
console.log(await page.getByText(detailBoxRegexp).innerText());
// This gets the detail's value. The .trim() is necessary since innertext adds extraneous whitespace on Webkit
const headerValueArray = (await page.getByText(detailBoxRegexp).innerText())
.trim()
.match(detailBoxRegexp);
// Check that the regex matches the expected format
if (headerValueArray === null || headerValueArray.length !== 2) {
console.log(
"testIndexExportSummmary Error: The detail box text does not match the expected format"
);
return false;
}
// Save the header value and detail for later comparison
headers.push({
header: detail,
value: ((await page.getByText(detailBoxRegexp).innerText())
.trim()
.match(detailBoxRegexp) ?? ["", "ERROR"])[1],
value: headerValueArray[1],
});
}
await indexExportButtonLocator.click();
Expand Down
6 changes: 2 additions & 4 deletions explorer/e2e/testInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ export interface BackpageAccessTags {
}

export interface ExportButtonInfo {
actionLandingMessage: string;
detailsName: string;
exportActionButtonText: string;
exportRequestButtonText: string;
firstLandingMessage?: string; //TODO: rename to requestLoadingMessage
firstLoadingMessage?: string;
secondLandingMessage?: string; //TODO: rename to actionLaodingMessage
secondLoadingMessage?: string;
requestLandingMessage: string;
}

export interface BackpageExportButtons extends ExportButtonInfo {
Expand Down
2 changes: 1 addition & 1 deletion explorer/e2e/testReadme.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ through the actions taken as part of the test and view the impact on the web pag
- Requires a list of the values in the sidebar to be present in `anvil-tabs.ts` and that plural labels are defined there for any columns that include n-tag cells
- Index Export (`anvil-index-export-button.spec.ts`)
- Test the "File Manifest Request" workflow works
- Runs through the export workfl.ow for "File Manifest Request" Workflow, checking that loading screens and text appear correctly on each page
- Runs through the export workflow for "File Manifest Request" workflow, checking that loading screens and text appear correctly on each page
- Checks that a download occurs when the "Download Manifest" is clicked
- Runs only on the Files tab
- Tests that the counts in the "Selected Data Summary" box match the counts on the index page
Expand Down

0 comments on commit 2629723

Please sign in to comment.