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