import React from "react"; import "@testing-library/jest-dom/extend-expect"; import { render } from "@testing-library/react"; import { Card, CardBody, CardFooter, CardHeader, CardImg, CardLink, CardSubtitle, CardText, CardTitle } from "../../"; test("should show Card with simple text", () => { const textMessage = "This is some text within a card body."; const { queryByTestId } = render( {textMessage} ); expect(queryByTestId("honey-ui-card")).toBeTruthy(); expect(queryByTestId("honey-ui-card")).toHaveClass("card"); expect(queryByTestId("honey-ui-card-body")).toBeTruthy(); expect(queryByTestId("honey-ui-card-body")).toHaveClass("card-body"); expect(queryByTestId("honey-ui-card-body")).toHaveTextContent(textMessage); }); test("should show Card with title, subtitle, text and link", () => { const { queryByTestId } = render( Card title Card subtitle Card text Card link ); const cardTitle = queryByTestId("honey-ui-card-title"); expect(cardTitle).toBeTruthy(); expect(cardTitle).toHaveClass("card-title"); expect(cardTitle).toHaveTextContent("Card title"); const cardSubtitle = queryByTestId("honey-ui-card-subtitle"); expect(cardSubtitle).toBeTruthy(); expect(cardSubtitle).toHaveClass("card-subtitle"); expect(cardSubtitle).toHaveTextContent("Card subtitle"); const cardText = queryByTestId("honey-ui-card-text"); expect(cardText).toBeTruthy(); expect(cardText).toHaveClass("card-text"); expect(cardText).toHaveTextContent("Card text"); const cardLink = queryByTestId("honey-ui-card-link"); expect(cardLink).toBeTruthy(); expect(cardLink).toHaveClass("card-link"); expect(cardLink).toHaveTextContent("Card link"); expect(cardLink && cardLink.getAttribute("href")).toEqual("#"); }); test("should show Card with header and footer", () => { const { queryByTestId } = render( Card header Card title Card text Card footer ); const cardHeader = queryByTestId("honey-ui-card-header"); expect(cardHeader).toBeTruthy(); expect(cardHeader).toHaveClass("card-header"); expect(cardHeader).toHaveTextContent("Card header"); const cardFooter = queryByTestId("honey-ui-card-footer"); expect(cardFooter).toBeTruthy(); expect(cardFooter).toHaveClass("card-footer"); expect(cardFooter).toHaveTextContent("Card footer"); }); test("should show Card with image", () => { const { queryByTestId } = render( Card text ); const cardImg = queryByTestId("honey-ui-card-img"); expect(cardImg).toBeTruthy(); expect(cardImg).toHaveClass("card-img"); expect(cardImg).toHaveClass("card-image-top"); expect(cardImg && cardImg.getAttribute("src")).toEqual("https://via.placeholder.com/150"); expect(cardImg && cardImg.getAttribute("alt")).toEqual("..."); }); test("should show Card with with custom background and outline", () => { const { queryByTestId } = render( Header Primary card title White text ); const card = queryByTestId("honey-ui-card"); expect(card).toBeTruthy(); expect(card).toHaveClass("card text-white bg-primary"); const cardHeader = queryByTestId("honey-ui-card-header"); expect(cardHeader).toBeTruthy(); expect(cardHeader).toHaveClass("card-header border-white"); });