-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fix and update autosuggest (#99)
* feat: fix and update autosuggest * Update index.scss * test: add some tests * chore: remove unused import * fix: ignore export * fix: weird menu option highlighted behavior
- Loading branch information
Showing
12 changed files
with
213 additions
and
146 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,40 @@ | ||
import React from "react"; | ||
import { expect, test } from "vitest"; | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { axe } from "jest-axe"; | ||
import AutoSuggest from "./AutoSuggest"; | ||
import TextInput from "../TextInput"; | ||
import { animals } from "./AutoSuggest.stories"; | ||
|
||
const props = { | ||
autoSuggestions: animals, | ||
children: <TextInput id="suggestions" labelText="Suggestions" />, | ||
inputProps: {}, | ||
onChange: () => {}, | ||
}; | ||
|
||
describe("AutoSuggest", () => { | ||
test("snapshot", () => { | ||
const { baseElement } = render(<AutoSuggest {...props} />); | ||
expect(baseElement).toMatchSnapshot(); | ||
}); | ||
|
||
test("functional", async () => { | ||
render(<AutoSuggest {...props} />); | ||
expect(await screen.findByLabelText("Suggestions")).toBeInTheDocument(); | ||
const input = screen.getByLabelText("Suggestions"); | ||
userEvent.type(input, "ca"); | ||
expect(await screen.findByText("caribou")).toBeInTheDocument(); | ||
expect(await screen.findByText("cat")).toBeInTheDocument(); | ||
const suggestion = screen.getByText("caribou"); | ||
await userEvent.click(suggestion); | ||
expect(screen.queryByText("cat")).toBeNull(); | ||
}); | ||
|
||
test("a11y", async () => { | ||
const { container } = render(<AutoSuggest {...props} />); | ||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
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
Oops, something went wrong.