Skip to content

Commit 0fc5615

Browse files
Issue #14 Backfill tests for Atoms/Heading and Atoms/HeadingIcon
Add tests for atoms heading and atomss heading icom
2 parents 6648d7d + 790986c commit 0fc5615

File tree

2 files changed

+86
-2
lines changed

2 files changed

+86
-2
lines changed
Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,62 @@
11
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";
210

311
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+
});
562
});
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
import React from "react";
2+
import faker from "faker";
3+
import { Heading } from "./heading";
4+
import { render } from "@testing-library/react";
25

36
describe("Heading", () => {
4-
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/14", () => {});
7+
test("when default props, renders heading", () => {
8+
// Assert
9+
const expected = faker.random.words();
10+
11+
// Act
12+
const { getByText } = render(<Heading>{expected}</Heading>);
13+
14+
// Assert
15+
expect(getByText(expected)).not.toBeNil();
16+
});
17+
18+
test("when cssClassName prop has value, renders with class name", () => {
19+
// Act
20+
const randomText = faker.random.words();
21+
const testClassName = "testClassName";
22+
23+
// Arrange
24+
const { container } = render(
25+
<Heading cssClassName={testClassName}>{randomText}</Heading>
26+
);
27+
const result = container.getElementsByClassName(testClassName);
28+
29+
// Assert
30+
expect(result[0]).not.toBeNil();
31+
});
532
});

0 commit comments

Comments
 (0)