|
1 | 1 | import React from "react"; |
| 2 | +import faker from "faker"; |
| 3 | +import { HeadingIcon } from "./heading-icon"; |
| 4 | +import { render } from "@testing-library/react"; |
| 5 | +import { Icons } from "../constants/icons"; |
| 6 | +import { IconUtils } from "../../utilities/icon-utils"; |
| 7 | +import { SvgIcon } from "../interfaces/svg-icon"; |
| 8 | +import { getSvgIconByType } from "../constants/svg-icons"; |
| 9 | +import { Icon } from "../icons/icon"; |
2 | 10 |
|
3 | 11 | describe("HeadingIcon", () => { |
4 | | - test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/14", () => {}); |
| 12 | + let registeredIcon: SvgIcon; |
| 13 | + |
| 14 | + beforeEach(() => { |
| 15 | + IconUtils.clearRegistry(); |
| 16 | + registeredIcon = getSvgIconByType(Icons.ChevronUp); |
| 17 | + IconUtils.registerSvgIcon(registeredIcon); |
| 18 | + }); |
| 19 | + |
| 20 | + test("when default props, renders Heading with icon", () => { |
| 21 | + // Arrange |
| 22 | + const expected = faker.random.words(); |
| 23 | + |
| 24 | + // Act |
| 25 | + const { getByText } = render( |
| 26 | + <HeadingIcon type={registeredIcon.type}>{expected}</HeadingIcon> |
| 27 | + ); |
| 28 | + |
| 29 | + // Assert |
| 30 | + expect(getByText(expected)).not.toBeNil(); |
| 31 | + }); |
| 32 | + |
| 33 | + test("when type prop set and icon exists, renders Heading with set icon", () => { |
| 34 | + // Arrange |
| 35 | + const testHeading = faker.random.words(); |
| 36 | + |
| 37 | + // Act |
| 38 | + const { container } = render( |
| 39 | + <HeadingIcon type={registeredIcon.type}>{testHeading}</HeadingIcon> |
| 40 | + ); |
| 41 | + const svgIcon = container.getElementsByTagName("svg"); |
| 42 | + |
| 43 | + // Assert |
| 44 | + expect(svgIcon).toHaveLength(1); |
| 45 | + }); |
| 46 | + |
| 47 | + test("when type prop set and icon does not exist, renders Heading with bare icon <i>", () => { |
| 48 | + // Arrange |
| 49 | + const expected = faker.random.words(); |
| 50 | + |
| 51 | + // Act |
| 52 | + const { container } = render( |
| 53 | + <HeadingIcon type={Icons.Lightbulb}>{expected}</HeadingIcon> |
| 54 | + ); |
| 55 | + const svgIcon = container.getElementsByTagName("svg"); |
| 56 | + const bareIcon = container.getElementsByTagName("i"); |
| 57 | + |
| 58 | + // Assert |
| 59 | + expect(svgIcon).toHaveLength(0); |
| 60 | + expect(bareIcon).toHaveLength(1); |
| 61 | + }); |
5 | 62 | }); |
0 commit comments