-
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.
refactor(BoxWithImage component) (#1569)
* modify BoxWithImage and storybook to align with new size specifications * add proper null check against text content * add correct strapi props in preparation for CMS changes
- Loading branch information
1 parent
80a8cb5
commit 7935eb0
Showing
4 changed files
with
98 additions
and
34 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,57 @@ | ||
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); | ||
}, | ||
); | ||
|
||
it("should display just an image if there is no text content", () => { | ||
const { getByAltText } = render( | ||
<BoxWithImage | ||
image={{ url: "image.png", alternativeText: imageAltText }} | ||
/>, | ||
); | ||
const image = getByAltText(imageAltText); | ||
expect(image).toBeInTheDocument(); | ||
expect(image.parentElement).toHaveClass("max-w-full"); | ||
}); | ||
}); |
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