import React from "react"; import cn from "classnames"; import { render } from "@testing-library/react"; import Text, { TextTypes } from "../Text"; describe("Text", () => { it("should render corrrrectly based on the type prop", () => { const tests: { type: TextTypes; expected: string }[] = [ { type: "headline-1", expected: "h1" }, { type: "headline-2", expected: "h2" }, { type: "headline-3", expected: "h3" }, { type: "headline-4", expected: "h4" }, { type: "headline-5", expected: "h5" }, { type: "headline-6", expected: "h6" }, { type: "subtitle-1", expected: "h6" }, { type: "subtitle-2", expected: "h6" }, { type: "body-1", expected: "p" }, { type: "body-2", expected: "p" }, { type: "overline", expected: "span" }, { type: "button", expected: "button" }, ]; tests.forEach(({ type, expected }) => { const { getByTestId, unmount } = render( ); const text = getByTestId("text"); expect(text.tagName.toLowerCase()).toBe(expected); expect(text.className).toBe(`rmd-typography rmd-typography--${type}`); unmount(); }); const { getByTestId } = render(
); const text = getByTestId("text"); expect(text.tagName).toBe("CAPTION"); expect(text.className).toBe("rmd-typography rmd-typography--caption"); }); it("should default to rendering as a

tag with the body-1 styles", () => { const { getByTestId } = render(); const p = getByTestId("p"); expect(p.tagName).toBe("P"); expect(p.className).toBe("rmd-typography rmd-typography--body-1"); }); it("should be able to render as a string component prop", () => { const { getByTestId } = render( Hello, world! ); const text = getByTestId("text"); expect(text.tagName).toBe("SECTION"); expect(text).toMatchSnapshot(); }); it("should be able to render as a functional component", () => { const Component = ({ className, children }: any) => (

{children}
); const { getByTestId } = render( Hello, world! ); const text = getByTestId("text"); expect(text.tagName).toBe("SECTION"); expect(text).toMatchSnapshot(); }); it("should be able to render as a class component", () => { class Component extends React.Component { public render() { const { children, className } = this.props; return (
{children}
); } } const { getByTestId } = render( Hello, world! ); const text = getByTestId("text"); expect(text.tagName).toBe("SECTION"); expect(text).toMatchSnapshot(); }); it("should be able to use a children render function", () => { const { container } = render( {({ className }) => ( Content )} ); expect(container).toMatchSnapshot(); }); });