diff --git a/frontend/tests/e2e/search/search-loading.spec.ts b/frontend/tests/e2e/search/search-loading.spec.ts new file mode 100644 index 0000000000..148d1f667f --- /dev/null +++ b/frontend/tests/e2e/search/search-loading.spec.ts @@ -0,0 +1,69 @@ +import { Page, expect, test } from "@playwright/test"; +import { + expectURLContainsQueryParam, + fillSearchInputAndSubmit, +} from "./searchSpecUtil"; + +import { BrowserContextOptions } from "playwright-core"; + +interface PageProps { + page: Page; + browserName?: string; + contextOptions?: BrowserContextOptions; +} + +test.describe("Search page tests", () => { + test.beforeEach(async ({ page }: PageProps) => { + // Navigate to the search page with the feature flag set + await page.goto("/search?_ff=showSearchV0:true"); + }); + + test("should return 0 results when searching for obscure term", async ({ + page, + browserName, + }: PageProps) => { + // TODO (Issue #2005): fix test for webkit + test.skip( + browserName === "webkit", + "Skipping test for WebKit due to a query param issue.", + ); + + const searchTerm = "0resultearch"; + + await fillSearchInputAndSubmit(searchTerm, page); + await new Promise((resolve) => setTimeout(resolve, 3250)); + expectURLContainsQueryParam(page, "query", searchTerm); + + // eslint-disable-next-line testing-library/prefer-screen-queries + const resultsHeading = page.getByRole("heading", { + name: /0 Opportunities/i, + }); + await expect(resultsHeading).toBeVisible(); + + await expect(page.locator("div.usa-prose h2")).toHaveText( + "Your search did not return any results.", + ); + }); + + test("should show and hide loading state", async ({ + page, + browserName, + }: PageProps) => { + // TODO (Issue #2005): fix test for webkit + test.skip( + browserName === "webkit", + "Skipping test for WebKit due to a query param issue.", + ); + const searchTerm = "advanced"; + await fillSearchInputAndSubmit(searchTerm, page); + + const loadingIndicator = page.locator("text='Loading results...'"); + await expect(loadingIndicator).toBeVisible(); + await expect(loadingIndicator).toBeHidden(); + + const searchTerm2 = "agency"; + await fillSearchInputAndSubmit(searchTerm2, page); + await expect(loadingIndicator).toBeVisible(); + await expect(loadingIndicator).toBeHidden(); + }); +}); diff --git a/frontend/tests/e2e/search/search-navigate.spec.ts b/frontend/tests/e2e/search/search-navigate.spec.ts new file mode 100644 index 0000000000..3824c49e0c --- /dev/null +++ b/frontend/tests/e2e/search/search-navigate.spec.ts @@ -0,0 +1,44 @@ +import { Page, expect, test } from "@playwright/test"; +import { + clickMobileNavMenu, + clickSearchNavLink, + expectCheckboxIDIsChecked, + expectURLContainsQueryParam, + getMobileMenuButton, + hasMobileMenu, +} from "./searchSpecUtil"; + +import { BrowserContextOptions } from "playwright-core"; + +interface PageProps { + page: Page; + browserName?: string; + contextOptions?: BrowserContextOptions; +} + +test("should navigate from index to search page", async ({ + page, +}: PageProps) => { + // Start from the index page with feature flag set + await page.goto("/?_ff=showSearchV0:true"); + + // Mobile chrome must first click the menu button + if (await hasMobileMenu(page)) { + const menuButton = getMobileMenuButton(page); + await clickMobileNavMenu(menuButton); + } + + await clickSearchNavLink(page); + + // Verify that the new URL is correct + expectURLContainsQueryParam(page, "status", "forecasted,posted"); + + // Verify the presence of "Search" content on the page + await expect(page.locator("h1")).toContainText( + "Search funding opportunities", + ); + + // Verify that the 'forecasted' and 'posted' are checked + await expectCheckboxIDIsChecked(page, "#status-forecasted"); + await expectCheckboxIDIsChecked(page, "#status-posted"); +}); diff --git a/frontend/tests/e2e/search/search.spec.ts b/frontend/tests/e2e/search/search.spec.ts index 02e78f1901..32fc9bf9ab 100644 --- a/frontend/tests/e2e/search/search.spec.ts +++ b/frontend/tests/e2e/search/search.spec.ts @@ -2,19 +2,15 @@ import { Page, expect, test } from "@playwright/test"; import { clickAccordionWithTitle, clickLastPaginationPage, - clickMobileNavMenu, clickPaginationPageNumber, - clickSearchNavLink, expectCheckboxIDIsChecked, expectSortBy, expectURLContainsQueryParam, fillSearchInputAndSubmit, getFirstSearchResultTitle, getLastSearchResultTitle, - getMobileMenuButton, getNumberOfOpportunitySearchResults, getSearchInput, - hasMobileMenu, refreshPageWithCurrentURL, selectSortBy, toggleCheckboxes, @@ -29,88 +25,12 @@ interface PageProps { contextOptions?: BrowserContextOptions; } -test("should navigate from index to search page", async ({ - page, -}: PageProps) => { - // Start from the index page with feature flag set - await page.goto("/?_ff=showSearchV0:true"); - - // Mobile chrome must first click the menu button - if (await hasMobileMenu(page)) { - const menuButton = getMobileMenuButton(page); - await clickMobileNavMenu(menuButton); - } - - await clickSearchNavLink(page); - - // Verify that the new URL is correct - expectURLContainsQueryParam(page, "status", "forecasted,posted"); - - // Verify the presence of "Search" content on the page - await expect(page.locator("h1")).toContainText( - "Search funding opportunities", - ); - - // Verify that the 'forecasted' and 'posted' are checked - await expectCheckboxIDIsChecked(page, "#status-forecasted"); - await expectCheckboxIDIsChecked(page, "#status-posted"); -}); - test.describe("Search page tests", () => { test.beforeEach(async ({ page }: PageProps) => { // Navigate to the search page with the feature flag set await page.goto("/search?_ff=showSearchV0:true"); }); - test("should return 0 results when searching for obscure term", async ({ - page, - browserName, - }: PageProps) => { - // TODO (Issue #2005): fix test for webkit - test.skip( - browserName === "webkit", - "Skipping test for WebKit due to a query param issue.", - ); - - const searchTerm = "0resultearch"; - - await fillSearchInputAndSubmit(searchTerm, page); - await new Promise((resolve) => setTimeout(resolve, 3250)); - expectURLContainsQueryParam(page, "query", searchTerm); - - // eslint-disable-next-line testing-library/prefer-screen-queries - const resultsHeading = page.getByRole("heading", { - name: /0 Opportunities/i, - }); - await expect(resultsHeading).toBeVisible(); - - await expect(page.locator("div.usa-prose h2")).toHaveText( - "Your search did not return any results.", - ); - }); - - test("should show and hide loading state", async ({ - page, - browserName, - }: PageProps) => { - // TODO (Issue #2005): fix test for webkit - test.skip( - browserName === "webkit", - "Skipping test for WebKit due to a query param issue.", - ); - const searchTerm = "advanced"; - await fillSearchInputAndSubmit(searchTerm, page); - - const loadingIndicator = page.locator("text='Loading results...'"); - await expect(loadingIndicator).toBeVisible(); - await expect(loadingIndicator).toBeHidden(); - - const searchTerm2 = "agency"; - await fillSearchInputAndSubmit(searchTerm2, page); - await expect(loadingIndicator).toBeVisible(); - await expect(loadingIndicator).toBeHidden(); - }); - test("should refresh and retain filters in a new tab", async ({ page, }: PageProps) => {