generated from NYCPlanning/ae-remix-template
-
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.
Implement a go to selected geo button Navigate to capital projects of city council or community district closes #67
- Loading branch information
1 parent
5923db5
commit e877149
Showing
8 changed files
with
210 additions
and
28 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
28 changes: 28 additions & 0 deletions
28
app/components/GoToDistrictBtn/GoToCityCouncilDistrictBtn.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,28 @@ | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import { GoToCityCouncilDistrictBtn } from "./GoToCityCouncilDistrictBtn"; | ||
|
||
describe("GoToCommunityDistrictBtn", () => { | ||
it("should call 'goToDistrict' when all ids are provided", () => { | ||
const goToDistrict = vi.fn(); | ||
render( | ||
<GoToCityCouncilDistrictBtn | ||
goToDistrict={goToDistrict} | ||
districtId={"10"} | ||
/>, | ||
); | ||
fireEvent.click(screen.getByText(/Go to Selected District/)); | ||
expect(goToDistrict).toHaveBeenCalled(); | ||
}); | ||
|
||
it("should not call 'goToDistrict' when an id is null", () => { | ||
const goToDistrict = vi.fn(); | ||
render( | ||
<GoToCityCouncilDistrictBtn | ||
goToDistrict={goToDistrict} | ||
districtId={null} | ||
/>, | ||
); | ||
fireEvent.click(screen.getByText(/Go to Selected District/)); | ||
expect(goToDistrict).not.toHaveBeenCalled(); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
app/components/GoToDistrictBtn/GoToCityCouncilDistrictBtn.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,22 @@ | ||
import { GoToDistrictBtn, GoToDistrictBtnProps } from "."; | ||
|
||
export interface GoToCityCouncilDistrictBtnProps | ||
extends Pick<GoToDistrictBtnProps, "goToDistrict"> { | ||
districtId: string | null; | ||
} | ||
|
||
export function GoToCityCouncilDistrictBtn({ | ||
districtId, | ||
...props | ||
}: GoToCityCouncilDistrictBtnProps) { | ||
return ( | ||
<GoToDistrictBtn | ||
path={ | ||
districtId === null | ||
? null | ||
: `city-council-districts/${districtId}/capital-projects` | ||
} | ||
{...props} | ||
/> | ||
); | ||
} |
30 changes: 30 additions & 0 deletions
30
app/components/GoToDistrictBtn/GoToCommunityDistrictBtn.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,30 @@ | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import { GoToCommunityDistrictBtn } from "./GoToCommunityDistrictBtn"; | ||
|
||
describe("GoToCommunityDistrictBtn", () => { | ||
it("should call 'goToDistrict' when all ids are provided", () => { | ||
const goToDistrict = vi.fn(); | ||
render( | ||
<GoToCommunityDistrictBtn | ||
goToDistrict={goToDistrict} | ||
boroughId={"1"} | ||
districtId={"01"} | ||
/>, | ||
); | ||
fireEvent.click(screen.getByText(/Go to Selected District/)); | ||
expect(goToDistrict).toHaveBeenCalled(); | ||
}); | ||
|
||
it("should not call 'goToDistrict' when an id is null", () => { | ||
const goToDistrict = vi.fn(); | ||
render( | ||
<GoToCommunityDistrictBtn | ||
goToDistrict={goToDistrict} | ||
boroughId={"1"} | ||
districtId={null} | ||
/>, | ||
); | ||
fireEvent.click(screen.getByText(/Go to Selected District/)); | ||
expect(goToDistrict).not.toHaveBeenCalled(); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
app/components/GoToDistrictBtn/GoToCommunityDistrictBtn.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,24 @@ | ||
import { GoToDistrictBtn, GoToDistrictBtnProps } from "."; | ||
|
||
export interface GoToCommunityDistrictBtnProps | ||
extends Pick<GoToDistrictBtnProps, "goToDistrict"> { | ||
boroughId: string | null; | ||
districtId: string | null; | ||
} | ||
|
||
export function GoToCommunityDistrictBtn({ | ||
boroughId, | ||
districtId, | ||
...props | ||
}: GoToCommunityDistrictBtnProps) { | ||
return ( | ||
<GoToDistrictBtn | ||
path={ | ||
boroughId === null || districtId === null | ||
? null | ||
: `boroughs/${boroughId}/community-districts/${districtId}/capital-projects` | ||
} | ||
{...props} | ||
/> | ||
); | ||
} |
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,24 @@ | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import { GoToDistrictBtn } from "."; | ||
|
||
describe("GoToDistrictBtn", () => { | ||
it("should render with 'Go To' text", () => { | ||
const goToDistrict = vi.fn(); | ||
render(<GoToDistrictBtn goToDistrict={goToDistrict} path={null} />); | ||
expect(screen.getByText(/Go to Selected District/)).toBeVisible(); | ||
}); | ||
|
||
it("should call 'goToDistrict' when path is a string", () => { | ||
const goToDistrict = vi.fn(); | ||
render(<GoToDistrictBtn goToDistrict={goToDistrict} path={"/"} />); | ||
fireEvent.click(screen.getByText(/Go to Selected District/)); | ||
expect(goToDistrict).toHaveBeenCalled(); | ||
}); | ||
|
||
it("should not call 'goToDistrict' when path is null", () => { | ||
const goToDistrict = vi.fn(); | ||
render(<GoToDistrictBtn goToDistrict={goToDistrict} path={null} />); | ||
fireEvent.click(screen.getByText(/Go to Selected District/)); | ||
expect(goToDistrict).not.toHaveBeenCalled(); | ||
}); | ||
}); |
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,20 @@ | ||
import { Button } from "@nycplanning/streetscape"; | ||
|
||
export { GoToCityCouncilDistrictBtn } from "./GoToCityCouncilDistrictBtn"; | ||
|
||
export interface GoToDistrictBtnProps { | ||
goToDistrict: (path: string) => void; | ||
path: string | null; | ||
} | ||
export function GoToDistrictBtn({ goToDistrict, path }: GoToDistrictBtnProps) { | ||
return ( | ||
<Button | ||
width="full" | ||
onClick={path !== null ? () => goToDistrict(path) : () => undefined} | ||
isDisabled={path === null} | ||
mt={4} | ||
> | ||
Go to Selected District | ||
</Button> | ||
); | ||
} |
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