|
| 1 | +import * as fields from '../../../../../assets/src/index.jsx' |
| 2 | +import '../../../../../assets/src/index.jsx' |
| 3 | +import { render } from '@testing-library/react' |
| 4 | +import { |
| 5 | + rendersWithMinimal, |
| 6 | + rendersWithoutLabelThrowWarning, |
| 7 | + rendersLabelAndDescription |
| 8 | +} from '../../../utils/fields.js' |
| 9 | + |
| 10 | +describe('Color component', () => { |
| 11 | + |
| 12 | + it('renders with minimal config', () => rendersWithMinimal({ type: 'color-picker', expectedClass: 'tf-color' })) |
| 13 | + it('renders when no label but throws a warning', () => rendersWithoutLabelThrowWarning({ type: 'color-picker', expectedClass: 'tf-color' })) |
| 14 | + it('renders label and description', () => rendersLabelAndDescription({ type: 'color-picker', expectedClass: 'tf-color' })) |
| 15 | + |
| 16 | + test.each([ |
| 17 | + // Valid initial value |
| 18 | + { initialValue: { value: '#00FFFFFF' }, expectedValue: '#00FFFFFF' }, |
| 19 | + // Invalid initial value, will default to #FFFFFFFF |
| 20 | + { initialValue: '', expectedValue: '#FFFFFFFF' }, |
| 21 | + { initialValue: {}, expectedValue: '#FFFFFFFF' }, |
| 22 | + { initialValue: { value: '' }, expectedValue: '#FFFFFFFF' }, |
| 23 | + { initialValue: { something: '#00FFFFFF' }, expectedValue: '#FFFFFFFF' }, |
| 24 | + ])('format initial value (%p)', ({ initialValue, expectedValue }) => { |
| 25 | + |
| 26 | + const { container } = render( |
| 27 | + fields.render({ |
| 28 | + type : 'color-picker', |
| 29 | + value : initialValue |
| 30 | + } |
| 31 | + )) |
| 32 | + |
| 33 | + const value = container.querySelector('.tf-color-container input[type="text"]').value |
| 34 | + expect(value).toBe(expectedValue) |
| 35 | + }) |
| 36 | + |
| 37 | +}) |
0 commit comments