Skip to content

Commit 2927d01

Browse files
committed
feat: first draft of anvil-cmg filter tests (#4068)
1 parent e96174c commit 2927d01

File tree

3 files changed

+145
-2
lines changed

3 files changed

+145
-2
lines changed
+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { expect, test } from "@playwright/test";
2+
import { testFilterPresence } from "../testFunctions";
3+
import { anvilFilters, anvilTabs, anvilTabTestOrder } from "./anvil-tabs";
4+
5+
test.describe.configure({ mode: "parallel" });
6+
7+
const filter_regex = (filter: string): RegExp =>
8+
new RegExp(filter + "\\s+\\([0-9]+\\)\\s*");
9+
10+
test("Check that all filters exist on the Datasets tab and are clickable", async ({
11+
page,
12+
}) => {
13+
await testFilterPresence(page, anvilTabs.datasets);
14+
});
15+
16+
test("Check that all filters exist on the Donors tab and are clickable", async ({
17+
page,
18+
}) => {
19+
await testFilterPresence(page, anvilTabs.donors);
20+
});
21+
22+
test("Check that all filters exist on the BioSamples tab and are clickable", async ({
23+
page,
24+
}) => {
25+
await testFilterPresence(page, anvilTabs.biosamples);
26+
});
27+
28+
test("Check that all filters exist on the Activities tab and are clickable", async ({
29+
page,
30+
}) => {
31+
await testFilterPresence(page, anvilTabs.activities);
32+
});
33+
34+
test("Check that all filters exist on the Files tab and are clickable", async ({
35+
page,
36+
}) => {
37+
await testFilterPresence(page, anvilTabs.files);
38+
});
39+
40+
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 ({
41+
page,
42+
}) => {
43+
// Goto the datasets tab
44+
await page.goto(anvilTabs.datasets.url);
45+
await expect(
46+
page.getByRole("tab").getByText(anvilTabs.datasets.tabName)
47+
).toBeVisible();
48+
49+
// Select a filter
50+
await page
51+
.getByRole("button")
52+
.getByText(filter_regex(anvilFilters[4]))
53+
.click();
54+
// Expect all checkboxes to be unchecked initially and to work properly
55+
await expect(page.getByRole("checkbox").first()).toBeVisible();
56+
const all_checkboxes = await page.getByRole("checkbox").all();
57+
for (let i = 0; i < all_checkboxes.length && i < 5; i++) {
58+
const checkbox = all_checkboxes[i];
59+
await checkbox.scrollIntoViewIfNeeded();
60+
await expect(checkbox).not.toBeChecked();
61+
await checkbox.click();
62+
await expect(checkbox).toBeChecked();
63+
}
64+
await page.locator("body").click();
65+
const firstElementTextLocator = page
66+
.getByRole("rowgroup")
67+
.nth(1)
68+
.getByRole("row")
69+
.nth(0)
70+
.getByRole("cell")
71+
.first();
72+
await expect(firstElementTextLocator).toBeVisible();
73+
});
74+
75+
test("Check that filter checkboxes are persistent across pages", async ({
76+
page,
77+
}) => {
78+
await page.goto(anvilTabs.datasets.url);
79+
await expect(
80+
page.getByRole("tab").getByText(anvilTabs.datasets.tabName)
81+
).toBeVisible();
82+
await page.getByText(filter_regex(anvilFilters[3])).click(); // maybe should select a random one instead;
83+
await expect(page.getByRole("checkbox").first()).not.toBeChecked();
84+
await page.getByRole("checkbox").first().click();
85+
await expect(page.getByRole("checkbox").first()).toBeChecked();
86+
await page.locator("body").click();
87+
for (const blah of anvilTabTestOrder) {
88+
console.log(blah);
89+
await page.getByRole("tab").getByText(anvilTabs[blah].tabName).click();
90+
const firstElementTextLocator = page
91+
.getByRole("rowgroup")
92+
.nth(1)
93+
.getByRole("row")
94+
.nth(0)
95+
.getByRole("cell")
96+
.first();
97+
await expect(firstElementTextLocator).toBeVisible();
98+
await expect(page.getByText(filter_regex(anvilFilters[3]))).toBeVisible();
99+
await page.getByText(filter_regex(anvilFilters[3])).click();
100+
await expect(page.getByRole("checkbox").first()).toBeChecked();
101+
await page.locator("body").click();
102+
}
103+
});

explorer/e2e/anvil/anvil-tabs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
TabDescription,
66
} from "../testInterfaces";
77

8-
export const filters: string[] = [
8+
export const anvilFilters: string[] = [
99
"Anatomical Site",
1010
"BioSample Type",
1111
"Consent Group",

explorer/e2e/testFunctions.ts

+41-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1-
import { expect, Page } from "@playwright/test";
1+
import { expect, Locator, Page } from "@playwright/test";
2+
import { anvilFilters, anvilTabs, anvilTabTestOrder } from "./anvil/anvil-tabs";
23
import { TabDescription } from "./testInterfaces";
34

45
/* eslint-disable sonarjs/no-duplicate-string -- ignoring duplicate strings here */
56
// Run the "Expect each tab to appear as selected when the corresponding url is accessed" test
7+
8+
const getFirstElementTextLocator = (
9+
page: Page,
10+
workColumnPosition: number
11+
): Locator => {
12+
return page
13+
.getByRole("rowgroup")
14+
.nth(1)
15+
.getByRole("row")
16+
.nth(0)
17+
.getByRole("cell")
18+
.nth(workColumnPosition);
19+
};
20+
621
export async function testUrl(
722
page: Page,
823
tab: TabDescription,
@@ -207,4 +222,29 @@ export async function testPreSelectedColumns(
207222
}
208223
}
209224

225+
const filter_regex = (filter: string): RegExp =>
226+
new RegExp(filter + "\\s+\\([0-9]+\\)\\s*");
227+
228+
export async function testFilterPresence(
229+
page: Page,
230+
tab: TabDescription
231+
): Promise<void> {
232+
await page.goto(tab.url);
233+
await expect(page.getByRole("tab").getByText(tab.tabName)).toBeVisible();
234+
await page.getByText(filter_regex(anvilFilters[3])).click(); // maybe should select a random one instead;
235+
await expect(page.getByRole("checkbox").first()).not.toBeChecked();
236+
await page.getByRole("checkbox").first().click();
237+
await expect(page.getByRole("checkbox").first()).toBeChecked();
238+
await page.locator("body").click();
239+
for (const blah of anvilTabTestOrder) {
240+
console.log(blah);
241+
await page.getByRole("tab").getByText(anvilTabs[blah].tabName).click();
242+
await expect(getFirstElementTextLocator(page, 0)).toBeVisible();
243+
await expect(page.getByText(filter_regex(anvilFilters[3]))).toBeVisible();
244+
await page.getByText(filter_regex(anvilFilters[3])).click();
245+
await expect(page.getByRole("checkbox").first()).toBeChecked();
246+
await page.locator("body").click();
247+
}
248+
}
249+
210250
/* eslint-enable sonarjs/no-duplicate-string -- Checking duplicate strings again*/

0 commit comments

Comments
 (0)