Skip to content

Commit f3dbd5f

Browse files
committed
fix: refactored locators and cleaned up typos in tests (#4078)
1 parent 072cd80 commit f3dbd5f

File tree

3 files changed

+62
-48
lines changed

3 files changed

+62
-48
lines changed

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

+3-9
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.workspaces.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.consortia.url);
26-
await testTab(page, tab);
20+
await testTab(page, anvilcatalogTabs.consortia, anvilcatalogTabs.workspaces);
2721
});

Diff for: explorer/e2e/anvil/anvil-tabs-buttons.spec.ts

+5-10
Original file line numberDiff line numberDiff line change
@@ -5,34 +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-
await page.goto(anvilTabs.activities.url);
9-
await testTab(page, anvilTabs.datasets);
8+
`` await testTab(page, anvilTabs.datasets, anvilTabs.activities);
109
});
1110

1211
test("Expect clicking the datasets tab to go to the correct url and to show all of the relevant columns when selected", async ({
1312
page,
1413
}) => {
15-
await page.goto(anvilTabs.datasets.url);
16-
await testTab(page, anvilTabs.activities);
14+
await testTab(page, anvilTabs.activities, anvilTabs.datasets);
1715
});
1816

1917
test("Expect clicking the files tab to go to the correct url and to show all of the relevant columns when selected", async ({
2018
page,
2119
}) => {
22-
await page.goto(anvilTabs.datasets.url);
23-
await testTab(page, anvilTabs.files);
20+
await testTab(page, anvilTabs.datasets, anvilTabs.files);
2421
});
2522

2623
test("Expect clicking the donors tab to go to the correct url and to show all of the relevant columns when selected", async ({
2724
page,
2825
}) => {
29-
await page.goto(anvilTabs.datasets.url);
30-
await testTab(page, anvilTabs.donors);
26+
await testTab(page, anvilTabs.datasets, anvilTabs.donors);
3127
});
3228

3329
test("Expect clicking the biosamples tab to go to the correct url and to show all of the relevant columns when selected", async ({
3430
page,
3531
}) => {
36-
await page.goto(anvilTabs.datasets.url);
37-
await testTab(page, anvilTabs.datasets);
32+
await testTab(page, anvilTabs.datasets, anvilTabs.biosamples);
3833
});

Diff for: explorer/e2e/testFunctions.ts

+54-29
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ export const getFirstRowNthColumnCellLocator = (
4141
return getMthRowNthColumnCellLocator(page, 0, columnIndex);
4242
};
4343

44+
/**
45+
* Get a locator to the cell in the first row's nth column
46+
* @param page - a Playwright page object
47+
* @param columnIndex - the zero-indexed column to return
48+
* @returns a Playwright locator object to the selected cell
49+
**/
50+
export const getLastRowNthColumnTextLocator = (
51+
page: Page,
52+
columnIndex: number
53+
): Locator => {
54+
return page
55+
.getByRole("rowgroup")
56+
.nth(1)
57+
.getByRole("row")
58+
.last()
59+
.getByRole("cell")
60+
.nth(columnIndex);
61+
};
62+
4463
/**
4564
* Tests that the tab url goes to a valid page and that the correct tab (and only
4665
* the correct tab) appears selected
@@ -53,7 +72,9 @@ export async function testUrl(
5372
tab: TabDescription,
5473
otherTabs: TabDescription[]
5574
): Promise<void> {
75+
// Go to the selected tab
5676
await page.goto(tab.url);
77+
// Check that the selected tab appears selected and the other tabs appear deselected
5778
await expect(
5879
page.getByRole("tab").getByText(tab.tabName, { exact: true })
5980
).toHaveAttribute("aria-selected", "true", { timeout: 25000 });
@@ -66,35 +87,36 @@ export async function testUrl(
6687
}
6788
}
6889

69-
// Run the "Expect each tab to become selected, to go to the correct url, and to show all of its columns when selected" test
7090
/**
7191
* Checks that all preselected columns listed in the tab object are visible in the correct order
7292
* @param page - a Playwright page object
73-
* @param tab - the tab object to test
93+
* @param startTab - the tab object to start testing on
94+
* @param endTab - the tab to select during the test
7495
*/
75-
export async function testTab(page: Page, tab: TabDescription): Promise<void> {
76-
await expect(
77-
page
78-
.getByRole("rowgroup")
79-
.nth(1)
80-
.getByRole("row")
81-
.nth(1)
82-
.getByRole("cell")
83-
.nth(1)
84-
).toBeVisible();
85-
await page.getByRole("tab").getByText(tab.tabName, { exact: true }).click();
86-
await expect(page).toHaveURL(tab.url, { timeout: 25000 }); // Long timeout because some tabs take a long time to load
87-
await expect(page.getByRole("tab").getByText(tab.tabName)).toHaveAttribute(
96+
export async function testTab(
97+
page: Page,
98+
startTab: TabDescription,
99+
endTab: TabDescription
100+
): Promise<void> {
101+
// Run the "Expect each tab to become selected, to go to the correct url, and to show all of its columns when selected" test
102+
await page.goto(startTab.url);
103+
await expect(getFirstRowNthColumnCellLocator(page, 1)).toBeVisible();
104+
await page
105+
.getByRole("tab")
106+
.getByText(endTab.tabName, { exact: true })
107+
.click();
108+
await expect(page).toHaveURL(endTab.url, { timeout: 25000 }); // Long timeout because some tabs take a long time to load
109+
await expect(page.getByRole("tab").getByText(endTab.tabName)).toHaveAttribute(
88110
"aria-selected",
89111
"true"
90112
);
91-
if (tab.emptyFirstColumn) {
113+
if (endTab.emptyFirstColumn) {
92114
await expect(page.getByRole("columnheader")).toHaveText(
93-
[" "].concat(tab.preselectedColumns.map((x) => x.name))
115+
[" "].concat(endTab.preselectedColumns.map((x) => x.name))
94116
);
95117
} else {
96118
await expect(page.getByRole("columnheader")).toHaveText(
97-
tab.preselectedColumns.map((x) => x.name)
119+
endTab.preselectedColumns.map((x) => x.name)
98120
);
99121
}
100122
}
@@ -129,21 +151,17 @@ export async function testSortAzul(
129151
page,
130152
columnIndex
131153
);
132-
const lastElementTextLocator = page
133-
.getByRole("rowgroup")
134-
.nth(1)
135-
.getByRole("row")
136-
.last()
137-
.getByRole("cell")
138-
.nth(columnIndex);
139-
// Locator for the sort button for the tab
154+
const lastElementTextLocator = getLastRowNthColumnTextLocator(
155+
page,
156+
columnIndex
157+
);
158+
// Locator for the sort button
140159
const columnSortLocator = page
141160
.getByRole("columnheader", {
142161
exact: true,
143162
name: tab.preselectedColumns[columnPosition].name,
144163
})
145164
.getByRole("button");
146-
147165
// Expect the first and last cells to be visible and have text
148166
await expect(firstElementTextLocator).toBeVisible();
149167
await expect(lastElementTextLocator).toBeVisible();
@@ -177,7 +195,6 @@ export async function testSortCatalog(
177195
): Promise<void> {
178196
// Get the current tab, and go to it's URL
179197
await page.goto(tab.url);
180-
// For each column
181198
for (
182199
let columnPosition = 0;
183200
columnPosition < tab.preselectedColumns.length;
@@ -225,10 +242,14 @@ export async function testSelectableColumns(
225242
page: Page,
226243
tab: TabDescription
227244
): Promise<void> {
245+
// Navigate to the tab
228246
await page.goto(tab.url);
247+
// Select the "Edit Columns" menu
229248
await page.getByRole("button").getByText("Edit Columns").click();
230249
await expect(page.getByRole("menu")).toBeVisible();
250+
// Enable each selectable tab
231251
for (const column of tab.selectableColumns) {
252+
// Locate the checkbox for each column
232253
const checkboxLocator = page
233254
.getByRole("menu")
234255
.locator("*")
@@ -238,13 +259,16 @@ export async function testSelectableColumns(
238259
.filter({ has: page.getByText(column.name, { exact: true }) }),
239260
})
240261
.getByRole("checkbox");
262+
// Expect each column to be enabled and unchecked for selectable tabs
241263
await expect(checkboxLocator).toBeEnabled();
242264
await expect(checkboxLocator).not.toBeChecked();
265+
// Expect clicking the checkbox to function
243266
await checkboxLocator.click();
244267
await expect(checkboxLocator).toBeChecked();
245268
}
246269
await page.getByRole("document").click();
247270
await expect(page.getByRole("menu")).not.toBeVisible();
271+
// Expect all selectable tabs to be enabled
248272
await expect(page.getByRole("columnheader")).toContainText(
249273
tab.selectableColumns.map((x) => x.name)
250274
);
@@ -510,8 +534,8 @@ export async function testClearAll(
510534
): Promise<void> {
511535
await page.goto(tab.url);
512536
const selectedFilterNamesList = [];
537+
// Select each filter and get the names of the actual filter text
513538
for (const filterName of filterNames) {
514-
// Select the passed filter names
515539
await page.getByText(filterRegex(filterName)).dispatchEvent("click");
516540
await getFirstFilterButtonLocator(page).getByRole("checkbox").click();
517541
await expect(
@@ -531,6 +555,7 @@ export async function testClearAll(
531555
page.locator("#sidebar-positioner").getByText(filterName)
532556
).toHaveCount(0);
533557
}
558+
// Ensure that the filters still show as unchecked
534559
for (let i = 0; i < filterNames.length; i++) {
535560
await page.getByText(filterRegex(filterNames[i])).dispatchEvent("click");
536561
await expect(

0 commit comments

Comments
 (0)