Skip to content

Commit c10699b

Browse files
committed
feat: refactored tests to make usability on other platforms better (#3626)
1 parent 2b4978e commit c10699b

File tree

9 files changed

+290
-155
lines changed

9 files changed

+290
-155
lines changed

explorer/e2e/anvil/anvil-pagination-content.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ const BackButtonTestID = "WestRoundedIcon";
55
const ForwardButtonTestID = "EastRoundedIcon";
66

77
test.setTimeout(90000);
8-
test("Check forward and backwards pagination causes the ", async ({ page }) => {
8+
test("Check forward and backwards pagination causes the page content to change", async ({
9+
page,
10+
}) => {
911
// Navigate to the BioSamples page
1012
await page.goto("/explore/biosamples");
1113
await expect(page.locator("text=Biosample Id")).toBeVisible();

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ test("Check first page has disabled back and enabled forward pagination buttons
3131
});
3232

3333
test.setTimeout(300000);
34-
test("Check that forward pagination increases the page count for the first five pages on the donors tab", async ({
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 ({
3535
page,
3636
}) => {
3737
// Should start on first page, and there should be multiple pages available
@@ -45,7 +45,6 @@ test("Check that forward pagination increases the page count for the first five
4545
const max_pages = parseInt(
4646
SplitStartingPageText[SplitStartingPageText.length - 1]
4747
);
48-
console.log(max_pages);
4948
// Paginate forwards
5049
for (let i = 2; i < max_pages + 1; i++) {
5150
await page
Lines changed: 30 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,35 @@
1-
import { expect, test } from "@playwright/test";
2-
import { anvilTabs, anvilTabTestOrder } from "./anvil-tabs";
1+
import { test } from "@playwright/test";
2+
import { testSort } from "../testFunctions";
3+
import { anvilTabs } from "./anvil-tabs";
34

4-
test.setTimeout(90000);
5-
test("Expect clicking the column header to change the first displayed entry in each column on each tab, except where all tabs have the same values", async ({
5+
test.describe.configure({ mode: "parallel" });
6+
7+
test("Expect clicking the column header to change the first displayed entry in each column on the datasets tab, except where all tabs have the same values", async ({
8+
page,
9+
}) => {
10+
await testSort(page, anvilTabs.datasets);
11+
});
12+
13+
test("Expect clicking the column header to change the first displayed entry in each column on the donors tab, except where all tabs have the same values", async ({
14+
page,
15+
}) => {
16+
await testSort(page, anvilTabs.donors);
17+
});
18+
19+
test("Expect clicking the column header to change the first displayed entry in each column on the biosamples tab, except where all tabs have the same values", async ({
20+
page,
21+
}) => {
22+
await testSort(page, anvilTabs.biosamples);
23+
});
24+
25+
test("Expect clicking the column header to change the first displayed entry in each column on the activities tab, except where all tabs have the same values", async ({
626
page,
727
}) => {
8-
// For each tab
9-
for (const tabId of anvilTabTestOrder) {
10-
// Get the current tab, and go to it's URL
11-
const tab = anvilTabs[tabId];
12-
await page.goto(tab.url);
13-
// For each column
14-
for (
15-
let columnPosition = 0;
16-
columnPosition < tab.preselectedColumns.length;
17-
columnPosition++
18-
) {
19-
// Get the column position, taking into account that some tabs start with a non-text first column
20-
if (tab.preselectedColumns[columnPosition].sortable) {
21-
const workColumnPosition: number = tab.emptyFirstColumn
22-
? columnPosition + 1
23-
: columnPosition;
24-
// Locators for the first and last cells in a particular column position on the page
25-
const firstElementTextLocator = page
26-
.getByRole("rowgroup")
27-
.nth(1)
28-
.getByRole("row")
29-
.nth(0)
30-
.getByRole("cell")
31-
.nth(workColumnPosition);
32-
const lastElementTextLocator = page
33-
.getByRole("rowgroup")
34-
.nth(1)
35-
.getByRole("row")
36-
.last()
37-
.getByRole("cell")
38-
.nth(workColumnPosition);
39-
// Locator for the sort button
40-
const columnSortLocator = page
41-
.getByRole("columnheader", {
42-
name: tab.preselectedColumns[columnPosition].name,
43-
})
44-
.getByRole("button");
45-
// Expect the first and last cells to be visible
46-
await expect(firstElementTextLocator).toBeVisible();
47-
await expect(lastElementTextLocator).toBeVisible();
48-
// Get the first cell text
49-
const firstElementTextNoClick =
50-
await firstElementTextLocator.innerText();
51-
// Sort may do nothing if the first and last element are equal, so skip testing here
52-
if (
53-
(await lastElementTextLocator.innerText()) == firstElementTextNoClick
54-
) {
55-
continue;
56-
}
57-
// Click to sort
58-
await columnSortLocator.click();
59-
await expect(firstElementTextLocator).toBeVisible();
60-
const firstElementTextFirstClick =
61-
await firstElementTextLocator.innerText();
62-
// Click again
63-
await columnSortLocator.click();
64-
// Expect the first cell to have changed after clicking sort
65-
await expect(firstElementTextLocator).toBeVisible();
66-
await expect(firstElementTextLocator).not.toHaveText(
67-
firstElementTextFirstClick
68-
);
69-
//await expect(firstElementTextLocator).toBeLessThanOrEqual( TODO: make this work, even though this function only works on numbers
70-
// firstElementTextFirstClick
71-
//);
28+
await testSort(page, anvilTabs.activities);
29+
});
7230

73-
//const newFirstElementText = await getFirstElementText(workColumnPosition);
74-
}
75-
}
76-
}
31+
test("Expect clicking the column header to change the first displayed entry in each column on the files tab, except where all tabs have the same values", async ({
32+
page,
33+
}) => {
34+
await testSort(page, anvilTabs.files);
7735
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { test } from "@playwright/test";
2+
import { testTab } from "../testFunctions";
3+
import { anvilTabs } from "./anvil-tabs";
4+
5+
test("Expect clicking the activities tab to go to the correct url and to show all of the relevant columns when selected", async ({
6+
page,
7+
}) => {
8+
const tab = anvilTabs.activities;
9+
await page.goto(anvilTabs.datasets.url);
10+
await testTab(page, tab);
11+
});
12+
13+
test("Expect clicking the datasets tab to go to the correct url and to show all of the relevant columns when selected", async ({
14+
page,
15+
}) => {
16+
const tab = anvilTabs.datasets;
17+
await page.goto(anvilTabs.activities.url);
18+
await testTab(page, tab);
19+
});
20+
21+
test("Expect clicking the files tab to go to the correct url and to show all of the relevant columns when selected", async ({
22+
page,
23+
}) => {
24+
const tab = anvilTabs.files;
25+
await page.goto(anvilTabs.datasets.url);
26+
await testTab(page, tab);
27+
});
28+
29+
test("Expect clicking the donors tab to go to the correct url and to show all of the relevant columns when selected", async ({
30+
page,
31+
}) => {
32+
const tab = anvilTabs.donors;
33+
await page.goto(anvilTabs.datasets.url);
34+
await testTab(page, tab);
35+
});
36+
37+
test("Expect clicking the biosamples tab to go to the correct url and to show all of the relevant columns when selected", async ({
38+
page,
39+
}) => {
40+
const tab = anvilTabs.biosamples;
41+
await page.goto(anvilTabs.datasets.url);
42+
await testTab(page, tab);
43+
});

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

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

explorer/e2e/anvil/anvil-tabs.ts

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,10 @@
1-
export interface tabDescription {
2-
emptyFirstColumn: boolean;
3-
preselectedColumns: columnDescription[];
4-
selectableColumns: columnDescription[];
5-
tabName: string;
6-
uniqueColumn: string;
7-
url: string;
8-
}
9-
10-
export interface tabCollection {
11-
activities: tabDescription;
12-
biosamples: tabDescription;
13-
datasets: tabDescription;
14-
donors: tabDescription;
15-
files: tabDescription;
16-
}
17-
18-
type tabCollectionKeys = keyof tabCollection;
19-
20-
export interface columnDescription {
21-
name: string;
22-
sortable: boolean;
23-
}
24-
251
/* eslint-disable sonarjs/no-duplicate-string -- ignoring duplicate strings here */
2+
import {
3+
AnvilCMGTabCollection,
4+
TabCollectionKeys,
5+
TabDescription,
6+
} from "../testInterfaces";
7+
268
export const filters: string[] = [
279
"Anatomical Site",
2810
"BioSample Type",
@@ -37,7 +19,7 @@ export const filters: string[] = [
3719
"Reported Ethnicity",
3820
];
3921

40-
export const anvilTabs: tabCollection = {
22+
export const anvilTabs: AnvilCMGTabCollection = {
4123
activities: {
4224
emptyFirstColumn: false,
4325
preselectedColumns: [
@@ -54,7 +36,6 @@ export const anvilTabs: tabCollection = {
5436
{ name: "Diagnosis", sortable: true },
5537
],
5638
tabName: "Activities",
57-
uniqueColumn: "Document Id",
5839
url: "/explore/activities",
5940
},
6041
biosamples: {
@@ -72,7 +53,6 @@ export const anvilTabs: tabCollection = {
7253
{ name: "Reported Ethnicity", sortable: true },
7354
],
7455
tabName: "BioSamples",
75-
uniqueColumn: "BioSample Id",
7656
url: "/explore/biosamples",
7757
},
7858
datasets: {
@@ -91,7 +71,6 @@ export const anvilTabs: tabCollection = {
9171
{ name: "Reported Ethnicity", sortable: true },
9272
],
9373
tabName: "Datasets",
94-
uniqueColumn: "Access",
9574
url: "/explore/datasets",
9675
},
9776
donors: {
@@ -106,7 +85,6 @@ export const anvilTabs: tabCollection = {
10685
],
10786
selectableColumns: [],
10887
tabName: "Donors",
109-
uniqueColumn: "Donor Id",
11088
url: "/explore/donors",
11189
},
11290
files: {
@@ -125,12 +103,19 @@ export const anvilTabs: tabCollection = {
125103
{ name: "Diagnosis", sortable: true },
126104
],
127105
tabName: "Files",
128-
uniqueColumn: "Name",
129106
url: "/explore/files",
130107
},
131108
};
132109

133-
export const anvilTabTestOrder: tabCollectionKeys[] = [
110+
export const anvilTabList: TabDescription[] = [
111+
anvilTabs.activities,
112+
anvilTabs.datasets,
113+
anvilTabs.biosamples,
114+
anvilTabs.donors,
115+
anvilTabs.files,
116+
];
117+
118+
export const anvilTabTestOrder: TabCollectionKeys[] = [
134119
"files",
135120
"datasets",
136121
"activities",
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { test } from "@playwright/test";
2+
import { testUrl } from "../testFunctions";
3+
import { anvilTabList, anvilTabs } from "./anvil-tabs";
4+
5+
test("Expect the activities tab to appear as selected when the corresponding url is accessed", async ({
6+
page,
7+
}) => {
8+
const tab = anvilTabs.activities;
9+
await testUrl(page, tab, anvilTabList);
10+
});
11+
12+
test("Expect the datasets tab to appear as selected when the corresponding url is accessed", async ({
13+
page,
14+
}) => {
15+
const tab = anvilTabs.datasets;
16+
await testUrl(page, tab, anvilTabList);
17+
});
18+
19+
test("Expect the files tab to appear as selected when the corresponding url is accessed", async ({
20+
page,
21+
}) => {
22+
const tab = anvilTabs.files;
23+
await testUrl(page, tab, anvilTabList);
24+
});
25+
26+
test("Expect the donors tab to appear as selected when the corresponding url is accessed", async ({
27+
page,
28+
}) => {
29+
const tab = anvilTabs.donors;
30+
await testUrl(page, tab, anvilTabList);
31+
});
32+
33+
test("Expect the biosamples tab to appear as selected when the corresponding url is accessed", async ({
34+
page,
35+
}) => {
36+
const tab = anvilTabs.biosamples;
37+
await testUrl(page, tab, anvilTabList);
38+
});

0 commit comments

Comments
 (0)