Skip to content

Commit abd3b3e

Browse files
Fran McDadeFran McDade
Fran McDade
authored and
Fran McDade
committed
fix: anvil explorer pagination test (#4453)
1 parent 233bf6d commit abd3b3e

File tree

4 files changed

+89
-48
lines changed

4 files changed

+89
-48
lines changed

e2e/anvil/anvil-dataset.spec.ts

+7-14
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@ import {
88
CHIP_TEXT_ACCESS_REQUIRED,
99
DatasetAccess,
1010
} from "./common/constants";
11-
import {
12-
MUI_ALERT_ROOT,
13-
MUI_BUTTON_GROUP_ROOT,
14-
MUI_FORM_CONTROL_ROOT,
15-
MUI_TABLE_CELL_ROOT,
16-
MUI_TABLE_ROOT,
17-
MUI_TABLE_ROW_ROOT,
18-
} from "../features/common/constants";
11+
import { MUI_CLASSES } from "../features/common/constants";
1912
import { ROUTE_MANIFEST_DOWNLOAD } from "../../site-config/anvil-cmg/dev/export/constants";
2013
import { ANVIL_CMG_CATEGORY_KEY } from "../../site-config/anvil-cmg/category";
2114

@@ -54,7 +47,7 @@ describe("Dataset", () => {
5447
// Confirm the login alert is displayed.
5548
await expect(
5649
page.locator(
57-
`${MUI_ALERT_ROOT}:has-text("To export this dataset, please sign in and, if necessary, request access.")`
50+
`${MUI_CLASSES.ALERT}:has-text("To export this dataset, please sign in and, if necessary, request access.")`
5851
)
5952
).toBeVisible();
6053
});
@@ -99,7 +92,7 @@ describe("Dataset", () => {
9992
// Confirm the login alert is displayed.
10093
await expect(
10194
page.locator(
102-
`${MUI_ALERT_ROOT}:has-text("To download this dataset manifest, please sign in and, if necessary, request access.")`
95+
`${MUI_CLASSES.ALERT}:has-text("To download this dataset manifest, please sign in and, if necessary, request access.")`
10396
)
10497
).toBeVisible();
10598
});
@@ -115,7 +108,7 @@ describe("Dataset", () => {
115108

116109
// Confirm the file manifest page is loaded: check there are two buttons
117110
// (one for download, one for copy to clipboard).
118-
const buttons = page.locator(`${MUI_BUTTON_GROUP_ROOT} button`);
111+
const buttons = page.locator(`${MUI_CLASSES.BUTTON_GROUP} button`);
119112

120113
// Ensure there are exactly two buttons.
121114
await expect(buttons).toHaveCount(2);
@@ -153,7 +146,7 @@ describe("Dataset", () => {
153146
await clickLink(page, BUTTON_TEXT_ANALYZE_IN_TERRA);
154147

155148
// Confirm the analyze in Terra page is loaded: check for form elements.
156-
await expect(page.locator(MUI_FORM_CONTROL_ROOT).first()).toBeVisible();
149+
await expect(page.locator(MUI_CLASSES.FORM_CONTROL).first()).toBeVisible();
157150
});
158151

159152
test("displays analyze in Terra selected data", async ({ page }) => {
@@ -213,12 +206,12 @@ async function goToDataset(page: Page, access: DatasetAccess): Promise<void> {
213206
// Find a dataset that user has access to.
214207
const datasetRow = page
215208
.locator(
216-
`${MUI_TABLE_ROOT} ${MUI_TABLE_ROW_ROOT}:has(${MUI_TABLE_CELL_ROOT}:has-text("${access}"))`
209+
`${MUI_CLASSES.TABLE} ${MUI_CLASSES.TABLE_ROW}:has(${MUI_CLASSES.TABLE_CELL}:has-text("${access}"))`
217210
)
218211
.first();
219212
await expect(datasetRow).toBeVisible(); // Confirm at least one dataset has been found.
220213
const datasetLink = datasetRow.locator(
221-
`${MUI_TABLE_CELL_ROOT}:first-child a`
214+
`${MUI_CLASSES.TABLE_CELL}:first-child a`
222215
);
223216
const datasetTitle = await datasetLink.innerText();
224217
await datasetLink.click();

e2e/anvil/anvil-filters.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
} from "../testFunctions";
1111
import {
1212
ANVIL_FILTER_NAMES,
13-
ANVIL_TABS,
1413
ANVIL_TAB_TEST_ORDER,
14+
ANVIL_TABS,
1515
BIOSAMPLE_TYPE_INDEX,
1616
CONSENT_GROUP_INDEX,
1717
DATASET_INDEX,

e2e/features/common/constants.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
export const MUI_ALERT_ROOT = ".MuiAlert-root";
2-
export const MUI_BUTTON_GROUP_ROOT = ".MuiButtonGroup-root";
3-
export const MUI_FORM_CONTROL_ROOT = ".MuiFormControl-root";
4-
export const MUI_TABLE_CELL_ROOT = ".MuiTableCell-root";
5-
export const MUI_TABLE_ROOT = ".MuiTable-root";
6-
export const MUI_TABLE_ROW_ROOT = ".MuiTableRow-root";
1+
export const KEYBOARD_KEYS = {
2+
ESCAPE: "Escape",
3+
};
4+
5+
export const MUI_CLASSES = {
6+
ALERT: ".MuiAlert-root",
7+
BUTTON: ".MuiButton-root",
8+
BUTTON_GROUP: ".MuiButtonGroup-root",
9+
FORM_CONTROL: ".MuiFormControl-root",
10+
ICON_BUTTON: ".MuiIconButton-root",
11+
LIST: ".MuiList-root",
12+
LIST_ITEM_BUTTON: ".MuiListItemButton-root",
13+
POPOVER: ".MuiPopover-root",
14+
TABLE: ".MuiTable-root",
15+
TABLE_BODY: ".MuiTableBody-root",
16+
TABLE_CELL: ".MuiTableCell-root",
17+
TABLE_CONTAINER: ".MuiTableContainer-root",
18+
TABLE_ROW: ".MuiTableRow-root",
19+
};

e2e/testFunctions.ts

+62-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { expect, Locator, Page } from "@playwright/test";
22
import { ColumnDescription, TabDescription } from "./testInterfaces";
3+
import { TEST_IDS } from "@databiosphere/findable-ui/lib/tests/testIds";
4+
import { KEYBOARD_KEYS, MUI_CLASSES } from "./features/common/constants";
35

46
/* eslint-disable sonarjs/no-duplicate-string -- ignoring duplicate strings here */
57

@@ -1038,7 +1040,10 @@ export async function filterAndTestLastPagePagination(
10381040
): Promise<boolean> {
10391041
// Filter to reduce the number of pages that must be selected
10401042
await page.goto(tab.url);
1041-
await page.getByText(filterRegex(filterName)).click();
1043+
await page
1044+
.getByTestId(TEST_IDS.FILTERS)
1045+
.getByText(filterRegex(filterName))
1046+
.click();
10421047
await expect(page.getByRole("checkbox").first()).toBeVisible();
10431048
const filterTexts = await page
10441049
.getByRole("button")
@@ -1069,25 +1074,41 @@ export async function filterAndTestLastPagePagination(
10691074
return false;
10701075
}
10711076
const minFilterValue = Math.min(...validFilterCounts);
1077+
1078+
const results = await page
1079+
.getByTestId(TEST_IDS.TABLE_PAGINATION_RESULTS)
1080+
.textContent();
1081+
10721082
await page
10731083
.getByRole("button")
10741084
.filter({ hasText: RegExp(`${minFilterValue}[\\s]*$`) })
10751085
.click();
1076-
await page.locator("body").click();
1077-
await expect(getFirstRowNthColumnCellLocator(page, 0)).toBeVisible();
1086+
1087+
await expect
1088+
.poll(
1089+
async () =>
1090+
await page.getByTestId(TEST_IDS.TABLE_PAGINATION_RESULTS).textContent()
1091+
)
1092+
.not.toEqual(results);
1093+
1094+
await page.keyboard.press(KEYBOARD_KEYS.ESCAPE);
10781095

10791096
// Should start on first page, and there should be multiple pages available
10801097
await expect(
1081-
page.locator(".MuiPaper-table").getByText(PAGE_COUNT_REGEX, { exact: true })
1098+
page
1099+
.getByTestId(TEST_IDS.TABLE_PAGINATION_PAGE)
1100+
.getByText(PAGE_COUNT_REGEX, { exact: true })
10821101
).toHaveText(/Page 1 of \d+/);
10831102
await expect(
1084-
page.locator(".MuiPaper-table").getByText(PAGE_COUNT_REGEX, { exact: true })
1103+
page
1104+
.getByTestId(TEST_IDS.TABLE_PAGINATION_PAGE)
1105+
.getByText(PAGE_COUNT_REGEX, { exact: true })
10851106
).not.toHaveText("Page 1 of 1");
10861107

10871108
// Detect number of pages
10881109
const splitStartingPageText = (
10891110
await page
1090-
.locator(".MuiPaper-table")
1111+
.getByTestId(TEST_IDS.TABLE_PAGINATION_PAGE)
10911112
.getByText(PAGE_COUNT_REGEX, { exact: true })
10921113
.innerText()
10931114
).split(" ");
@@ -1098,30 +1119,37 @@ export async function filterAndTestLastPagePagination(
10981119
for (let i = 2; i < maxPages + 1; i++) {
10991120
// (dispatchevent necessary because the filter menu sometimes interrupts the click event)
11001121
await page
1101-
.getByRole("button")
1102-
.filter({ has: page.getByTestId(FORWARD_BUTTON_TEST_ID) })
1122+
.getByTestId(TEST_IDS.TABLE_PAGINATION)
1123+
.locator(MUI_CLASSES.ICON_BUTTON)
1124+
.last()
11031125
.dispatchEvent("click");
11041126
await expect(getFirstRowNthColumnCellLocator(page, 0)).toBeVisible();
11051127
// Expect the page count to have incremented
1106-
await expect(page.getByText(PAGE_COUNT_REGEX, { exact: true })).toHaveText(
1107-
`Page ${i} of ${maxPages}`
1108-
);
1128+
await expect(
1129+
page
1130+
.getByTestId(TEST_IDS.TABLE_PAGINATION_PAGE)
1131+
.getByText(PAGE_COUNT_REGEX, { exact: true })
1132+
).toHaveText(`Page ${i} of ${maxPages}`);
11091133
}
11101134
// Expect to be on the last page
1111-
await expect(page.getByText(PAGE_COUNT_REGEX, { exact: true })).toContainText(
1112-
`Page ${maxPages} of ${maxPages}`
1113-
);
1135+
await expect(
1136+
page
1137+
.getByTestId(TEST_IDS.TABLE_PAGINATION_PAGE)
1138+
.getByText(PAGE_COUNT_REGEX, { exact: true })
1139+
).toContainText(`Page ${maxPages} of ${maxPages}`);
11141140
// Expect the back button to be enabled on the last page
11151141
await expect(
11161142
page
1117-
.getByRole("button")
1118-
.filter({ has: page.getByTestId(BACK_BUTTON_TEST_ID) })
1143+
.getByTestId(TEST_IDS.TABLE_PAGINATION)
1144+
.locator(MUI_CLASSES.ICON_BUTTON)
1145+
.first()
11191146
).toBeEnabled();
11201147
// Expect the forward button to be disabled
11211148
await expect(
11221149
page
1123-
.getByRole("button")
1124-
.filter({ has: page.getByTestId(FORWARD_BUTTON_TEST_ID) })
1150+
.getByTestId(TEST_IDS.TABLE_PAGINATION)
1151+
.locator(MUI_CLASSES.ICON_BUTTON)
1152+
.last()
11251153
).toBeDisabled();
11261154
return true;
11271155
}
@@ -1142,7 +1170,9 @@ export async function testPaginationContent(
11421170
"true"
11431171
);
11441172

1145-
const firstElementTextLocator = getFirstRowNthColumnCellLocator(page, 0);
1173+
await page.getByTestId(TEST_IDS.TABLE_FIRST_CELL).waitFor();
1174+
1175+
const firstElementTextLocator = page.getByTestId(TEST_IDS.TABLE_FIRST_CELL);
11461176

11471177
// Should start on first page
11481178
await expect(page.getByText(PAGE_COUNT_REGEX, { exact: true })).toHaveText(
@@ -1158,8 +1188,9 @@ export async function testPaginationContent(
11581188
// Click the next button
11591189
// dispatchEvent necessary because the table loading component sometimes interrupts a click event
11601190
await page
1161-
.getByRole("button")
1162-
.filter({ has: page.getByTestId(FORWARD_BUTTON_TEST_ID) })
1191+
.getByTestId(TEST_IDS.TABLE_PAGINATION)
1192+
.locator(MUI_CLASSES.ICON_BUTTON)
1193+
.last()
11631194
.dispatchEvent("click");
11641195
// Expect the page count to have incremented
11651196
await expect(page.getByText(PAGE_COUNT_REGEX, { exact: true })).toHaveText(
@@ -1168,15 +1199,17 @@ export async function testPaginationContent(
11681199
// Expect the back button to be enabled
11691200
await expect(
11701201
page
1171-
.getByRole("button")
1172-
.filter({ has: page.getByTestId(BACK_BUTTON_TEST_ID) })
1202+
.getByTestId(TEST_IDS.TABLE_PAGINATION)
1203+
.locator(MUI_CLASSES.ICON_BUTTON)
1204+
.first()
11731205
).toBeEnabled();
11741206
// Expect the forwards button to be enabled
11751207
if (i != maxPages) {
11761208
await expect(
11771209
page
1178-
.getByRole("button")
1179-
.filter({ has: page.getByTestId(FORWARD_BUTTON_TEST_ID) })
1210+
.getByTestId(TEST_IDS.TABLE_PAGINATION)
1211+
.locator(MUI_CLASSES.ICON_BUTTON)
1212+
.last()
11801213
).toBeEnabled();
11811214
}
11821215
// Expect the first entry to have changed on the new page
@@ -1191,9 +1224,11 @@ export async function testPaginationContent(
11911224
for (let i = 0; i < maxPages - 1; i++) {
11921225
const OldFirstTableEntry = FirstTableEntries[maxPages - i - 2];
11931226
await page
1194-
.getByRole("button")
1195-
.filter({ has: page.getByTestId(BACK_BUTTON_TEST_ID) })
1227+
.getByTestId(TEST_IDS.TABLE_PAGINATION)
1228+
.locator(MUI_CLASSES.ICON_BUTTON)
1229+
.first()
11961230
.click();
1231+
await page.getByTestId(TEST_IDS.TABLE_PAGINATION_RESULTS).waitFor();
11971232
// Expect page number to be correct
11981233
await expect(page.getByText(PAGE_COUNT_REGEX, { exact: true })).toHaveText(
11991234
RegExp(`Page ${maxPages - i - 1} of \\d+`)

0 commit comments

Comments
 (0)