Skip to content

Commit f39743f

Browse files
author
Said Shah
committed
added tests for radio list
1 parent 2368707 commit f39743f

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import React from "react";
22
import { render } from "@testing-library/react";
3-
import { RadioList } from "./radio-list";
3+
import {
4+
RadioList,
5+
COMPONENT_CLASS,
6+
RadioListStyles,
7+
RadioListButtonStyleClassName,
8+
} from "./radio-list";
49
import faker from "faker";
510

611
describe("RadioList", () => {
@@ -16,4 +21,32 @@ describe("RadioList", () => {
1621
// Assert
1722
expect(getByText(expected)).not.toBeNull();
1823
});
24+
25+
test("when items prop is empty, radio-list returns", () => {
26+
// Arrange & Act
27+
const { container } = render(<RadioList items={[]} />);
28+
const result = container.querySelector("." + COMPONENT_CLASS);
29+
30+
// Assert
31+
expect(result).toBeNil();
32+
});
33+
34+
test(`when type prop is ${RadioListStyles.Button}, renders with class name ${RadioListButtonStyleClassName}`, () => {
35+
// Arrange
36+
const expected = faker.random.words();
37+
38+
// Act
39+
const { container } = render(
40+
<RadioList
41+
items={[<span>{expected}</span>]}
42+
style={RadioListStyles.Button}
43+
/>
44+
);
45+
const result = container.querySelector(
46+
"." + RadioListButtonStyleClassName
47+
);
48+
49+
// Assert
50+
expect(result).not.toBeNil();
51+
});
1952
});

src/molecules/lists/radio-list.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as React from "react";
22
import { UnorderedList } from "./unordered-list";
33

4-
const COMPONENT_CLASS = "c-radio-list";
4+
export const COMPONENT_CLASS = "c-radio-list";
5+
export const RadioListButtonStyleClassName = "-button-style";
56

67
export interface RadioListProps {
78
items: JSX.Element[];
@@ -22,7 +23,7 @@ const RadioList: React.FunctionComponent<RadioListProps> = (props) => {
2223

2324
const classNames = [COMPONENT_CLASS];
2425
if (style === RadioListStyles.Button) {
25-
classNames.push("-button-style");
26+
classNames.push(RadioListButtonStyleClassName);
2627
}
2728

2829
return (

0 commit comments

Comments
 (0)