-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* mapbox token added locally * autocomplete added * search bar style update * added clear icon * responsive styling updateed * prettier format update * search-bar test updated
- Loading branch information
Showing
11 changed files
with
1,076 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,6 @@ node_modules | |
# Mac | ||
.DS_Store | ||
/.next/ | ||
|
||
# Sensitive config | ||
.env.development.local |
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,51 @@ | ||
import { render, fireEvent, screen } from "@testing-library/react"; | ||
import SearchBar from "../search-bar"; | ||
import "@testing-library/jest-dom"; | ||
|
||
jest.mock("@mapbox/search-js-react", () => ({ | ||
AddressAutofill: ({ children, onRetrieve }) => ( | ||
<div onClick={() => onRetrieve({ features: [{ place_name: "Mock Address" }] })}> | ||
{children} | ||
</div> | ||
), | ||
})); | ||
|
||
describe("SearchBar Component", () => { | ||
it("renders search input and icons correctly", () => { | ||
render(<SearchBar />); | ||
|
||
const input = screen.getByPlaceholderText("Search San Francisco address"); | ||
const searchIcon = screen.getByTestId("search-icon"); | ||
const clearIcon = screen.getByTestId("clear-icon"); | ||
|
||
expect(input).toBeInTheDocument(); | ||
expect(searchIcon).toBeInTheDocument(); | ||
expect(clearIcon).toBeInTheDocument(); | ||
expect(searchIcon).toHaveStyle({ color: "rgb(23, 25, 35" }); | ||
}); | ||
|
||
it("updates address state when typing", () => { | ||
render(<SearchBar />); | ||
const input = screen.getByPlaceholderText("Search San Francisco address"); | ||
|
||
fireEvent.change(input, { target: { value: "123 Main St" } }); | ||
expect(input.value).toBe("123 Main St"); | ||
}); | ||
|
||
it("clears the address field when clear icon is clicked", () => { | ||
render(<SearchBar />); | ||
const input = screen.getByPlaceholderText("Search San Francisco address"); | ||
const clearIcon = screen.getByTestId("clear-icon"); | ||
|
||
fireEvent.change(input, { target: { value: "123 Main St" } }); | ||
fireEvent.click(clearIcon); | ||
expect(input.value).toBe(""); | ||
}); | ||
|
||
it("calls handleRetrieve and updates fullAddress on retrieve event", () => { | ||
render(<SearchBar />); | ||
const input = screen.getByPlaceholderText("Search San Francisco address"); | ||
|
||
fireEvent.click(input); | ||
}); | ||
}); |
This file was deleted.
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,84 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import { | ||
Input, | ||
InputGroup, | ||
InputLeftElement, | ||
InputRightElement, | ||
} from "@chakra-ui/react"; | ||
import { IoSearchSharp } from "react-icons/io5"; | ||
import { RxCross2 } from "react-icons/rx"; | ||
import { AddressAutofill } from "@mapbox/search-js-react"; | ||
|
||
const SearchBar = () => { | ||
const [address, setAddress] = useState(""); | ||
const [fullAddress, setFullAddress] = useState(null); | ||
|
||
const handleClearClick = () => { | ||
console.log(address); | ||
console.log(fullAddress); | ||
setAddress(""); | ||
}; | ||
|
||
const handleRetrieve = (event) => { | ||
const addressData = event.features[0]; | ||
setFullAddress(addressData); | ||
}; | ||
|
||
return ( | ||
<form> | ||
<AddressAutofill | ||
accessToken={process.env.NEXT_PUBLIC_MAPBOX_TOKEN} | ||
onRetrieve={handleRetrieve} | ||
> | ||
<InputGroup | ||
maxW={{ base: "303px", sm: "303px", md: "371px", lg: "417px" }} | ||
size={{ base: "md", md: "lg", xl: "lg" }} | ||
data-testid="search-bar" | ||
> | ||
<InputLeftElement> | ||
<IoSearchSharp | ||
color="grey.900" | ||
fontSize="1.1em" | ||
data-testid="search-icon" | ||
/> | ||
</InputLeftElement> | ||
<Input | ||
placeholder="Search San Francisco address" | ||
fontSize={{ base: "md", sm: "md", md: "md", lg: "lg" }} | ||
p={{ | ||
base: "0 10px 0 35px", | ||
sm: "0 10px 0 35px", | ||
md: "0 10px 0 48px", | ||
lg: "0 10px 0 48px", | ||
}} | ||
borderRadius="50" | ||
bgColor="white" | ||
focusBorderColor="yellow" | ||
type="text" | ||
name="address-1" | ||
value={address} | ||
onChange={(event) => setAddress(event.target.value)} | ||
_hover={{ | ||
borderColor: "yellow", | ||
_placeholder: { color: "grey.900" }, | ||
}} | ||
_invalid={{ borderColor: "red" }} | ||
autoComplete="address-line1" | ||
/> | ||
<InputRightElement> | ||
<RxCross2 | ||
color="grey.900" | ||
fontSize="1.1em" | ||
data-testid="clear-icon" | ||
onClick={handleClearClick} | ||
/> | ||
</InputRightElement> | ||
</InputGroup> | ||
</AddressAutofill> | ||
</form> | ||
); | ||
}; | ||
|
||
export default SearchBar; |
This file was deleted.
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
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 |
---|---|---|
|
@@ -27,4 +27,4 @@ const nextConfig = { | |
}, | ||
}; | ||
|
||
module.exports = nextConfig; | ||
module.exports = nextConfig; |
Oops, something went wrong.