-
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.
HCBS Footer 2/x - Set up app routes (#13)
- Loading branch information
1 parent
b550eda
commit 04e526a
Showing
19 changed files
with
985 additions
and
2 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
services/ui-src/src/components/accordions/AccordionItem.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,31 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
import { RouterWrappedComponent } from "utils/testing/setupJest"; | ||
import { Accordion } from "@chakra-ui/react"; | ||
import { AccordionItem } from "components"; | ||
|
||
const accordionItemComponent = ( | ||
<RouterWrappedComponent> | ||
<Accordion> | ||
<AccordionItem data-testid="accordion-item" /> | ||
</Accordion> | ||
</RouterWrappedComponent> | ||
); | ||
|
||
describe("Test AccordionItem", () => { | ||
beforeEach(() => { | ||
render(accordionItemComponent); | ||
}); | ||
|
||
test("AccordionItem is visible", () => { | ||
expect(screen.getByTestId("accordion-item")).toBeVisible(); | ||
}); | ||
}); | ||
|
||
describe("Test AccordionItem accessibility", () => { | ||
it("Should not have basic accessibility issues", async () => { | ||
const { container } = render(accordionItemComponent); | ||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
59 changes: 59 additions & 0 deletions
59
services/ui-src/src/components/accordions/AccordionItem.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,59 @@ | ||
import { ReactChild } from "react"; | ||
import { | ||
AccordionButton, | ||
AccordionItem as AccordionItemRoot, | ||
AccordionPanel, | ||
Image, | ||
Text, | ||
} from "@chakra-ui/react"; | ||
import plusIcon from "assets/icons/icon_plus.png"; | ||
import minusIcon from "assets/icons/icon_minus.png"; | ||
|
||
export const AccordionItem = ({ label, children, ...props }: Props) => { | ||
return ( | ||
<AccordionItemRoot sx={sx.root} {...props}> | ||
{({ isExpanded }) => ( | ||
<> | ||
<AccordionButton | ||
sx={sx.accordionButton} | ||
aria-label={label} | ||
title="accordion-button" | ||
> | ||
<Text flex="1">{label}</Text> | ||
<Image | ||
src={isExpanded ? minusIcon : plusIcon} | ||
alt={isExpanded ? "Collapse" : "Expand"} | ||
sx={sx.accordionIcon} | ||
/> | ||
</AccordionButton> | ||
<AccordionPanel sx={sx.accordionPanel}>{children}</AccordionPanel> | ||
</> | ||
)} | ||
</AccordionItemRoot> | ||
); | ||
}; | ||
|
||
interface Props { | ||
children?: ReactChild | ReactChild[]; | ||
[key: string]: any; | ||
} | ||
|
||
const sx = { | ||
root: { | ||
borderStyle: "none", | ||
}, | ||
accordionButton: { | ||
minHeight: "3.5rem", | ||
bg: "palette.gray_lightest", | ||
textAlign: "left", | ||
}, | ||
accordionPanel: { | ||
padding: "1.5rem 1rem 0.5rem", | ||
".mobile &": { | ||
padding: "0.5rem 0", | ||
}, | ||
}, | ||
accordionIcon: { | ||
width: "1rem", | ||
}, | ||
}; |
50 changes: 50 additions & 0 deletions
50
services/ui-src/src/components/accordions/FaqAccordion.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,50 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { RouterWrappedComponent } from "utils/testing/setupJest"; | ||
import { FaqAccordion } from "components"; | ||
|
||
const accordionItems = [ | ||
{ | ||
question: "Question?", | ||
answer: "Answer!", | ||
}, | ||
]; | ||
|
||
const faqAccordionComponent = ( | ||
<RouterWrappedComponent> | ||
<FaqAccordion accordionItems={accordionItems} /> | ||
</RouterWrappedComponent> | ||
); | ||
|
||
describe("Test FaqAccordion", () => { | ||
beforeEach(() => { | ||
render(faqAccordionComponent); | ||
}); | ||
|
||
test("FaqAccordion is visible", () => { | ||
expect(screen.getByText(accordionItems[0].question)).toBeVisible(); | ||
}); | ||
|
||
test("FaqAccordion default closed state only shows the question", () => { | ||
expect(screen.getByText(accordionItems[0].question)).toBeVisible(); | ||
expect(screen.getByText(accordionItems[0].answer)).not.toBeVisible(); | ||
}); | ||
|
||
test("FaqAccordion should show answer on click", async () => { | ||
const faqQuestion = screen.getByText(accordionItems[0].question); | ||
expect(faqQuestion).toBeVisible(); | ||
expect(screen.getByText(accordionItems[0].answer)).not.toBeVisible(); | ||
await userEvent.click(faqQuestion); | ||
expect(faqQuestion).toBeVisible(); | ||
expect(screen.getByText(accordionItems[0].answer)).toBeVisible(); | ||
}); | ||
}); | ||
|
||
describe("Test FaqAccordion accessibility", () => { | ||
it("Should not have basic accessibility issues", async () => { | ||
const { container } = render(faqAccordionComponent); | ||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
services/ui-src/src/components/accordions/FaqAccordion.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,33 @@ | ||
import { Accordion, Box, Text } from "@chakra-ui/react"; | ||
import { AccordionItem } from "components"; | ||
import { AnyObject } from "types"; | ||
|
||
export const FaqAccordion = ({ accordionItems, ...props }: Props) => { | ||
return ( | ||
<Accordion allowToggle={true} allowMultiple={true} {...props}> | ||
{accordionItems.map((item: AnyObject, index: number) => ( | ||
<AccordionItem key={index} label={item.question} sx={sx.item}> | ||
<Box sx={sx.answerBox}> | ||
<Text>{item.answer}</Text> | ||
</Box> | ||
</AccordionItem> | ||
))} | ||
</Accordion> | ||
); | ||
}; | ||
|
||
interface Props { | ||
accordionItems: AnyObject; | ||
} | ||
|
||
const sx = { | ||
item: { | ||
marginBottom: "1.5rem", | ||
borderStyle: "none", | ||
}, | ||
answerBox: { | ||
".mobile &": { | ||
paddingLeft: "1rem", | ||
}, | ||
}, | ||
}; |
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,13 @@ | ||
import { Route, Routes } from "react-router-dom"; | ||
import { HelpPage } from "components"; | ||
|
||
export const AppRoutes = () => { | ||
return ( | ||
<main id="main-content" tabIndex={-1}> | ||
<Routes> | ||
{/* General Routes */} | ||
<Route path="/help" element={<HelpPage />} /> | ||
</Routes> | ||
</main> | ||
); | ||
}; |
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,27 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
import { Card } from "components"; | ||
|
||
const cardComponent = ( | ||
<Card {...{ "data-testid": "card" }}> | ||
<p>Mock child component</p> | ||
</Card> | ||
); | ||
|
||
describe("Test Card", () => { | ||
beforeEach(() => { | ||
render(cardComponent); | ||
}); | ||
|
||
test("Card is visible", () => { | ||
expect(screen.getByTestId("card")).toBeVisible(); | ||
}); | ||
}); | ||
|
||
describe("Test Card accessibility", () => { | ||
it("Should not have basic accessibility issues", async () => { | ||
const { container } = render(cardComponent); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ReactChild } from "react"; | ||
import { Box } from "@chakra-ui/react"; | ||
|
||
export const Card = ({ children, ...props }: Props) => { | ||
return ( | ||
<Box {...props} sx={sx.root}> | ||
{children} | ||
</Box> | ||
); | ||
}; | ||
|
||
interface Props { | ||
children?: ReactChild | ReactChild[]; | ||
[key: string]: any; | ||
} | ||
|
||
const sx = { | ||
root: { | ||
width: "100%", | ||
padding: "2rem", | ||
".mobile &": { | ||
padding: "1rem", | ||
}, | ||
}, | ||
}; |
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,45 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
import { EmailCard } from "components"; | ||
import { createEmailLink } from "utils/other/email"; | ||
import verbiage from "verbiage/pages/help"; | ||
|
||
const emailCardComponent = ( | ||
<EmailCard | ||
verbiage={verbiage.cards.helpdesk} | ||
icon="settings" | ||
cardprops={{ "data-testid": "email-card" }} | ||
/> | ||
); | ||
|
||
describe("Test EmailCard", () => { | ||
beforeEach(() => { | ||
render(emailCardComponent); | ||
}); | ||
|
||
test("EmailCard is visible", () => { | ||
expect(screen.getByTestId("email-card")).toBeVisible(); | ||
}); | ||
|
||
test("Email links are created correctly", () => { | ||
const mockEmailData = { | ||
address: "[email protected]", | ||
subject: "the subject", | ||
body: "the body", | ||
}; | ||
const expectedEmailLink = "mailto:[email protected]?the%20subject"; | ||
expect(createEmailLink(mockEmailData)).toEqual(expectedEmailLink); | ||
}); | ||
|
||
test("Email links are visible", () => { | ||
expect(screen.getByRole("link")).toBeVisible(); | ||
}); | ||
}); | ||
|
||
describe("Test EmailCard accessibility", () => { | ||
it("Should not have basic accessibility issues", async () => { | ||
const { container } = render(emailCardComponent); | ||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
Oops, something went wrong.