Skip to content

Commit 995aca1

Browse files
authored
AnVIL CMG E2E tests first draft (#3636)
* feat: first pass of tests for AnVIL-CMG (#3626) * feat: refactored tests to make usability on other platforms better (#3626)
1 parent 63415d9 commit 995aca1

16 files changed

+503
-246
lines changed

explorer/e2e/anvil-catalog/anvilcatalog-filters.spec.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

explorer/e2e/anvil-catalog/anvilcatalog-url.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect, test } from "@playwright/test";
22
/* eslint-disable sonarjs/no-duplicate-string -- ignoring duplicate strings here */
33

44
test("Expect workspaces url to go to workspaces tab", async ({ page }) => {
5-
await page.goto("/explore/workspaces");
5+
await page.goto("/data/workspaces");
66
await expect(
77
page.locator("_react=Tabs >> button >> text='Workspaces'")
88
).toHaveAttribute("aria-selected", "true");
@@ -12,15 +12,15 @@ test("Expect workspaces url to go to workspaces tab", async ({ page }) => {
1212
});
1313

1414
test("Expect studies url to go to studies tab", async ({ page }) => {
15-
await page.goto("/explore/studies");
15+
await page.goto("/data/studies");
1616
await expect(
1717
page.locator("_react=Tabs >> button >> text='Studies'")
1818
).toHaveAttribute("aria-selected", "true");
1919
await expect(page.locator("text='Study Design' >> nth=0")).toBeVisible();
2020
});
2121

2222
test("Expect consortia url to go to consortia tab", async ({ page }) => {
23-
await page.goto("/explore/consortia");
23+
await page.goto("/data/consortia");
2424
await expect(
2525
page.locator("_react=Tabs >> button >> text='Consortia'")
2626
).toHaveAttribute("aria-selected", "true");

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

Lines changed: 0 additions & 105 deletions
This file was deleted.
Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,58 @@
11
import { expect, test } from "@playwright/test";
22

33
const PaginationSelector = "_react=Pagination";
4-
const BackButtonSelector = "data-testid=WestRoundedIcon";
5-
const ForwardButtonSelector = "data-testid=EastRoundedIcon";
4+
const BackButtonTestID = "WestRoundedIcon";
5+
const ForwardButtonTestID = "EastRoundedIcon";
66

77
test.setTimeout(90000);
8-
test("Check forward and backwards pagination causes values to change", async ({
8+
test("Check forward and backwards pagination causes the page content to change", async ({
99
page,
1010
}) => {
1111
// Navigate to the BioSamples page
12-
await page.goto("/explore/");
13-
await page.locator("text=BioSamples").click();
14-
await expect(page).toHaveURL("/explore/biosamples", { timeout: 10000 });
12+
await page.goto("/explore/biosamples");
1513
await expect(page.locator("text=Biosample Id")).toBeVisible();
1614

17-
const TestThreePageText = await page.locator(PaginationSelector).innerText();
15+
const firstElementTextLocator = page
16+
.getByRole("rowgroup")
17+
.nth(1)
18+
.getByRole("row")
19+
.nth(0)
20+
.getByRole("cell")
21+
.nth(0);
22+
1823
// Should start on first page
1924
await expect(page.locator(PaginationSelector)).toContainText("Page 1 of ");
20-
const SplitStartingPageText = TestThreePageText.split(" ");
21-
const max_pages = parseInt(
22-
SplitStartingPageText[SplitStartingPageText.length - 1]
23-
);
24-
25+
const max_pages = 5;
2526
const FirstTableEntries = [];
2627

2728
// Paginate forwards
28-
const FirstTableEntrySelector = "_react=TableComponent >> td >> nth=0";
2929
for (let i = 2; i < max_pages + 1; i++) {
30-
const OriginalFirstTableEntry = await page
31-
.locator(FirstTableEntrySelector)
32-
.innerText();
30+
const OriginalFirstTableEntry = await firstElementTextLocator.innerText();
3331
// Click the next button
34-
await page.locator(ForwardButtonSelector).click();
32+
await page
33+
.getByRole("button")
34+
.filter({ has: page.getByTestId(ForwardButtonTestID) })
35+
.click();
3536
// Expect the page count to have incremented
3637
await expect(page.locator(PaginationSelector)).toContainText(
37-
`Page ${i} of ${max_pages}`
38+
`Page ${i} of `
3839
);
3940
// Expect the back button to be enabled
40-
await expect
41-
.soft(page.locator(BackButtonSelector).locator(".."))
42-
.toBeEnabled();
41+
await expect(
42+
page
43+
.getByRole("button")
44+
.filter({ has: page.getByTestId(BackButtonTestID) })
45+
).toBeEnabled();
4346
// Expect the forwards button to be enabled
4447
if (i != max_pages) {
4548
await expect(
46-
page.locator(ForwardButtonSelector).locator("..")
49+
page
50+
.getByRole("button")
51+
.filter({ has: page.getByTestId(ForwardButtonTestID) })
4752
).toBeEnabled();
4853
}
4954
// Expect the first entry to have changed on the new page
50-
await expect(page.locator(FirstTableEntrySelector)).not.toHaveText(
55+
await expect(firstElementTextLocator).not.toHaveText(
5156
OriginalFirstTableEntry
5257
);
5358
// Remember the first entry
@@ -57,14 +62,15 @@ test("Check forward and backwards pagination causes values to change", async ({
5762
// Paginate backwards
5863
for (let i = 0; i < max_pages - 1; i++) {
5964
const OldFirstTableEntry = FirstTableEntries[max_pages - i - 2];
60-
await page.locator(BackButtonSelector).click();
65+
await page
66+
.getByRole("button")
67+
.filter({ has: page.getByTestId(BackButtonTestID) })
68+
.click();
6169
// Expect page number to be correct
6270
await expect(page.locator(PaginationSelector)).toContainText(
63-
`Page ${max_pages - i - 1} of ${max_pages}`
71+
`Page ${max_pages - i - 1} of `
6472
);
6573
// Expect page entry to be consistent with forward pagination
66-
await expect(page.locator(FirstTableEntrySelector)).toHaveText(
67-
OldFirstTableEntry
68-
);
74+
await expect(firstElementTextLocator).toHaveText(OldFirstTableEntry);
6975
}
7076
});
Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
import { expect, test } from "@playwright/test";
2+
import { anvilTabs } from "./anvil-tabs";
23

34
const PaginationSelector = "_react=Pagination";
4-
const BackButtonSelector = "data-testid=WestRoundedIcon";
5-
const ForwardButtonSelector = "data-testid=EastRoundedIcon";
5+
const BackButtonTestID = "WestRoundedIcon";
6+
const ForwardButtonTestID = "EastRoundedIcon";
67

78
test.beforeEach(async ({ page }) => {
8-
// Navigate to the BioSamples page
9-
await page.goto("/explore/");
10-
await page.locator("text=BioSamples").click();
11-
await expect(page).toHaveURL("/explore/biosamples", { timeout: 10000 });
12-
await expect(page.locator("text=Biosample Id")).toBeVisible();
9+
// Navigate to the Donors page
10+
await page.goto(anvilTabs.donors.url);
11+
await expect(
12+
page.getByRole("tab").getByText(anvilTabs.donors.tabName)
13+
).toBeVisible();
1314
});
1415

15-
test("Check first page has correct buttons", async ({ page }) => {
16+
test("Check first page has disabled back and enabled forward pagination buttons on Donors Page", async ({
17+
page,
18+
}) => {
1619
// Should start on first page
1720
await expect(page.locator(PaginationSelector)).toContainText("Page 1 of ");
1821
// Back Button should start disabled
19-
await expect(page.locator(BackButtonSelector).locator("..")).toBeDisabled();
22+
await expect(
23+
page.getByRole("button").filter({ has: page.getByTestId(BackButtonTestID) })
24+
).toBeDisabled();
2025
// Forward button should start enabled
21-
await expect(page.locator(ForwardButtonSelector).locator("..")).toBeEnabled();
26+
await expect(
27+
page
28+
.getByRole("button")
29+
.filter({ has: page.getByTestId(ForwardButtonTestID) })
30+
).toBeEnabled();
2231
});
2332

24-
test("Check last page has correct buttons and that forward pagination increases the page count", async ({
33+
test.setTimeout(300000);
34+
test("Check that forward pagination increments the current page and that page count stays static for the first five pages on the donors tab", async ({
2535
page,
2636
}) => {
2737
// Should start on first page, and there should be multiple pages available
@@ -37,7 +47,10 @@ test("Check last page has correct buttons and that forward pagination increases
3747
);
3848
// Paginate forwards
3949
for (let i = 2; i < max_pages + 1; i++) {
40-
await page.locator(ForwardButtonSelector).click();
50+
await page
51+
.getByRole("button")
52+
.filter({ has: page.getByTestId(ForwardButtonTestID) })
53+
.click();
4154
// Expect the page count to have incremented
4255
await expect(page.locator(PaginationSelector)).toContainText(
4356
`Page ${i} of ${max_pages}`
@@ -48,11 +61,13 @@ test("Check last page has correct buttons and that forward pagination increases
4861
`Page ${max_pages} of ${max_pages}`
4962
);
5063
// Expect the back button to be enabled on the last page
51-
await expect
52-
.soft(page.locator(BackButtonSelector).locator(".."))
53-
.toBeEnabled();
64+
await expect(
65+
page.getByRole("button").filter({ has: page.getByTestId(BackButtonTestID) })
66+
).toBeEnabled();
5467
// Expect the forward button to be disabled
55-
await expect
56-
.soft(page.locator(ForwardButtonSelector).locator(".."))
57-
.toBeDisabled();
68+
await expect(
69+
page
70+
.getByRole("button")
71+
.filter({ has: page.getByTestId(ForwardButtonTestID) })
72+
).toBeDisabled();
5873
});

0 commit comments

Comments
 (0)