Skip to content

Commit

Permalink
feat: first draft of anvil-cmg filter tests (#4068)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpaten committed Jul 15, 2024
1 parent e96174c commit 2927d01
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 2 deletions.
103 changes: 103 additions & 0 deletions explorer/e2e/anvil/anvil-filters.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { expect, test } from "@playwright/test";
import { testFilterPresence } from "../testFunctions";
import { anvilFilters, anvilTabs, anvilTabTestOrder } from "./anvil-tabs";

test.describe.configure({ mode: "parallel" });

const filter_regex = (filter: string): RegExp =>
new RegExp(filter + "\\s+\\([0-9]+\\)\\s*");

test("Check that all filters exist on the Datasets tab and are clickable", async ({
page,
}) => {
await testFilterPresence(page, anvilTabs.datasets);
});

test("Check that all filters exist on the Donors tab and are clickable", async ({
page,
}) => {
await testFilterPresence(page, anvilTabs.donors);
});

test("Check that all filters exist on the BioSamples tab and are clickable", async ({
page,
}) => {
await testFilterPresence(page, anvilTabs.biosamples);
});

test("Check that all filters exist on the Activities tab and are clickable", async ({
page,
}) => {
await testFilterPresence(page, anvilTabs.activities);
});

test("Check that all filters exist on the Files tab and are clickable", async ({
page,
}) => {
await testFilterPresence(page, anvilTabs.files);
});

test("Check that the first filter on the Datasets tab creates at least one checkbox, and that checking up to the first five does not cause an error and does not cause there to be no entries in the table", async ({
page,
}) => {
// Goto the datasets tab
await page.goto(anvilTabs.datasets.url);
await expect(
page.getByRole("tab").getByText(anvilTabs.datasets.tabName)
).toBeVisible();

// Select a filter
await page
.getByRole("button")
.getByText(filter_regex(anvilFilters[4]))
.click();
// Expect all checkboxes to be unchecked initially and to work properly
await expect(page.getByRole("checkbox").first()).toBeVisible();
const all_checkboxes = await page.getByRole("checkbox").all();
for (let i = 0; i < all_checkboxes.length && i < 5; i++) {
const checkbox = all_checkboxes[i];
await checkbox.scrollIntoViewIfNeeded();
await expect(checkbox).not.toBeChecked();
await checkbox.click();
await expect(checkbox).toBeChecked();
}
await page.locator("body").click();
const firstElementTextLocator = page
.getByRole("rowgroup")
.nth(1)
.getByRole("row")
.nth(0)
.getByRole("cell")
.first();
await expect(firstElementTextLocator).toBeVisible();
});

test("Check that filter checkboxes are persistent across pages", async ({
page,
}) => {
await page.goto(anvilTabs.datasets.url);
await expect(
page.getByRole("tab").getByText(anvilTabs.datasets.tabName)
).toBeVisible();
await page.getByText(filter_regex(anvilFilters[3])).click(); // maybe should select a random one instead;
await expect(page.getByRole("checkbox").first()).not.toBeChecked();
await page.getByRole("checkbox").first().click();
await expect(page.getByRole("checkbox").first()).toBeChecked();
await page.locator("body").click();
for (const blah of anvilTabTestOrder) {
console.log(blah);
await page.getByRole("tab").getByText(anvilTabs[blah].tabName).click();
const firstElementTextLocator = page
.getByRole("rowgroup")
.nth(1)
.getByRole("row")
.nth(0)
.getByRole("cell")
.first();
await expect(firstElementTextLocator).toBeVisible();
await expect(page.getByText(filter_regex(anvilFilters[3]))).toBeVisible();
await page.getByText(filter_regex(anvilFilters[3])).click();
await expect(page.getByRole("checkbox").first()).toBeChecked();
await page.locator("body").click();
}
});
2 changes: 1 addition & 1 deletion explorer/e2e/anvil/anvil-tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
TabDescription,
} from "../testInterfaces";

export const filters: string[] = [
export const anvilFilters: string[] = [
"Anatomical Site",
"BioSample Type",
"Consent Group",
Expand Down
42 changes: 41 additions & 1 deletion explorer/e2e/testFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import { expect, Page } from "@playwright/test";
import { expect, Locator, Page } from "@playwright/test";
import { anvilFilters, anvilTabs, anvilTabTestOrder } from "./anvil/anvil-tabs";
import { TabDescription } from "./testInterfaces";

/* eslint-disable sonarjs/no-duplicate-string -- ignoring duplicate strings here */
// Run the "Expect each tab to appear as selected when the corresponding url is accessed" test

const getFirstElementTextLocator = (
page: Page,
workColumnPosition: number
): Locator => {
return page
.getByRole("rowgroup")
.nth(1)
.getByRole("row")
.nth(0)
.getByRole("cell")
.nth(workColumnPosition);
};

export async function testUrl(
page: Page,
tab: TabDescription,
Expand Down Expand Up @@ -207,4 +222,29 @@ export async function testPreSelectedColumns(
}
}

const filter_regex = (filter: string): RegExp =>
new RegExp(filter + "\\s+\\([0-9]+\\)\\s*");

export async function testFilterPresence(
page: Page,
tab: TabDescription
): Promise<void> {
await page.goto(tab.url);
await expect(page.getByRole("tab").getByText(tab.tabName)).toBeVisible();
await page.getByText(filter_regex(anvilFilters[3])).click(); // maybe should select a random one instead;
await expect(page.getByRole("checkbox").first()).not.toBeChecked();
await page.getByRole("checkbox").first().click();
await expect(page.getByRole("checkbox").first()).toBeChecked();
await page.locator("body").click();
for (const blah of anvilTabTestOrder) {
console.log(blah);
await page.getByRole("tab").getByText(anvilTabs[blah].tabName).click();
await expect(getFirstElementTextLocator(page, 0)).toBeVisible();
await expect(page.getByText(filter_regex(anvilFilters[3]))).toBeVisible();
await page.getByText(filter_regex(anvilFilters[3])).click();
await expect(page.getByRole("checkbox").first()).toBeChecked();
await page.locator("body").click();
}
}

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

0 comments on commit 2927d01

Please sign in to comment.