Skip to content

Commit 30f489c

Browse files
committed
fix: refactored locators and cleaned up typos in tests (#4078)
1 parent ac63c9d commit 30f489c

File tree

4 files changed

+68
-65
lines changed

4 files changed

+68
-65
lines changed

explorer/e2e/anvil-catalog/anvilcatalog-tabs-buttons.spec.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,17 @@ import { anvilcatalogTabs } from "./anvilcatalog-tabs";
55
test("Expect clicking the consortia tab to go to the correct url and to show all of the relevant columns when selected", async ({
66
page,
77
}) => {
8-
const tab = anvilcatalogTabs.consortia;
9-
await page.goto(anvilcatalogTabs.studies.url);
10-
await testTab(page, tab);
8+
await testTab(page, anvilcatalogTabs.studies, anvilcatalogTabs.consortia);
119
});
1210

1311
test("Expect clicking the studies tab to go to the correct url and to show all of the relevant columns when selected", async ({
1412
page,
1513
}) => {
16-
const tab = anvilcatalogTabs.studies;
17-
await page.goto(anvilcatalogTabs.consortia.url);
18-
await testTab(page, tab);
14+
await testTab(page, anvilcatalogTabs.workspaces, anvilcatalogTabs.studies);
1915
});
2016

2117
test("Expect clicking the workspaces tab to go to the correct url and to show all of the relevant columns when selected", async ({
2218
page,
2319
}) => {
24-
const tab = anvilcatalogTabs.workspaces;
25-
await page.goto(anvilcatalogTabs.workspaces.url);
26-
await testTab(page, tab);
20+
await testTab(page, anvilcatalogTabs.consortia, anvilcatalogTabs.workspaces);
2721
});

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect, test } from "@playwright/test";
2+
import { getFirstElementTextLocator } from "../testFunctions";
23
import { anvilTabs } from "./anvil-tabs";
34

45
const pageCountRegex = /Page [0-9]+ of [0-9]+/;
@@ -16,13 +17,7 @@ test("Check forward and backwards pagination causes the page content to change o
1617
page.getByRole("tab").getByText(tab.tabName, { exact: true })
1718
).toHaveAttribute("aria-selected", "true", { timeout: 25000 });
1819

19-
const firstElementTextLocator = page
20-
.getByRole("rowgroup")
21-
.nth(1)
22-
.getByRole("row")
23-
.nth(0)
24-
.getByRole("cell")
25-
.nth(0);
20+
const firstElementTextLocator = getFirstElementTextLocator(page, 0);
2621

2722
// Should start on first page
2823
await expect(page.getByText(pageCountRegex, { exact: true })).toHaveText(

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,29 @@ import { anvilTabs } from "./anvil-tabs";
55
test("Expect clicking the activities tab to go to the correct url and to show all of the relevant columns when selected", async ({
66
page,
77
}) => {
8-
const tab = anvilTabs.activities;
9-
await page.goto(anvilTabs.datasets.url);
10-
await testTab(page, tab);
8+
await testTab(page, anvilTabs.datasets, anvilTabs.activities);
119
});
1210

1311
test("Expect clicking the datasets tab to go to the correct url and to show all of the relevant columns when selected", async ({
1412
page,
1513
}) => {
16-
const tab = anvilTabs.datasets;
17-
await page.goto(anvilTabs.activities.url);
18-
await testTab(page, tab);
14+
await testTab(page, anvilTabs.activities, anvilTabs.datasets);
1915
});
2016

2117
test("Expect clicking the files tab to go to the correct url and to show all of the relevant columns when selected", async ({
2218
page,
2319
}) => {
24-
const tab = anvilTabs.files;
25-
await page.goto(anvilTabs.datasets.url);
26-
await testTab(page, tab);
20+
await testTab(page, anvilTabs.datasets, anvilTabs.files);
2721
});
2822

2923
test("Expect clicking the donors tab to go to the correct url and to show all of the relevant columns when selected", async ({
3024
page,
3125
}) => {
32-
const tab = anvilTabs.donors;
33-
await page.goto(anvilTabs.datasets.url);
34-
await testTab(page, tab);
26+
await testTab(page, anvilTabs.datasets, anvilTabs.donors);
3527
});
3628

3729
test("Expect clicking the biosamples tab to go to the correct url and to show all of the relevant columns when selected", async ({
3830
page,
3931
}) => {
40-
const tab = anvilTabs.biosamples;
41-
await page.goto(anvilTabs.datasets.url);
42-
await testTab(page, tab);
32+
await testTab(page, anvilTabs.datasets, anvilTabs.biosamples);
4333
});

explorer/e2e/testFunctions.ts

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,47 @@ import { expect, Locator, Page } from "@playwright/test";
22
import { TabDescription } from "./testInterfaces";
33

44
/* eslint-disable sonarjs/no-duplicate-string -- ignoring duplicate strings here */
5-
// Run the "Expect each tab to appear as selected when the corresponding url is accessed" test
5+
6+
export const getNthElementTextLocator = (
7+
page: Page,
8+
row_position: number,
9+
column_position: number
10+
): Locator => {
11+
return page
12+
.getByRole("rowgroup")
13+
.nth(1)
14+
.getByRole("row")
15+
.nth(row_position)
16+
.getByRole("cell")
17+
.nth(column_position);
18+
};
619

720
export const getFirstElementTextLocator = (
821
page: Page,
9-
workColumnPosition: number
22+
column_position: number
23+
): Locator => getNthElementTextLocator(page, 0, column_position);
24+
25+
export const getLastElementTextLocator = (
26+
page: Page,
27+
column_position: number
1028
): Locator => {
1129
return page
1230
.getByRole("rowgroup")
1331
.nth(1)
1432
.getByRole("row")
15-
.nth(0)
33+
.last()
1634
.getByRole("cell")
17-
.nth(workColumnPosition);
35+
.nth(column_position);
1836
};
1937

2038
export async function testUrl(
2139
page: Page,
2240
tab: TabDescription,
2341
otherTabs: TabDescription[]
2442
): Promise<void> {
43+
// Go to the selected tab
2544
await page.goto(tab.url);
45+
// Check that the selected tab appears selected and the other tabs appear deselected
2646
await expect(
2747
page.getByRole("tab").getByText(tab.tabName, { exact: true })
2848
).toHaveAttribute("aria-selected", "true", { timeout: 25000 });
@@ -35,30 +55,30 @@ export async function testUrl(
3555
}
3656
}
3757

38-
// Run the "Expect each tab to become selected, to go to the correct url, and to show all of its columns when selected" test
39-
export async function testTab(page: Page, tab: TabDescription): Promise<void> {
40-
await expect(
41-
page
42-
.getByRole("rowgroup")
43-
.nth(1)
44-
.getByRole("row")
45-
.nth(1)
46-
.getByRole("cell")
47-
.nth(1)
48-
).toBeVisible();
49-
await page.getByRole("tab").getByText(tab.tabName, { exact: true }).click();
50-
await expect(page).toHaveURL(tab.url, { timeout: 25000 }); // Long timeout because some tabs take a long time to load
51-
await expect(page.getByRole("tab").getByText(tab.tabName)).toHaveAttribute(
58+
export async function testTab(
59+
page: Page,
60+
startTab: TabDescription,
61+
endTab: TabDescription
62+
): Promise<void> {
63+
// Run the "Expect each tab to become selected, to go to the correct url, and to show all of its columns when selected" test
64+
await page.goto(startTab.url);
65+
await expect(getFirstElementTextLocator(page, 1)).toBeVisible();
66+
await page
67+
.getByRole("tab")
68+
.getByText(endTab.tabName, { exact: true })
69+
.click();
70+
await expect(page).toHaveURL(endTab.url, { timeout: 25000 }); // Long timeout because some tabs take a long time to load
71+
await expect(page.getByRole("tab").getByText(endTab.tabName)).toHaveAttribute(
5272
"aria-selected",
5373
"true"
5474
);
55-
if (tab.emptyFirstColumn) {
75+
if (endTab.emptyFirstColumn) {
5676
await expect(page.getByRole("columnheader")).toHaveText(
57-
[" "].concat(tab.preselectedColumns.map((x) => x.name))
77+
[" "].concat(endTab.preselectedColumns.map((x) => x.name))
5878
);
5979
} else {
6080
await expect(page.getByRole("columnheader")).toHaveText(
61-
tab.preselectedColumns.map((x) => x.name)
81+
endTab.preselectedColumns.map((x) => x.name)
6282
);
6383
}
6484
}
@@ -85,21 +105,17 @@ export async function testSortAzul(
85105
page,
86106
workColumnPosition
87107
);
88-
const lastElementTextLocator = page
89-
.getByRole("rowgroup")
90-
.nth(1)
91-
.getByRole("row")
92-
.last()
93-
.getByRole("cell")
94-
.nth(workColumnPosition);
95-
// Locator for the sort buttonf
108+
const lastElementTextLocator = getLastElementTextLocator(
109+
page,
110+
workColumnPosition
111+
);
112+
// Locator for the sort button
96113
const columnSortLocator = page
97114
.getByRole("columnheader", {
98115
exact: true,
99116
name: tab.preselectedColumns[columnPosition].name,
100117
})
101118
.getByRole("button");
102-
103119
// Expect the first and last cells to be visible and have text
104120
await expect(firstElementTextLocator).toBeVisible();
105121
await expect(lastElementTextLocator).toBeVisible();
@@ -125,7 +141,6 @@ export async function testSortCatalog(
125141
): Promise<void> {
126142
// Get the current tab, and go to it's URL
127143
await page.goto(tab.url);
128-
// For each column
129144
for (
130145
let columnPosition = 0;
131146
columnPosition < tab.preselectedColumns.length;
@@ -148,9 +163,7 @@ export async function testSortCatalog(
148163
name: tab.preselectedColumns[columnPosition].name,
149164
})
150165
.getByRole("button");
151-
152166
await expect(firstElementTextLocator).toBeVisible();
153-
154167
// Click to sort
155168
await columnSortLocator.click();
156169
// Expect the first and cells to still be visible
@@ -168,10 +181,14 @@ export async function testSelectableColumns(
168181
page: Page,
169182
tab: TabDescription
170183
): Promise<void> {
184+
// Navigate to the tab
171185
await page.goto(tab.url);
186+
// Select the "Edit Columns" menu
172187
await page.getByRole("button").getByText("Edit Columns").click();
173188
await expect(page.getByRole("menu")).toBeVisible();
189+
// Enable each selectable tab
174190
for (const column of tab.selectableColumns) {
191+
// Locate the checkbox for each column
175192
const checkboxLocator = page
176193
.getByRole("menu")
177194
.locator("*")
@@ -181,13 +198,16 @@ export async function testSelectableColumns(
181198
.filter({ has: page.getByText(column.name, { exact: true }) }),
182199
})
183200
.getByRole("checkbox");
201+
// Expect each column to be enabled and unchecked for selectable tabs
184202
await expect(checkboxLocator).toBeEnabled();
185203
await expect(checkboxLocator).not.toBeChecked();
204+
// Expect clicking the checkbox to function
186205
await checkboxLocator.click();
187206
await expect(checkboxLocator).toBeChecked();
188207
}
189208
await page.getByRole("document").click();
190209
await expect(page.getByRole("menu")).not.toBeVisible();
210+
// Expect all selectable tabs to be enabled
191211
await expect(page.getByRole("columnheader")).toContainText(
192212
tab.selectableColumns.map((x) => x.name)
193213
);
@@ -246,6 +266,7 @@ export const getNamedFilterButton = (
246266
.getByRole("button")
247267
.filter({ has: page.getByRole("checkbox"), hasText: filterName });
248268
};
269+
249270
export const getFirstFilterButton = (page: Page): Locator => {
250271
return page
251272
.getByRole("button")
@@ -341,7 +362,7 @@ export async function testFilterBubbles(
341362
tab: TabDescription,
342363
filters: string[]
343364
): Promise<void> {
344-
page.goto(tab.url);
365+
await page.goto(tab.url);
345366
for (const filter of filters) {
346367
// Select a filter
347368
await page.getByText(filterRegex(filter)).dispatchEvent("click");
@@ -380,6 +401,7 @@ export async function testClearAll(
380401
): Promise<void> {
381402
await page.goto(tab.url);
382403
const selected_filter_list = [];
404+
// Select each filter and get the names of the actual filter text
383405
for (const filter of filters) {
384406
await page.getByText(filterRegex(filter)).dispatchEvent("click");
385407
await getFirstFilterButton(page).getByRole("checkbox").click();
@@ -393,12 +415,14 @@ export async function testClearAll(
393415
);
394416
await page.locator("body").click();
395417
}
418+
// Click the clear all button
396419
await page.getByText("Clear All").dispatchEvent("click");
397420
for (const filter of selected_filter_list) {
398421
await expect(
399422
page.locator("#sidebar-positioner").getByText(filter)
400423
).toHaveCount(0);
401424
}
425+
// Ensure that the filters still show as unchecked
402426
for (let i = 0; i < filters.length; i++) {
403427
await page.getByText(filterRegex(filters[i])).dispatchEvent("click");
404428
await expect(

0 commit comments

Comments
 (0)