Skip to content

Commit 6847f97

Browse files
author
Said Shah
committed
Added tests for dropdown button
1 parent 42f60a7 commit 6847f97

File tree

1 file changed

+86
-4
lines changed

1 file changed

+86
-4
lines changed
Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,89 @@
1-
// import React from "react";
2-
// import { render } from "@testing-library/react";
3-
// import { DropdownButton } from "./dropdown-button";
1+
import React from "react";
2+
import faker from "faker";
3+
import { ButtonSizes } from "../../atoms/constants/button-sizes";
4+
import { ButtonStyles } from "../../atoms/constants/button-styles";
5+
import { DropdownButton } from "./dropdown-button";
6+
import { render } from "@testing-library/react";
47

58
describe("DropdownButton", () => {
6-
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/21", () => {});
9+
test("when default props, renders Dropdown Button", () => {
10+
// Arrange
11+
const expected = faker.random.words();
12+
const itemOne = { component: faker.random.word(), onSelect: () => {} };
13+
const itemTwo = { component: faker.random.word(), onSelect: () => {} };
14+
15+
// Act
16+
const { getByText } = render(
17+
<DropdownButton
18+
buttonContents={expected}
19+
menuItems={[itemOne, itemTwo]}
20+
/>
21+
);
22+
23+
// Assert
24+
expect(getByText(expected)).not.toBeNil();
25+
});
26+
27+
test("when buttonClassName prop provided, renders with class name", () => {
28+
// Arrange
29+
const itemOne = { component: faker.random.word(), onSelect: () => {} };
30+
const itemTwo = { component: faker.random.word(), onSelect: () => {} };
31+
const testButtonContents = faker.random.words();
32+
const testButtonClassName = "testButtonClassName";
33+
34+
// Act
35+
const { container } = render(
36+
<DropdownButton
37+
buttonClassName={testButtonClassName}
38+
buttonContents={testButtonContents}
39+
menuItems={[itemOne, itemTwo]}
40+
/>
41+
);
42+
const result = container.getElementsByClassName(testButtonClassName);
43+
44+
// Assert
45+
expect(result).toHaveLength(1);
46+
});
47+
48+
test("when button size prop provided, renders with correct size class", () => {
49+
// Arrange
50+
const itemOne = { component: faker.random.word(), onSelect: () => {} };
51+
const itemTwo = { component: faker.random.word(), onSelect: () => {} };
52+
const testButtonContents = faker.random.words();
53+
const testButtonSize = ButtonSizes.Large;
54+
55+
// Act
56+
const { container } = render(
57+
<DropdownButton
58+
buttonContents={testButtonContents}
59+
menuItems={[itemOne, itemTwo]}
60+
size={testButtonSize}
61+
/>
62+
);
63+
const result = container.getElementsByClassName(testButtonSize);
64+
65+
// Assert
66+
expect(result).toHaveLength(1);
67+
});
68+
69+
test("when button style prop provided, renders with correct style class", () => {
70+
// Arrange
71+
const itemOne = { component: faker.random.word(), onSelect: () => {} };
72+
const itemTwo = { component: faker.random.word(), onSelect: () => {} };
73+
const testButtonContents = faker.random.words();
74+
const testButtonStyle = ButtonStyles.Destructive;
75+
76+
// Act
77+
const { container } = render(
78+
<DropdownButton
79+
buttonContents={testButtonContents}
80+
menuItems={[itemOne, itemTwo]}
81+
style={testButtonStyle}
82+
/>
83+
);
84+
const result = container.getElementsByClassName(testButtonStyle);
85+
86+
// Assert
87+
expect(result).toHaveLength(1);
88+
});
789
});

0 commit comments

Comments
 (0)