-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(color-picker): add tests for ColorPicker
- Loading branch information
Showing
3 changed files
with
81 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import ColorPicker from '../../src/components/ColorPicker'; | ||
|
||
describe('<ColorPicker>', () => { | ||
it('should render a basic ColorPicker', () => { | ||
render(<ColorPicker />); | ||
const colorPicker = screen.getByTestId('color-picker'); | ||
expect(colorPicker).toBeTruthy(); | ||
}); | ||
|
||
it('should render a basic ColorPicker with a loading spinner', () => { | ||
render(<ColorPicker isLoading />); | ||
const colorPicker = screen.getByTestId('color-picker'); | ||
expect(colorPicker).toBeTruthy(); | ||
const spinner = screen.getByTestId('spinner'); | ||
expect(spinner).toBeTruthy(); | ||
}); | ||
|
||
it('should render a basic ColorPicker with input', () => { | ||
render(<ColorPicker showInput />); | ||
const colorPicker = screen.getByTestId('color-picker'); | ||
expect(colorPicker).toBeTruthy(); | ||
const inputElement = screen.getByTestId('input-element'); | ||
expect(inputElement).toBeTruthy(); | ||
}); | ||
|
||
it('should render a basic ColorPicker with an input and a loading spinner', () => { | ||
render(<ColorPicker showInput isLoading />); | ||
const colorPicker = screen.getByTestId('color-picker'); | ||
expect(colorPicker).toBeTruthy(); | ||
const inputElement = screen.getByTestId('input-element'); | ||
expect(inputElement).toBeTruthy(); | ||
const spinner = screen.getByTestId('spinner'); | ||
expect(spinner).toBeTruthy(); | ||
}); | ||
|
||
it('should render a basic ColorPicker call mockFunction onChangePicker when a color is changed on popover', () => { | ||
const onChangePickerFunction = jest.fn(); | ||
const color = 'BBBCCC'; | ||
const { container } = render( | ||
<ColorPicker onChangePicker={onChangePickerFunction} /> | ||
); | ||
const colorPicker = screen.getByTestId('color-picker'); | ||
fireEvent.click(colorPicker); | ||
const inputHex = container.querySelector('#rc-editable-input-1'); | ||
fireEvent.change(inputHex, { target: { value: color } }); | ||
expect(screen.getByDisplayValue(color)).toBeTruthy(); | ||
}); | ||
|
||
it('should render a basic ColorPicker call mockFunction onChangeInput when a color is changed on input', () => { | ||
const onChangeInputFunction = jest.fn(); | ||
const color = 'BBBCCC'; | ||
render(<ColorPicker showInput onChangeInput={onChangeInputFunction} />); | ||
const inputColorPicker = screen.getByTestId('input-element'); | ||
fireEvent.change(inputColorPicker, { target: { value: color } }); | ||
expect(screen.getByDisplayValue(color)).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters