Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src/molecules/lists/unordered-list.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from "react";
import { render } from "@testing-library/react";
import { UnorderedList } from "./unordered-list";
import { UnorderedList, UnorderedListIconClassName } from "./unordered-list";
import faker from "faker";
import { Icons } from "../../atoms/constants/icons";

describe("UnorderedList", () => {
test("when default props, renders items", () => {
Expand All @@ -14,4 +15,38 @@ describe("UnorderedList", () => {
// Assert
expect(getByText(expected)).not.toBeNull();
});

test("when cssClassName prop provided, renders with class name", () => {
// Arrange
const expected = faker.random.words();
const cssClassNameTest = "cssClassNameTest";

// Act
const { container } = render(
<UnorderedList
listItems={[expected]}
cssClassName={cssClassNameTest}
/>
);
const result = container.querySelector("." + cssClassNameTest);

// Assert
expect(result).not.toBeNil();
});

test(`when default props and include icon, renders with class name ${UnorderedListIconClassName}`, () => {
// Arrange
const expected = faker.random.words();

// Act
const { container } = render(
<UnorderedList listItems={[expected]} listIcon={Icons.Checkmark} />
);
const result = container.querySelector(
"." + UnorderedListIconClassName
);

// Assert
expect(result).not.toBeNil();
});
});
10 changes: 9 additions & 1 deletion src/molecules/lists/unordered-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import React from "react";
import { Icons } from "../../atoms/constants/icons";
import { StringUtils } from "andculturecode-javascript-core";

// -------------------------------------------------------------------------------------------------
// #region Constants
// -------------------------------------------------------------------------------------------------

export const UnorderedListIconClassName = "-has-icon";
Comment thread
wintondeshong marked this conversation as resolved.

// #endregion Constants

// -----------------------------------------------------------------------------------------
// #region Interfaces
// -----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -29,7 +37,7 @@ const UnorderedList: React.FC<UnorderedListProps> = (
}

if (props.listIcon != null) {
cssClassNames.push("-has-icon");
cssClassNames.push(UnorderedListIconClassName);
cssClassNames.push(props.listIcon);
}

Expand Down