Skip to content

Commit 4389139

Browse files
author
Said Shah
committed
Updated tests based on PR comments
1 parent 6513f3c commit 4389139

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/molecules/link-card/link-card.test.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from "react";
22
import faker from "faker";
3-
import { LinkCard } from "./link-card";
3+
import { LinkCard, IconClassName } from "./link-card";
44
import { TestUtils } from "../../tests/test-utils";
55
import { LinkCardTypes } from "../constants/link-card-types";
66

77
describe("LinkCard", () => {
8-
test("When default props, renders LinkCard", () => {
8+
test("when default props, renders LinkCard", () => {
99
// Arrange
1010
const expected = faker.random.words();
1111
const label = faker.random.words();
@@ -19,7 +19,7 @@ describe("LinkCard", () => {
1919
expect(getByText(expected)).not.toBeNull();
2020
});
2121

22-
test("When type prop is button, renders LinkCard with button", () => {
22+
test("when type prop is button, renders LinkCardTypes.Button", () => {
2323
// Arrange
2424
const expected = faker.random.words();
2525
const label = faker.random.words();
@@ -35,11 +35,10 @@ describe("LinkCard", () => {
3535

3636
// Assert
3737
expect(result).not.toBeNull();
38-
expect(result.classList).toContain("c-button");
3938
expect(container.innerHTML).toContain("button");
4039
});
4140

42-
test("When default props and include icon, renders with class name -with-icon", () => {
41+
test("when default props and include icon, renders with class name -with-icon", () => {
4342
// Arrange
4443
const expected = faker.random.words();
4544
const label = faker.random.words();
@@ -50,10 +49,10 @@ describe("LinkCard", () => {
5049
{expected}
5150
</LinkCard>
5251
);
53-
const result = container.getElementsByClassName("-with-icon")[0];
52+
const result = container.getElementsByClassName(IconClassName)[0];
5453

5554
// Assert
5655
expect(result).not.toBeNull();
57-
expect(result.classList).toContain("-with-icon");
56+
expect(result.classList).toContain(IconClassName);
5857
});
5958
});

src/molecules/link-card/link-card.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ParagraphSizes } from "../../atoms/constants/paragraph-sizes";
1313
// -------------------------------------------------------------------------------------------------
1414

1515
const COMPONENT_CLASS = "c-link-card";
16+
export const IconClassName = "-with-icon";
1617

1718
// #endregion Constants
1819

@@ -39,7 +40,7 @@ export interface LinkCardProps {
3940
const LinkCard: React.FC<LinkCardProps> = (props: LinkCardProps) => {
4041
const cssClassNames = [COMPONENT_CLASS];
4142
if (props.includeIcon) {
42-
cssClassNames.push("-with-icon");
43+
cssClassNames.push(IconClassName);
4344
}
4445

4546
const cssClassNamesFlat = cssClassNames.join(" ");

src/tests/test-utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { MemoryRouter } from "react-router-dom";
22
import { render } from "@testing-library/react";
3+
import { ReactElement } from "react";
34

45
// -----------------------------------------------------------------------------------------
56
// #region Functions
@@ -13,7 +14,7 @@ import { render } from "@testing-library/react";
1314
* @returns {ReactComponent}
1415
*/
1516

16-
const _renderWithRouter = (ui, { route = "/" } = {}) => {
17+
const _renderWithRouter = (ui: ReactElement, route: string = "/") => {
1718
window.history.pushState({}, "Test page", route);
1819

1920
return render(ui, { wrapper: MemoryRouter });

0 commit comments

Comments
 (0)