|
| 1 | +import React from "react"; |
| 2 | +import { render, wait } from "@testing-library/react"; |
| 3 | +import { Button } from "./button"; |
| 4 | +import faker from "faker"; |
| 5 | +import { ButtonSizes } from "../constants/button-sizes"; |
| 6 | +import { ButtonStyles } from "../constants/button-styles"; |
| 7 | + |
| 8 | +describe("Button", () => { |
| 9 | + it("when default props, renders button children", async () => { |
| 10 | + // Arrange |
| 11 | + const expected = faker.random.words(); |
| 12 | + |
| 13 | + // Act |
| 14 | + const { getByText } = render(<Button>{expected}</Button>); |
| 15 | + |
| 16 | + // Assert |
| 17 | + expect(getByText(expected)).not.toBeNull(); |
| 18 | + }); |
| 19 | + |
| 20 | + it("when accessibleText provided, renders child accessible span", () => { |
| 21 | + // Arrange |
| 22 | + const expected = faker.random.word(); |
| 23 | + |
| 24 | + // Act |
| 25 | + const { getByText } = render( |
| 26 | + <Button accessibleText={expected}></Button> |
| 27 | + ); |
| 28 | + |
| 29 | + // Assert |
| 30 | + expect(getByText(expected)).not.toBeUndefined(); |
| 31 | + }); |
| 32 | + |
| 33 | + it("when cssClassName provided, adds provided className to button", () => { |
| 34 | + // Arrange |
| 35 | + const expected = faker.random.word(); |
| 36 | + |
| 37 | + // Act |
| 38 | + const { container } = render(<Button cssClassName={expected}></Button>); |
| 39 | + |
| 40 | + // Assert |
| 41 | + expect(container.firstChild.className).toContain(expected); |
| 42 | + }); |
| 43 | + |
| 44 | + it("when size provided, adds size className to button", () => { |
| 45 | + // Arrange |
| 46 | + const expected = ButtonSizes.Large; |
| 47 | + |
| 48 | + // Act |
| 49 | + const { container } = render(<Button size={expected}></Button>); |
| 50 | + |
| 51 | + // Assert |
| 52 | + expect(container.firstChild.className).toContain(`-${expected}`); |
| 53 | + }); |
| 54 | + |
| 55 | + it(`when style of '${ButtonStyles.None}', has className of only 'none'`, () => { |
| 56 | + // Arrange |
| 57 | + const expected = ButtonStyles.None; |
| 58 | + |
| 59 | + // Act |
| 60 | + const { container } = render(<Button style={expected}></Button>); |
| 61 | + |
| 62 | + // Assert |
| 63 | + expect(container.firstChild.className).toBe(`-${expected}`); |
| 64 | + }); |
| 65 | + |
| 66 | + it("when style provided, adds style className to button", () => { |
| 67 | + // Arrange |
| 68 | + const expected = ButtonStyles.Destructive; |
| 69 | + |
| 70 | + // Act |
| 71 | + const { container } = render(<Button style={expected}></Button>); |
| 72 | + |
| 73 | + // Assert |
| 74 | + expect(container.firstChild.className).toContain(`-${expected}`); |
| 75 | + }); |
| 76 | +}); |
0 commit comments