Skip to content

Commit 6bf73dc

Browse files
committed
try to make filter tests less flaky
1 parent 18fafab commit 6bf73dc

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

frontend/tests/e2e/search/search.spec.ts

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect, test } from "@playwright/test";
22
import { camelCase } from "lodash";
3-
import { PageProps } from "tests/e2e/playwrightUtils";
43
import {
54
clickAccordionWithTitle,
65
clickLastPaginationPage,
@@ -19,6 +18,7 @@ import {
1918
toggleMobileSearchFilters,
2019
validateTopLevelAndNestedSelectedFilterCounts,
2120
waitForAnyURLChange,
21+
waitForFilterOptions,
2222
waitForSearchResultsInitialLoad,
2323
waitForUrl,
2424
waitForURLContainsQueryParam,
@@ -54,13 +54,15 @@ test.describe("Search page tests", () => {
5454
"category-agriculture": "agriculture",
5555
};
5656

57-
await waitForSearchResultsInitialLoad(page);
58-
await selectSortBy(page, "agencyDesc");
59-
await expectSortBy(page, "agencyDesc");
60-
6157
if (project.name.match(/[Mm]obile/)) {
6258
await toggleMobileSearchFilters(page);
6359
}
60+
await Promise.all([
61+
waitForSearchResultsInitialLoad(page),
62+
waitForFilterOptions(page, "agency"),
63+
]);
64+
await selectSortBy(page, "agencyDesc");
65+
await expectSortBy(page, "agencyDesc");
6466

6567
await fillSearchInputAndSubmit(searchTerm, page);
6668

@@ -139,7 +141,10 @@ test.describe("Search page tests", () => {
139141
await toggleCheckboxes(page, statusCheckboxes, "status");
140142

141143
// Wait for the page to reload
142-
await waitForSearchResultsInitialLoad(page);
144+
await Promise.all([
145+
waitForSearchResultsInitialLoad(page),
146+
waitForFilterOptions(page, "agency"),
147+
]);
143148

144149
// Verify that page 1 is highlighted
145150
currentPageButton = page
@@ -153,9 +158,17 @@ test.describe("Search page tests", () => {
153158

154159
test("last result becomes first result when flipping sort order", async ({
155160
page,
156-
}: PageProps) => {
161+
}, { project }) => {
157162
await page.goto("/search");
158-
await waitForSearchResultsInitialLoad(page);
163+
164+
if (project.name.match(/[Mm]obile/)) {
165+
await toggleMobileSearchFilters(page);
166+
}
167+
168+
await Promise.all([
169+
waitForSearchResultsInitialLoad(page),
170+
waitForFilterOptions(page, "agency"),
171+
]);
159172
await selectSortBy(page, "opportunityTitleDesc");
160173

161174
await clickLastPaginationPage(page);
@@ -213,13 +226,17 @@ test.describe("Search page tests", () => {
213226
// load search page
214227
await page.goto("/search");
215228

216-
const initialSearchResultsCount =
217-
await getNumberOfOpportunitySearchResults(page);
218-
219229
// open accordion for filter type
220230
if (project.name.match(/[Mm]obile/)) {
221231
await toggleMobileSearchFilters(page);
222232
}
233+
await Promise.all([
234+
waitForSearchResultsInitialLoad(page),
235+
waitForFilterOptions(page, "agency"),
236+
]);
237+
238+
const initialSearchResultsCount =
239+
await getNumberOfOpportunitySearchResults(page);
223240

224241
await clickAccordionWithTitle(page, filterType);
225242

@@ -301,13 +318,17 @@ test.describe("Search page tests", () => {
301318

302319
await page.goto("/search");
303320

304-
const initialSearchResultsCount =
305-
await getNumberOfOpportunitySearchResults(page);
306-
307321
// open accordion for filter type
308322
if (project.name.match(/[Mm]obile/)) {
309323
await toggleMobileSearchFilters(page);
310324
}
325+
await Promise.all([
326+
waitForSearchResultsInitialLoad(page),
327+
waitForFilterOptions(page, "agency"),
328+
]);
329+
330+
const initialSearchResultsCount =
331+
await getNumberOfOpportunitySearchResults(page);
311332

312333
await clickAccordionWithTitle(page, "Agency");
313334

frontend/tests/e2e/search/searchSpecUtil.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,14 @@ export const validateTopLevelAndNestedSelectedFilterCounts = async (
317317
await expect(expanderButton).toContainText(`${expectedNestedCount}`);
318318
}
319319
};
320+
321+
export const waitForFilterOptions = async (page: Page, filterType: string) => {
322+
const filterButton = page.locator(
323+
`button[aria-controls="opportunity-filter-${filterType}"]`,
324+
);
325+
await filterButton.click();
326+
// expect(page.locator(`input[name="${filterType}-*"]`)).toBeTruthy();
327+
const filterOptions = page.locator(`input[name="${filterType}-*"]`);
328+
await filterOptions.isVisible();
329+
await filterButton.click();
330+
};

0 commit comments

Comments
 (0)