-
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.
- Loading branch information
Showing
15 changed files
with
495 additions
and
26 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
services/ui-src/src/components/accordions/TemplateCardAccordion.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,81 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { RouterWrappedComponent } from "utils/testing/setupJest"; | ||
import { TemplateCardAccordion } from "components"; | ||
import verbiage from "verbiage/pages/home"; | ||
import { AnyObject } from "types"; | ||
import { testA11y } from "utils/testing/commonTests"; | ||
|
||
const accordionComponent = (mockProps?: AnyObject) => { | ||
const props = { | ||
verbiage: verbiage.cards.QM.accordion, | ||
...mockProps, | ||
}; | ||
return ( | ||
<RouterWrappedComponent> | ||
<TemplateCardAccordion {...props} /> | ||
</RouterWrappedComponent> | ||
); | ||
}; | ||
|
||
const accordionContent = verbiage.cards.QM.accordion.text[0].content; | ||
const accordionButtonLabel = verbiage.cards.QM.accordion.buttonLabel; | ||
|
||
describe("<TemplateCardAccordion />", () => { | ||
test("Accordion is visible", () => { | ||
render(accordionComponent()); | ||
expect(screen.getByText(accordionButtonLabel)).toBeVisible(); | ||
}); | ||
|
||
test("Accordion default closed state only shows the question", () => { | ||
render(accordionComponent()); | ||
expect(screen.getByText(accordionButtonLabel)).toBeVisible(); | ||
expect(screen.getByText(accordionContent)).not.toBeVisible(); | ||
}); | ||
|
||
test("Accordion should show answer on click", async () => { | ||
render(accordionComponent()); | ||
const accordionQuestion = screen.getByText(accordionButtonLabel); | ||
expect(accordionQuestion).toBeVisible(); | ||
expect(screen.getByText(accordionContent)).not.toBeVisible(); | ||
await userEvent.click(accordionQuestion); | ||
expect(accordionQuestion).toBeVisible(); | ||
expect(screen.getByText(accordionContent)).toBeVisible(); | ||
}); | ||
|
||
test("Accordion should render a list when given one", async () => { | ||
const mockProps = { | ||
verbiage: { | ||
buttonLabel: "expand", | ||
list: ["item one", "item two", "item three"], | ||
}, | ||
}; | ||
|
||
render(accordionComponent(mockProps)); | ||
const button = screen.getByText("expand"); | ||
await userEvent.click(button); | ||
|
||
expect(screen.getByText("item one")).toBeVisible(); | ||
expect(screen.getByText("item two")).toBeVisible(); | ||
expect(screen.getByText("item three")).toBeVisible(); | ||
}); | ||
|
||
test("Accordion should render a table when given one", async () => { | ||
const mockProps = { | ||
verbiage: { | ||
buttonLabel: "expand", | ||
table: { | ||
headRow: ["mock column header"], | ||
}, | ||
}, | ||
}; | ||
|
||
render(accordionComponent(mockProps)); | ||
const button = screen.getByText("expand"); | ||
await userEvent.click(button); | ||
|
||
expect(screen.getByText("mock column header")).toBeVisible(); | ||
}); | ||
|
||
testA11y(accordionComponent()); | ||
}); |
53 changes: 53 additions & 0 deletions
53
services/ui-src/src/components/accordions/TemplateCardAccordion.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,53 @@ | ||
import { Accordion, ListItem, UnorderedList } from "@chakra-ui/react"; | ||
import { AccordionItem, Table } from "components"; | ||
import { AnyObject } from "types"; | ||
import { parseCustomHtml } from "utils"; | ||
|
||
export const TemplateCardAccordion = ({ verbiage, ...props }: Props) => ( | ||
<Accordion sx={sx.root} allowToggle={true} {...props}> | ||
<AccordionItem sx={sx.text} label={verbiage.buttonLabel}> | ||
{parseCustomHtml(verbiage.text)} | ||
{verbiage.table && ( | ||
<Table | ||
content={verbiage.table} | ||
variant="striped" | ||
sxOverride={sx.table} | ||
/> | ||
)} | ||
{verbiage.list && ( | ||
<UnorderedList sx={sx.list}> | ||
{verbiage.list.map((listItem: string, index: number) => ( | ||
<ListItem key={index}>{listItem}</ListItem> | ||
))} | ||
</UnorderedList> | ||
)} | ||
</AccordionItem> | ||
</Accordion> | ||
); | ||
|
||
interface Props { | ||
verbiage: AnyObject; | ||
[key: string]: any; | ||
} | ||
|
||
const sx = { | ||
root: { | ||
marginTop: "2rem", | ||
}, | ||
text: { | ||
p: { | ||
marginBottom: "1rem", | ||
}, | ||
}, | ||
table: { | ||
"tr td:last-of-type": { | ||
fontWeight: "semibold", | ||
}, | ||
}, | ||
list: { | ||
paddingLeft: "1rem", | ||
"li:last-of-type": { | ||
fontWeight: "bold", | ||
}, | ||
}, | ||
}; |
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
63 changes: 63 additions & 0 deletions
63
services/ui-src/src/components/cards/TemplateCard.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,63 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { TemplateCard } from "components"; | ||
import { mockUseStore, RouterWrappedComponent } from "utils/testing/setupJest"; | ||
import { useStore } from "utils"; | ||
import verbiage from "verbiage/pages/home"; | ||
import { testA11y } from "utils/testing/commonTests"; | ||
|
||
jest.mock("utils/other/useBreakpoint", () => ({ | ||
useBreakpoint: jest.fn(() => ({ | ||
isDesktop: true, | ||
})), | ||
})); | ||
|
||
jest.mock("utils/state/useStore"); | ||
|
||
const mockedUseStore = useStore as jest.MockedFunction<typeof useStore>; | ||
|
||
const mockUseNavigate = jest.fn(); | ||
|
||
jest.mock("react-router-dom", () => ({ | ||
useNavigate: () => mockUseNavigate, | ||
})); | ||
|
||
const qmTemplateVerbiage = verbiage.cards.QM; | ||
|
||
const qmTemplateCardComponent = ( | ||
<RouterWrappedComponent> | ||
<TemplateCard templateName="QM" verbiage={qmTemplateVerbiage} /> | ||
</RouterWrappedComponent> | ||
); | ||
|
||
describe("<TemplateCard />", () => { | ||
describe("Renders", () => { | ||
beforeEach(() => { | ||
render(qmTemplateCardComponent); | ||
}); | ||
|
||
test("QM TemplateCard is visible", () => { | ||
expect(screen.getByText(qmTemplateVerbiage.title)).toBeVisible(); | ||
}); | ||
|
||
test("QM TemplateCard image is visible on desktop", () => { | ||
const imageAltText = "Spreadsheet icon"; | ||
expect(screen.getByAltText(imageAltText)).toBeVisible(); | ||
}); | ||
|
||
test("QM TemplateCard link is visible on desktop", () => { | ||
const templateCardLink = qmTemplateVerbiage.link.text; | ||
expect(screen.getByText(templateCardLink)).toBeVisible(); | ||
}); | ||
|
||
test("QM TemplateCard navigates to next route on link click", async () => { | ||
mockedUseStore.mockReturnValue(mockUseStore); | ||
const templateCardLink = screen.getByText(qmTemplateVerbiage.link.text)!; | ||
await userEvent.click(templateCardLink); | ||
const expectedRoute = qmTemplateVerbiage.link.route; | ||
await expect(mockUseNavigate).toHaveBeenCalledWith(expectedRoute); | ||
}); | ||
}); | ||
|
||
testA11y(qmTemplateCardComponent); | ||
}); |
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,146 @@ | ||
import { Button, Flex, Heading, Image, Text, Link } from "@chakra-ui/react"; | ||
import { Card, TemplateCardAccordion } from "components"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { useBreakpoint, getSignedTemplateUrl } from "utils"; | ||
import { AnyObject } from "types"; | ||
import downloadIcon from "assets/icons/icon_download.png"; | ||
import nextIcon from "assets/icons/icon_next_white.png"; | ||
import spreadsheetIcon from "assets/icons/icon_spreadsheet.png"; | ||
|
||
const downloadTemplate = async (templateName: string) => { | ||
const signedUrl = await getSignedTemplateUrl(templateName); | ||
const link = document.createElement("a"); | ||
link.setAttribute("target", "_blank"); | ||
link.setAttribute("href", signedUrl); | ||
link.click(); | ||
link.remove(); | ||
}; | ||
|
||
export const TemplateCard = ({ | ||
templateName, | ||
verbiage, | ||
cardprops, | ||
isHidden, | ||
...props | ||
}: Props) => { | ||
const { isDesktop } = useBreakpoint(); | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<Card boxShadow="0px 3px 9px rgba(0, 0, 0, 0.2)" {...cardprops}> | ||
<Flex sx={sx.root} {...props}> | ||
{isDesktop && ( | ||
<Image | ||
src={spreadsheetIcon} | ||
alt="Spreadsheet icon" | ||
sx={sx.spreadsheetIcon} | ||
/> | ||
)} | ||
<Flex sx={sx.cardContentFlex}> | ||
<Heading sx={sx.cardTitleText}>{verbiage.title}</Heading> | ||
<Text> | ||
{verbiage.body.available} | ||
{/* <Link href={verbiage.linkLocation} isExternal> | ||
{verbiage.linkText} | ||
</Link> */} | ||
{verbiage.midText} | ||
<Link href={verbiage.linkLocation2} isExternal> | ||
{verbiage.linkText2} | ||
</Link> | ||
{/* {verbiage.postLinkText} */} | ||
</Text> | ||
<Flex sx={sx.actionsFlex}> | ||
{verbiage.downloadText && ( | ||
<Button | ||
variant="link" | ||
sx={sx.templateDownloadButton} | ||
leftIcon={ | ||
<Image | ||
src={downloadIcon} | ||
alt="Download Icon" | ||
height="1.5rem" | ||
/> | ||
} | ||
onClick={async () => { | ||
await downloadTemplate(templateName); | ||
}} | ||
> | ||
{verbiage.downloadText} | ||
</Button> | ||
)} | ||
{!isHidden && ( | ||
<Button | ||
sx={sx.formLink} | ||
onClick={() => navigate(verbiage.link.route)} | ||
rightIcon={ | ||
<Image src={nextIcon} alt="Link Icon" height="1rem" /> | ||
} | ||
> | ||
{verbiage.link.text} | ||
</Button> | ||
)} | ||
</Flex> | ||
<TemplateCardAccordion verbiage={verbiage.accordion} /> | ||
<Text sx={sx.textMargin}>Notes on when it's due</Text> | ||
</Flex> | ||
</Flex> | ||
</Card> | ||
); | ||
}; | ||
|
||
interface Props { | ||
verbiage: AnyObject; | ||
isHidden?: boolean; | ||
[key: string]: any; | ||
} | ||
|
||
const sx = { | ||
root: { | ||
flexDirection: "row", | ||
}, | ||
spreadsheetIcon: { | ||
marginRight: "2rem", | ||
boxSize: "5.5rem", | ||
}, | ||
cardContentFlex: { | ||
width: "100%", | ||
flexDirection: "column", | ||
}, | ||
cardTitleText: { | ||
marginBottom: "0.5rem", | ||
fontSize: "lg", | ||
fontWeight: "bold", | ||
lineHeight: "1.5", | ||
}, | ||
actionsFlex: { | ||
flexFlow: "wrap", | ||
gridGap: "1rem", | ||
justifyContent: "space-between", | ||
margin: "1rem 0 0 1rem", | ||
".mobile &": { | ||
flexDirection: "column", | ||
}, | ||
}, | ||
templateDownloadButton: { | ||
justifyContent: "start", | ||
marginRight: "1rem", | ||
padding: "0", | ||
span: { | ||
marginLeft: "0rem", | ||
marginRight: "0.5rem", | ||
}, | ||
".mobile &": { | ||
marginRight: "0", | ||
}, | ||
}, | ||
formLink: { | ||
justifyContent: "start", | ||
span: { | ||
marginLeft: "0.5rem", | ||
marginRight: "-0.25rem", | ||
}, | ||
}, | ||
textMargin: { | ||
paddingTop: "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
Oops, something went wrong.