Skip to content

Commit 80c2af1

Browse files
committed
Added additional tests to make up for lost coverage on altered components
1 parent 26ed2a7 commit 80c2af1

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

src/atoms/anchors/anchor.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { act, render, wait, fireEvent } from "@testing-library/react";
33
import { Anchor } from "./anchor";
44
import faker from "faker";
55
import { MemoryRouter } from "react-router-dom";
6+
import { Icons } from "../constants/icons";
67

78
describe("Anchor", () => {
89
it("when default props, renders link with correct url", async () => {
@@ -105,4 +106,24 @@ describe("Anchor", () => {
105106
).not.toBeNull();
106107
});
107108
});
109+
110+
it("when icon prop is set, renders link with icon tag", async () => {
111+
// Arrange
112+
const expected = `/some/random/path/${faker.random.word()}`;
113+
const icon = Icons.Close;
114+
115+
// Act
116+
const { container } = render(
117+
<MemoryRouter>
118+
<Anchor icon={icon} to={expected}>Link</Anchor>
119+
</MemoryRouter>
120+
);
121+
122+
const result = container.getElementsByTagName("a")[0].firstChild.nodeName;
123+
124+
// Assert
125+
await wait(() => {
126+
expect(result).toBe("I");
127+
});
128+
});
108129
});

src/atoms/forms/text-input.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { TextInput } from "./text-input";
33
import faker from "faker";
44
import { render, fireEvent } from "@testing-library/react";
55
import uuid from "uuid";
6+
import { Icons } from "../constants/icons";
67

78
describe("TextInput", () => {
89
test("when default props, renders input", () => {
@@ -61,4 +62,19 @@ describe("TextInput", () => {
6162
maximumLength.toString()
6263
);
6364
});
65+
66+
test("when icon prop has value, renders input with icon tag", () => {
67+
// Arrange
68+
const icon = Icons.Checkmark;
69+
70+
// Act
71+
const { container } = render(
72+
<TextInput icon={icon} onChange={() => {}} id={uuid()} />
73+
);
74+
75+
const result = container.getElementsByClassName("c-text-input")[0].firstChild.nodeName;
76+
77+
// Assert
78+
expect(result).toBe("I");
79+
});
6480
});

src/atoms/typography/heading.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React from "react";
22
import faker from "faker";
33
import { Heading } from "./heading";
44
import { render } from "@testing-library/react";
5+
import { Icon } from "../icons/icon";
6+
import { Icons } from "../constants/icons";
57

68
describe("Heading", () => {
79
test("when default props, renders heading", () => {
@@ -29,4 +31,20 @@ describe("Heading", () => {
2931
// Assert
3032
expect(result[0]).not.toBeNil();
3133
});
34+
35+
test("when icon prop has value, renders with icon tag", () => {
36+
// Act
37+
const randomText = faker.random.words();
38+
const icon = Icons.Checkmark;
39+
40+
// Arrange
41+
const { container } = render(
42+
<Heading icon={icon}>{randomText}</Heading>
43+
);
44+
45+
const result = container.getElementsByClassName("c-heading")[0].firstChild.nodeName;
46+
47+
// Assert
48+
expect(result).toBe("I");
49+
});
3250
});

0 commit comments

Comments
 (0)