Skip to content

Commit 790986c

Browse files
author
Said Shah
committed
Updated tests
1 parent d75e17a commit 790986c

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/atoms/typography/heading-icon.test.tsx

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,60 @@ import faker from "faker";
33
import { HeadingIcon } from "./heading-icon";
44
import { render } from "@testing-library/react";
55
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";
610

711
describe("HeadingIcon", () => {
8-
test("when default props, renders Heading with Icon", () => {
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", () => {
921
// Arrange
1022
const expected = faker.random.words();
1123

1224
// Act
1325
const { getByText } = render(
14-
<HeadingIcon type={Icons.Checkmark}>{expected}</HeadingIcon>
26+
<HeadingIcon type={registeredIcon.type}>{expected}</HeadingIcon>
1527
);
1628

1729
// Assert
1830
expect(getByText(expected)).not.toBeNil();
1931
});
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+
});
2062
});

src/atoms/typography/heading.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe("Heading", () => {
1515
expect(getByText(expected)).not.toBeNil();
1616
});
1717

18-
test("when given cssClassName prop, renders with given class name", () => {
18+
test("when cssClassName prop has value, renders with class name", () => {
1919
// Act
2020
const randomText = faker.random.words();
2121
const testClassName = "testClassName";

0 commit comments

Comments
 (0)