-
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.
Test SearchBar unit test and integration test
- Loading branch information
Showing
8 changed files
with
183 additions
and
38 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
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,49 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import SearchBar from "./SearchBar"; | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
describe("Given a SearchBar component", () => { | ||
const expectedLabelText = /search/i; | ||
const expectedInputContent = "head"; | ||
const actionOnSubmit = vi.fn(); | ||
|
||
describe("When it is rendered", () => { | ||
test("Then it should show a 'Search' input", () => { | ||
render(<SearchBar actionOnSubmit={actionOnSubmit} />); | ||
|
||
const searchInput = screen.getByLabelText(expectedLabelText); | ||
|
||
expect(searchInput).toBeInTheDocument(); | ||
}); | ||
|
||
test("Then it should show a button with an alt text 'Magnifying glass icon'", () => { | ||
const expectedSearchButtonAlt = "Magnifying glass icon"; | ||
|
||
render(<SearchBar actionOnSubmit={actionOnSubmit} />); | ||
|
||
const button = screen.getByRole("button", { | ||
name: expectedSearchButtonAlt, | ||
}); | ||
|
||
expect(button).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe("When it is rendered with a current query 'head'", () => { | ||
test("Then the input should have the received value 'head'", () => { | ||
render( | ||
<SearchBar | ||
actionOnSubmit={actionOnSubmit} | ||
currentQuery={expectedInputContent} | ||
/>, | ||
); | ||
|
||
const searchInput = screen.getByLabelText(expectedLabelText); | ||
|
||
expect(searchInput).toHaveValue(expectedInputContent); | ||
}); | ||
}); | ||
}); |
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