-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify variantWidths interface, add unit test
- Loading branch information
1 parent
bf12524
commit f20f1a0
Showing
2 changed files
with
68 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
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,46 @@ | ||
import { render } from "@testing-library/react"; | ||
import type { Variant } from "~/components/BoxWithImage"; | ||
import BoxWithImage, { variantWidths } from "~/components/BoxWithImage"; | ||
|
||
describe("BoxWithImage", () => { | ||
const imageAltText = "Alt text"; | ||
it("should render", () => { | ||
const imageText = "A beautiful image"; | ||
const headerText = "Some title description"; | ||
const { getByText, getByAltText } = render( | ||
<BoxWithImage | ||
image={{ alternativeText: imageAltText, url: "image.png" }} | ||
content={imageText} | ||
heading={{ text: headerText }} | ||
/>, | ||
); | ||
expect(getByText(imageText)).toBeInTheDocument(); | ||
expect(getByText(headerText)).toBeInTheDocument(); | ||
expect(getByAltText(imageAltText)).toBeInTheDocument(); | ||
}); | ||
|
||
it.each( | ||
Object.entries(variantWidths).map(([key, value]) => [ | ||
key as Variant, | ||
value, | ||
]), | ||
)( | ||
"image variant %s should have proper styling", | ||
(imageVariant, expectedStyle) => { | ||
const { getByAltText } = render( | ||
<BoxWithImage | ||
variant={imageVariant} | ||
image={{ url: "image.png", alternativeText: imageAltText }} | ||
content="Wow great image!" | ||
/>, | ||
); | ||
const imageContainer = getByAltText(imageAltText).parentElement; | ||
const shouldWrap = imageVariant === "XL" || imageVariant === "XXL"; | ||
const flexContainer = imageContainer?.parentElement; | ||
expect(flexContainer).toHaveClass( | ||
shouldWrap ? "md:flex-wrap" : "sm:flex-nowrap", | ||
); | ||
expect(imageContainer).toHaveClass(expectedStyle); | ||
}, | ||
); | ||
}); |