Skip to content

Commit e77c8b6

Browse files
Merge pull request #56 from SaidShah/add-tests-for-molecules-unordered-list
Added tests for unordered list
2 parents a71e0a9 + 4fadecb commit e77c8b6

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/molecules/lists/unordered-list.test.tsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from "react";
22
import { render } from "@testing-library/react";
3-
import { UnorderedList } from "./unordered-list";
3+
import { UnorderedList, UnorderedListIconClassName } from "./unordered-list";
44
import faker from "faker";
5+
import { Icons } from "../../atoms/constants/icons";
56

67
describe("UnorderedList", () => {
78
test("when default props, renders items", () => {
@@ -14,4 +15,38 @@ describe("UnorderedList", () => {
1415
// Assert
1516
expect(getByText(expected)).not.toBeNull();
1617
});
18+
19+
test("when cssClassName prop provided, renders with class name", () => {
20+
// Arrange
21+
const expected = faker.random.words();
22+
const cssClassNameTest = "cssClassNameTest";
23+
24+
// Act
25+
const { container } = render(
26+
<UnorderedList
27+
listItems={[expected]}
28+
cssClassName={cssClassNameTest}
29+
/>
30+
);
31+
const result = container.querySelector("." + cssClassNameTest);
32+
33+
// Assert
34+
expect(result).not.toBeNil();
35+
});
36+
37+
test(`when default props and include icon, renders with class name ${UnorderedListIconClassName}`, () => {
38+
// Arrange
39+
const expected = faker.random.words();
40+
41+
// Act
42+
const { container } = render(
43+
<UnorderedList listItems={[expected]} listIcon={Icons.Checkmark} />
44+
);
45+
const result = container.querySelector(
46+
"." + UnorderedListIconClassName
47+
);
48+
49+
// Assert
50+
expect(result).not.toBeNil();
51+
});
1752
});

src/molecules/lists/unordered-list.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import React from "react";
22
import { Icons } from "../../atoms/constants/icons";
33
import { StringUtils } from "andculturecode-javascript-core";
44

5+
// -------------------------------------------------------------------------------------------------
6+
// #region Constants
7+
// -------------------------------------------------------------------------------------------------
8+
9+
export const UnorderedListIconClassName = "-has-icon";
10+
11+
// #endregion Constants
12+
513
// -----------------------------------------------------------------------------------------
614
// #region Interfaces
715
// -----------------------------------------------------------------------------------------
@@ -29,7 +37,7 @@ const UnorderedList: React.FC<UnorderedListProps> = (
2937
}
3038

3139
if (props.listIcon != null) {
32-
cssClassNames.push("-has-icon");
40+
cssClassNames.push(UnorderedListIconClassName);
3341
cssClassNames.push(props.listIcon);
3442
}
3543

0 commit comments

Comments
 (0)