diff --git a/frontend/tests/e2e/search/search.spec.ts b/frontend/tests/e2e/search/search.spec.ts index 6d8cfd676..ddf0ac043 100644 --- a/frontend/tests/e2e/search/search.spec.ts +++ b/frontend/tests/e2e/search/search.spec.ts @@ -11,6 +11,7 @@ import { getFirstSearchResultTitle, getLastSearchResultTitle, getMobileMenuButton, + getNumberOfOpportunitySearchResults, getSearchInput, hasMobileMenu, refreshPageWithCurrentURL, @@ -21,6 +22,8 @@ import { } from "./searchSpecUtil"; import { expect, test } from "@playwright/test"; +import page from "../../../src/app/search/page"; + test("should navigate from index to search page", async ({ page }) => { // Start from the index page with feature flag set await page.goto("/?_ff=showSearchV0:true"); @@ -202,10 +205,8 @@ test.describe("Search page tests", () => { }) => { await clickLastPaginationPage(page); - // Wait for the search results to load again await waitForSearchResultsInitialLoad(page); - // Note the last result on the last page const lastSearchResultTitle = await getLastSearchResultTitle(page); await selectOppositeSortOption(page); @@ -214,4 +215,28 @@ test.describe("Search page tests", () => { expect(firstSearchResultTitle).toBe(lastSearchResultTitle); }); + + test("number of results is the same with none or all opportunity status checked", async ({ + page, + }) => { + const initialNumberOfOpportunityResults = + await getNumberOfOpportunitySearchResults(page); + + // check all 4 boxes + const statusCheckboxes = { + "status-forecasted": "forecasted", + "status-posted": "posted", + "status-closed": "closed", + "status-archived": "archived", + }; + + await toggleCheckboxes(page, statusCheckboxes, "status"); + + const updatedNumberOfOpportunityResults = + await getNumberOfOpportunitySearchResults(page); + + expect(initialNumberOfOpportunityResults).toBe( + updatedNumberOfOpportunityResults, + ); + }); }); diff --git a/frontend/tests/e2e/search/searchSpecUtil.ts b/frontend/tests/e2e/search/searchSpecUtil.ts index 8d7a7da40..f54d32b15 100644 --- a/frontend/tests/e2e/search/searchSpecUtil.ts +++ b/frontend/tests/e2e/search/searchSpecUtil.ts @@ -188,3 +188,20 @@ export async function selectOppositeSortOption(page: Page) { await sortByDropdown.selectOption(oppositeValue); } + +export async function waitForLoaderToBeHidden(page: Page) { + await page.waitForSelector( + ".display-flex.flex-align-center.flex-justify-center.margin-bottom-15.margin-top-15", + { state: "hidden" }, + ); +} + +export async function getNumberOfOpportunitySearchResults(page: Page) { + await waitForLoaderToBeHidden(page); + const opportunitiesText = await page + .locator("h2.tablet-lg\\:grid-col-fill") + .textContent(); + return opportunitiesText + ? parseInt(opportunitiesText.replace(/\D/g, ""), 10) + : 0; +}