Skip to content

Commit 652380c

Browse files
mrtopsytjpaten
authored and
jpaten
committed
fix: refactored locators and cleaned up typos in tests (#4078)
1 parent 0b4ffcd commit 652380c

File tree

3 files changed

+62
-48
lines changed

3 files changed

+62
-48
lines changed

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
});

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
});

explorer/e2e/testFunctions.ts

+54-29
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ export const getFirstRowNthColumnCellLocator = (
4747
return getMthRowNthColumnCellLocator(page, 0, columnIndex);
4848
};
4949

50+
/**
51+
* Get a locator to the cell in the first row's nth column
52+
* @param page - a Playwright page object
53+
* @param columnIndex - the zero-indexed column to return
54+
* @returns a Playwright locator object to the selected cell
55+
**/
56+
export const getLastRowNthColumnTextLocator = (
57+
page: Page,
58+
columnIndex: number
59+
): Locator => {
60+
return page
61+
.getByRole("rowgroup")
62+
.nth(1)
63+
.getByRole("row")
64+
.last()
65+
.getByRole("cell")
66+
.nth(columnIndex);
67+
};
68+
5069
/**
5170
* Tests that the tab url goes to a valid page and that the correct tab (and only
5271
* the correct tab) appears selected
@@ -59,7 +78,9 @@ export async function testUrl(
5978
tab: TabDescription,
6079
otherTabs: TabDescription[]
6180
): Promise<void> {
81+
// Go to the selected tab
6282
await page.goto(tab.url);
83+
// Check that the selected tab appears selected and the other tabs appear deselected
6384
await expect(
6485
page.getByRole("tab").getByText(tab.tabName, { exact: true })
6586
).toHaveAttribute("aria-selected", "true", { timeout: 25000 });
@@ -72,35 +93,36 @@ export async function testUrl(
7293
}
7394
}
7495

75-
// Run the "Expect each tab to become selected, to go to the correct url, and to show all of its columns when selected" test
7696
/**
7797
* Checks that all preselected columns listed in the tab object are visible in the correct order
7898
* @param page - a Playwright page object
79-
* @param tab - the tab object to test
99+
* @param startTab - the tab object to start testing on
100+
* @param endTab - the tab to select during the test
80101
*/
81-
export async function testTab(page: Page, tab: TabDescription): Promise<void> {
82-
await expect(
83-
page
84-
.getByRole("rowgroup")
85-
.nth(1)
86-
.getByRole("row")
87-
.nth(1)
88-
.getByRole("cell")
89-
.nth(1)
90-
).toBeVisible();
91-
await page.getByRole("tab").getByText(tab.tabName, { exact: true }).click();
92-
await expect(page).toHaveURL(tab.url, { timeout: 25000 }); // Long timeout because some tabs take a long time to load
93-
await expect(page.getByRole("tab").getByText(tab.tabName)).toHaveAttribute(
102+
export async function testTab(
103+
page: Page,
104+
startTab: TabDescription,
105+
endTab: TabDescription
106+
): Promise<void> {
107+
// Run the "Expect each tab to become selected, to go to the correct url, and to show all of its columns when selected" test
108+
await page.goto(startTab.url);
109+
await expect(getFirstRowNthColumnCellLocator(page, 1)).toBeVisible();
110+
await page
111+
.getByRole("tab")
112+
.getByText(endTab.tabName, { exact: true })
113+
.click();
114+
await expect(page).toHaveURL(endTab.url, { timeout: 25000 }); // Long timeout because some tabs take a long time to load
115+
await expect(page.getByRole("tab").getByText(endTab.tabName)).toHaveAttribute(
94116
"aria-selected",
95117
"true"
96118
);
97-
if (tab.emptyFirstColumn) {
119+
if (endTab.emptyFirstColumn) {
98120
await expect(page.getByRole("columnheader")).toHaveText(
99-
[" "].concat(tab.preselectedColumns.map((x) => x.name))
121+
[" "].concat(endTab.preselectedColumns.map((x) => x.name))
100122
);
101123
} else {
102124
await expect(page.getByRole("columnheader")).toHaveText(
103-
tab.preselectedColumns.map((x) => x.name)
125+
endTab.preselectedColumns.map((x) => x.name)
104126
);
105127
}
106128
}
@@ -135,21 +157,17 @@ export async function testSortAzul(
135157
page,
136158
columnIndex
137159
);
138-
const lastElementTextLocator = page
139-
.getByRole("rowgroup")
140-
.nth(1)
141-
.getByRole("row")
142-
.last()
143-
.getByRole("cell")
144-
.nth(columnIndex);
145-
// Locator for the sort button for the tab
160+
const lastElementTextLocator = getLastRowNthColumnTextLocator(
161+
page,
162+
columnIndex
163+
);
164+
// Locator for the sort button
146165
const columnSortLocator = page
147166
.getByRole("columnheader", {
148167
exact: true,
149168
name: tab.preselectedColumns[columnPosition].name,
150169
})
151170
.getByRole("button");
152-
153171
// Expect the first and last cells to be visible and have text
154172
await expect(firstElementTextLocator).toBeVisible();
155173
await expect(lastElementTextLocator).toBeVisible();
@@ -183,7 +201,6 @@ export async function testSortCatalog(
183201
): Promise<void> {
184202
// Get the current tab, and go to it's URL
185203
await page.goto(tab.url);
186-
// For each column
187204
for (
188205
let columnPosition = 0;
189206
columnPosition < tab.preselectedColumns.length;
@@ -231,10 +248,14 @@ export async function testSelectableColumns(
231248
page: Page,
232249
tab: TabDescription
233250
): Promise<void> {
251+
// Navigate to the tab
234252
await page.goto(tab.url);
253+
// Select the "Edit Columns" menu
235254
await page.getByRole("button").getByText("Edit Columns").click();
236255
await expect(page.getByRole("menu")).toBeVisible();
256+
// Enable each selectable tab
237257
for (const column of tab.selectableColumns) {
258+
// Locate the checkbox for each column
238259
const checkboxLocator = page
239260
.getByRole("menu")
240261
.locator("*")
@@ -244,13 +265,16 @@ export async function testSelectableColumns(
244265
.filter({ has: page.getByText(column.name, { exact: true }) }),
245266
})
246267
.getByRole("checkbox");
268+
// Expect each column to be enabled and unchecked for selectable tabs
247269
await expect(checkboxLocator).toBeEnabled();
248270
await expect(checkboxLocator).not.toBeChecked();
271+
// Expect clicking the checkbox to function
249272
await checkboxLocator.click();
250273
await expect(checkboxLocator).toBeChecked();
251274
}
252275
await page.getByRole("document").click();
253276
await expect(page.getByRole("menu")).not.toBeVisible();
277+
// Expect all selectable tabs to be enabled
254278
await expect(page.getByRole("columnheader")).toContainText(
255279
tab.selectableColumns.map((x) => x.name)
256280
);
@@ -516,8 +540,8 @@ export async function testClearAll(
516540
): Promise<void> {
517541
await page.goto(tab.url);
518542
const selectedFilterNamesList = [];
543+
// Select each filter and get the names of the actual filter text
519544
for (const filterName of filterNames) {
520-
// Select the passed filter names
521545
await page.getByText(filterRegex(filterName)).dispatchEvent("click");
522546
await getFirstFilterButtonLocator(page).getByRole("checkbox").click();
523547
await expect(
@@ -537,6 +561,7 @@ export async function testClearAll(
537561
page.locator("#sidebar-positioner").getByText(filterName)
538562
).toHaveCount(0);
539563
}
564+
// Ensure that the filters still show as unchecked
540565
for (let i = 0; i < filterNames.length; i++) {
541566
await page.getByText(filterRegex(filterNames[i])).dispatchEvent("click");
542567
await expect(

0 commit comments

Comments
 (0)