diff --git a/app/components-test-lib/page.tsx b/app/components-test-lib/page.tsx index 2dd9c30f..6d7a7d62 100644 --- a/app/components-test-lib/page.tsx +++ b/app/components-test-lib/page.tsx @@ -2,6 +2,7 @@ import { Box, Heading, VStack, Text, HStack, Divider } from "@chakra-ui/react"; import SearchBar from "../components/search-bar"; +import CardHazard from "../components/card-hazard"; const ComponentsTestLib = () => { return ( @@ -15,22 +16,28 @@ const ComponentsTestLib = () => { }} m="auto" > - + Components Test Library - Search Bar - - This section demonstrates different states of the Search Bar component - + This section demonstrates the Search Bar component - - Default - - + + + + + + + + Hazards Card + + This section demonstrates Hazard Card component + + + diff --git a/app/components/__mocks__/address-data.js b/app/components/__mocks__/address-data.js new file mode 100644 index 00000000..6632d30b --- /dev/null +++ b/app/components/__mocks__/address-data.js @@ -0,0 +1,6 @@ +export const AddressData = { + softStory: "Non-compliant", + seismic: "No data", + tsunami: "Compliant", + address: "1000 Great Highway", +}; diff --git a/app/components/__mocks__/hazards.js b/app/components/__mocks__/hazards.js new file mode 100644 index 00000000..89d95ac3 --- /dev/null +++ b/app/components/__mocks__/hazards.js @@ -0,0 +1,23 @@ +export const Hazards = [ + { + title: "Soft story", + description: + "Soft story buildings have less structural integrity in an earthquake", + update: "00-00-0000", + color: "#171923", + }, + { + title: "Seismic", + description: + "This region is known to experience more focused seismic activity", + update: "00-00-0000", + color: "#F6AD55", + }, + { + title: "Tsunami", + description: + "These coastal areas can be at risk of flooding in the event of a tsunami", + update: "00-00-0000", + color: "#ED64A6", + }, +]; diff --git a/app/components/__tests__/card-hazard.test.tsx b/app/components/__tests__/card-hazard.test.tsx new file mode 100644 index 00000000..704d5e13 --- /dev/null +++ b/app/components/__tests__/card-hazard.test.tsx @@ -0,0 +1,45 @@ +import React from "react"; +import { render, screen } from "@testing-library/react"; +import CardHazard from "../card-hazard"; +import { Hazards } from "../__mocks__/hazards"; +import "@testing-library/jest-dom"; + +// eslint-disable-next-line react/display-name +jest.mock("../pill.tsx", () => () => ( +
Pill Component
+)); + +describe("CardHazard Component", () => { + beforeEach(() => { + Hazards[0] = { + title: "Earthquake", + description: "Potential hazard in the area.", + color: "#FF0000", + update: "2 days ago", + }; + }); + + it("renders without crashing", () => { + render(); + expect(screen.getByText("Earthquake")).toBeInTheDocument(); + }); + + it("displays the hazard title and description", () => { + render(); + expect(screen.getByText("Earthquake")).toBeInTheDocument(); + expect( + screen.getByText("Potential hazard in the area.") + ).toBeInTheDocument(); + }); + + it("displays the hazard's updated time", () => { + render(); + expect(screen.getByText("Updated 2 days ago")).toBeInTheDocument(); + }); + + it("displays the hazard's color in the SVG circle", () => { + render(); + const svgCircle = screen.getByRole("img", { hidden: true }); + expect(svgCircle).toHaveAttribute("fill", "#FF0000"); + }); +}); diff --git a/app/components/card-hazard.tsx b/app/components/card-hazard.tsx new file mode 100644 index 00000000..b361e000 --- /dev/null +++ b/app/components/card-hazard.tsx @@ -0,0 +1,63 @@ +import { + Card, + CardHeader, + CardBody, + CardFooter, + Text, + HStack, +} from "@chakra-ui/react"; +import { Hazards } from "./__mocks__/hazards"; +import Pill from "./pill"; + +const CardHazard = () => { + const hazard = Hazards[0]; + + return ( + + + + {hazard.title} + + + + + {hazard.description} + + + + + + + {"Updated " + hazard.update} + + + + ); +}; + +export default CardHazard; diff --git a/app/components/pill.tsx b/app/components/pill.tsx new file mode 100644 index 00000000..9ba8b023 --- /dev/null +++ b/app/components/pill.tsx @@ -0,0 +1,32 @@ +import { Box, Text } from "@chakra-ui/react"; +import { AddressData } from "./__mocks__/address-data"; + +const Pill = () => { + const getBgColor = (status: string) => { + switch (status) { + case "No data": + return "gray.400"; + case "Compliant": + return "green"; + case "Non-compliant": + return "red"; + default: + return "gray.400"; + } + }; + + return ( + + + {AddressData.softStory} + + + ); +}; + +export default Pill; diff --git a/styles/theme.ts b/styles/theme.ts index 771432b5..57200ee4 100644 --- a/styles/theme.ts +++ b/styles/theme.ts @@ -27,6 +27,11 @@ const customTheme = extendTheme({ fontWeight: "bold", color: "white", }, + textBig: { + fontSize: "xl", + fontWeight: "bold", + color: "blue", + }, textMedium: { fontSize: "md", fontWeight: "normal",