Skip to content

Commit 325c24b

Browse files
committed
Added test coverage to anchor-with-icon to fix issue #4
1 parent 4443e3f commit 325c24b

1 file changed

Lines changed: 74 additions & 1 deletion

File tree

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,78 @@
11
import React from "react";
2+
import { MemoryRouter } from "react-router-dom";
3+
import { render } from "@testing-library/react";
4+
import { AnchorWithIcon } from "./anchor-with-icon";
5+
import { Icons } from "../constants/icons";
6+
import faker from "faker";
7+
import { SvgIcon } from "../interfaces/svg-icon";
8+
import { IconUtils } from "../../utilities/icon-utils";
9+
import { getSvgIconByType } from "../constants/svg-icons";
10+
import { ButtonStyles } from "../constants/button-styles";
211

312
describe("AnchorWithIcon", () => {
4-
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/4", () => {});
13+
let registeredIcon: SvgIcon;
14+
15+
beforeEach(() => {
16+
IconUtils.clearRegistry();
17+
registeredIcon = getSvgIconByType(Icons.ChevronUp);
18+
IconUtils.registerSvgIcon(registeredIcon);
19+
});
20+
21+
test("when default props, renders icon with children", async () => {
22+
// Arrange
23+
const expected = faker.random.words();
24+
25+
// Act
26+
const { container, getByText } = render(
27+
<MemoryRouter>
28+
<AnchorWithIcon icon={registeredIcon.type} to="/test">
29+
{expected}
30+
</AnchorWithIcon>
31+
</MemoryRouter>
32+
);
33+
34+
// Assert
35+
expect(container.querySelector("svg")).not.toBeNull();
36+
expect(getByText(expected)).not.toBeNull();
37+
});
38+
39+
it("when accessibleText provided, renders child accessible span", () => {
40+
// Arrange
41+
const expected = faker.random.words();
42+
43+
// Act
44+
const { getByText } = render(
45+
<MemoryRouter>
46+
<AnchorWithIcon
47+
accessibleText={expected}
48+
icon={registeredIcon.type}
49+
to="/test">
50+
{faker.random.words()}
51+
</AnchorWithIcon>
52+
</MemoryRouter>
53+
);
54+
55+
// Assert
56+
expect(getByText(expected)).not.toBeUndefined();
57+
});
58+
59+
test("when style provided, renders with className set", async () => {
60+
// Arrange
61+
const expected = ButtonStyles.Anchor;
62+
63+
// Act
64+
const { container } = render(
65+
<MemoryRouter>
66+
<AnchorWithIcon
67+
icon={registeredIcon.type}
68+
style={expected}
69+
to="/test">
70+
{faker.random.words()}
71+
</AnchorWithIcon>
72+
</MemoryRouter>
73+
);
74+
75+
// Assert
76+
expect(container.firstChild.getAttribute("class")).toContain(expected);
77+
});
578
});

0 commit comments

Comments
 (0)