|
1 | 1 | import React from "react"; |
| 2 | +import faker from "faker"; |
| 3 | +import { |
| 4 | + ProgressBar, |
| 5 | + ProgressBarStyles, |
| 6 | + ProgressBarErrorClass, |
| 7 | +} from "./progress-bar"; |
| 8 | +import { render, getByTestId } from "@testing-library/react"; |
2 | 9 |
|
3 | 10 | describe("ProgressBar", () => { |
4 | | - test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/13", () => {}); |
| 11 | + test("when default props, renders progress bar", () => { |
| 12 | + // Arrange |
| 13 | + const expected = "dataTestId"; |
| 14 | + |
| 15 | + // Act |
| 16 | + const { getByTestId } = render( |
| 17 | + <ProgressBar value={faker.random.number(100)} testId={expected} /> |
| 18 | + ); |
| 19 | + |
| 20 | + // Assert |
| 21 | + expect(getByTestId(expected)).not.toBeNil(); |
| 22 | + }); |
| 23 | + |
| 24 | + test("when cssClassName set, renders with class name", () => { |
| 25 | + // Arrange |
| 26 | + const testCssClassName = "testCssClassName"; |
| 27 | + |
| 28 | + // Act |
| 29 | + const { container } = render( |
| 30 | + <ProgressBar |
| 31 | + value={faker.random.number(100)} |
| 32 | + cssClassName={testCssClassName} |
| 33 | + /> |
| 34 | + ); |
| 35 | + const result = container.getElementsByClassName(testCssClassName); |
| 36 | + |
| 37 | + // Assert |
| 38 | + expect(result).toHaveLength(1); |
| 39 | + }); |
| 40 | + |
| 41 | + test.each` |
| 42 | + style |
| 43 | + ${ProgressBarStyles.Thick} |
| 44 | + ${ProgressBarStyles.Thin} |
| 45 | + `("when style prop set, renders with $style", ({ style }) => { |
| 46 | + // Arrange |
| 47 | + const expected = faker.random.number(100); |
| 48 | + |
| 49 | + // Act |
| 50 | + const { container } = render( |
| 51 | + <ProgressBar value={expected} style={style} /> |
| 52 | + ); |
| 53 | + const result = container.getElementsByClassName(style); |
| 54 | + |
| 55 | + // Assert |
| 56 | + expect(result).toHaveLength(1); |
| 57 | + }); |
| 58 | + |
| 59 | + test(`when isErrored prop set, renders with ${ProgressBarErrorClass} class name`, () => { |
| 60 | + // Arrange |
| 61 | + const expected = faker.random.number(100); |
| 62 | + |
| 63 | + // Act |
| 64 | + const { container } = render( |
| 65 | + <ProgressBar value={expected} isErrored={true} /> |
| 66 | + ); |
| 67 | + const result = container.getElementsByClassName(ProgressBarErrorClass); |
| 68 | + |
| 69 | + // Assert |
| 70 | + expect(result).toHaveLength(1); |
| 71 | + }); |
| 72 | + |
| 73 | + test(`when value prop set > 100, renders with value 100`, () => { |
| 74 | + // Arrange |
| 75 | + const incorrectValue = 110; |
| 76 | + const maximumValue = 100; |
| 77 | + const dataTestId = "dataTestId"; |
| 78 | + |
| 79 | + // Act |
| 80 | + const { getByTestId } = render( |
| 81 | + <ProgressBar value={incorrectValue} testId={dataTestId} /> |
| 82 | + ); |
| 83 | + |
| 84 | + // Assert |
| 85 | + expect(getByTestId(dataTestId).innerHTML).toContain(maximumValue); |
| 86 | + expect(getByTestId(dataTestId).innerHTML).not.toContain(incorrectValue); |
| 87 | + }); |
| 88 | + |
| 89 | + test(`when value prop set < 0, renders with value 0`, () => { |
| 90 | + // Arrange |
| 91 | + const incorrectValue = -10; |
| 92 | + const minimumValue = 0; |
| 93 | + const dataTestId = "dataTestId"; |
| 94 | + |
| 95 | + // Act |
| 96 | + const { getByTestId } = render( |
| 97 | + <ProgressBar value={incorrectValue} testId={dataTestId} /> |
| 98 | + ); |
| 99 | + |
| 100 | + // Assert |
| 101 | + expect(getByTestId(dataTestId).innerHTML).toContain(minimumValue); |
| 102 | + expect(getByTestId(dataTestId).innerHTML).not.toContain(incorrectValue); |
| 103 | + }); |
5 | 104 | }); |
0 commit comments