-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow error page to be interactive without refresh
- Loading branch information
1 parent
7f94ecc
commit 0f1da69
Showing
5 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { useEffect, useRef } from "react"; | ||
|
||
export const usePrevious = <T>(value: T) => { | ||
const ref = useRef<T>(); | ||
useEffect(() => { | ||
ref.current = value; | ||
}); | ||
return ref.current; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { expect, Page, test } from "@playwright/test"; | ||
import { BrowserContextOptions } from "playwright-core"; | ||
|
||
import { toggleCheckbox, toggleMobileSearchFilters } from "./searchSpecUtil"; | ||
|
||
interface PageProps { | ||
page: Page; | ||
browserName?: string; | ||
contextOptions?: BrowserContextOptions; | ||
} | ||
|
||
test.describe("Search error page", () => { | ||
test("should return an error page when expected", async ({ | ||
page, | ||
}: PageProps) => { | ||
// trigger error by providing an invalid status value | ||
await page.goto("/search?status=not_a_status"); | ||
|
||
expect(page.locator(".usa-alert--error")).toBeTruthy(); | ||
}); | ||
|
||
test("should allow for performing a new search from error state", async ({ | ||
page, | ||
}, { project }) => { | ||
await page.goto("/search?status=not_a_status"); | ||
|
||
if (project.name.match(/[Mm]obile/)) { | ||
await toggleMobileSearchFilters(page); | ||
} | ||
|
||
await toggleCheckbox(page, "status-closed"); | ||
|
||
await page.waitForURL(/status\=forecasted\,posted\,closed/, { | ||
timeout: 5000, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { renderHook } from "@testing-library/react"; | ||
import { usePrevious } from "src/hooks/usePrevious"; | ||
|
||
// note that these tests come from https://github.com/streamich/react-use/blob/master/tests/usePrevious.test.ts | ||
const setUp = () => | ||
renderHook(({ state }) => usePrevious(state), { initialProps: { state: 0 } }); | ||
|
||
describe("usePrevious", () => { | ||
it("should return undefined on initial render", () => { | ||
const { result } = setUp(); | ||
|
||
expect(result.current).toBeUndefined(); | ||
}); | ||
|
||
it("should always return previous state after each update", () => { | ||
const { result, rerender } = setUp(); | ||
|
||
rerender({ state: 2 }); | ||
expect(result.current).toBe(0); | ||
|
||
rerender({ state: 4 }); | ||
expect(result.current).toBe(2); | ||
|
||
rerender({ state: 6 }); | ||
expect(result.current).toBe(4); | ||
}); | ||
}); |