Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Break up slow tests
Browse files Browse the repository at this point in the history
  • Loading branch information
acouch committed Jul 26, 2024
1 parent d70e412 commit df65dbc
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 80 deletions.
69 changes: 69 additions & 0 deletions frontend/tests/e2e/search/search-loading.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
44 changes: 44 additions & 0 deletions frontend/tests/e2e/search/search-navigate.spec.ts
Original file line number Diff line number Diff line change
@@ -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");
});
80 changes: 0 additions & 80 deletions frontend/tests/e2e/search/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) => {
Expand Down

0 comments on commit df65dbc

Please sign in to comment.