Skip to content

Commit

Permalink
test(color-picker): add test for color-picker alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWeilian committed Jan 17, 2023
1 parent 815a744 commit 7620834
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/color-picker/__tests__/color-picker.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import React from 'react';
import React, { useState } from 'react';
import { render, fireEvent } from '@test/utils';
import ColorPickerPanel from '../ColorPickerPanel';
import ColorPicker from '../ColorPicker';

describe('ColorPicker 组件测试', () => {
test('ColorPickerPanel 测试', () => {
const { queryByText } = render(<ColorPickerPanel defaultValue={'#0052d9'} />);
expect(queryByText('最近使用颜色')).toBeInTheDocument();
});

test('ColorPicker Trigger 测试', () => {
const { container } = render(<ColorPicker defaultValue="#0052d9" />);
expect(container.querySelector('.t-input__inner').value).toBe('#0052d9');
expect(container.querySelector('.t-input__inner')).toHaveValue('#0052d9');
});

test('ColorPicker 线性渐变 测试', () => {
Expand All @@ -27,3 +22,32 @@ describe('ColorPicker 组件测试', () => {
expect(document.querySelector('.t-color-picker__gradient')).toBeInTheDocument();
});
});

describe('ColorPickerPanel 组件测试', () => {
test('ColorPickerPanel 测试', () => {
const { queryByText } = render(<ColorPickerPanel defaultValue={'#0052d9'} />);
expect(queryByText('最近使用颜色')).toBeInTheDocument();
});

test('enableAlpha 开启透明通道', () => {
const btnText = 'changeAlpha';
const [defaultValue, changeValue] = ['rgba(0, 82, 217, 1)', 'rgba(0, 82, 217, 0.32)'];
const TestComponent = () => {
const [value, setValue] = useState(defaultValue);
const onClick = () => {
setValue(changeValue);
};
return (
<>
<button onClick={onClick}>{btnText}</button>
<ColorPickerPanel enableAlpha value={value} />
</>
);
};
const { container, getByText } = render(<TestComponent />);
expect(container.querySelector('.t-color-picker__alpha')).toBeInTheDocument();
expect(container.querySelector('.t-color-picker__sliders-preview-inner')).toHaveStyle({ background: defaultValue });
fireEvent.click(getByText(btnText));
expect(container.querySelector('.t-color-picker__sliders-preview-inner')).toHaveStyle({ background: changeValue });
});
});

0 comments on commit 7620834

Please sign in to comment.