-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add debounced search on type to the search bar (#2703)
* debounced search on type * loading workspaces on page entry * fixing e2e test * removing boilerplate
- Loading branch information
1 parent
6a55889
commit d9668f7
Showing
7 changed files
with
78 additions
and
11 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
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
38 changes: 38 additions & 0 deletions
38
site/src/components/SearchBarWithFilter/SearchBarWithFilter.test.tsx
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,38 @@ | ||
import { fireEvent, screen } from "@testing-library/react" | ||
import userEvent from "@testing-library/user-event" | ||
import { render } from "../../testHelpers/renderHelpers" | ||
import { SearchBarWithFilter } from "./SearchBarWithFilter" | ||
|
||
// mock the debounce utility | ||
jest.mock("just-debounce-it", () => | ||
jest.fn((fn) => { | ||
fn.cancel = jest.fn() | ||
return fn | ||
}), | ||
) | ||
|
||
describe("SearchBarWithFilter", () => { | ||
it("calls the onFilter handler on keystroke", async () => { | ||
// When | ||
const onFilter = jest.fn() | ||
render(<SearchBarWithFilter onFilter={onFilter} />) | ||
|
||
const searchInput = screen.getByRole("textbox") | ||
await userEvent.type(searchInput, "workspace") // 9 characters | ||
|
||
// Then | ||
expect(onFilter).toBeCalledTimes(10) // 9 characters + 1 on component mount | ||
}) | ||
|
||
it("calls the onFilter handler on submit", async () => { | ||
// When | ||
const onFilter = jest.fn() | ||
render(<SearchBarWithFilter onFilter={onFilter} />) | ||
|
||
const searchInput = screen.getByRole("textbox") | ||
await fireEvent.keyDown(searchInput, { key: "Enter", code: "Enter", charCode: 13 }) | ||
|
||
// Then | ||
expect(onFilter).toBeCalledTimes(1) | ||
}) | ||
}) |
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
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