-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuseCheckboxStyleProps.test.ts
More file actions
70 lines (54 loc) · 2.86 KB
/
useCheckboxStyleProps.test.ts
File metadata and controls
70 lines (54 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { renderHook } from '@testing-library/react';
import { ValidationStates } from '../../../constants';
import { type SpiritCheckboxProps } from '../../../types';
import { useCheckboxStyleProps } from '../useCheckboxStyleProps';
describe('useCheckboxStyleProps', () => {
it('should return defaults', () => {
const props = { id: 'checkbox', label: 'Label' };
const { result } = renderHook(() => useCheckboxStyleProps(props));
expect(result.current.classProps).toEqual({
root: 'Checkbox Checkbox--inputPositionStart',
text: 'Checkbox__text',
input: 'Checkbox__input',
label: 'Checkbox__label',
validationText: 'Checkbox__validationText',
});
});
it('should return required input', () => {
const props = { isRequired: true } as SpiritCheckboxProps;
const { result } = renderHook(() => useCheckboxStyleProps(props));
expect(result.current.classProps.label).toBe('Checkbox__label Checkbox__label--required');
});
it('should return hidden label', () => {
const props = { isLabelHidden: true } as SpiritCheckboxProps;
const { result } = renderHook(() => useCheckboxStyleProps(props));
expect(result.current.classProps.label).toBe('Checkbox__label Checkbox__label--hidden');
});
it('should return field as an Item', () => {
const props = { isItem: true } as SpiritCheckboxProps;
const { result } = renderHook(() => useCheckboxStyleProps(props));
expect(result.current.classProps.root).toBe('Checkbox Checkbox--inputPositionStart Checkbox--item');
});
it.each([Object.values(ValidationStates)])('should return field with %s', (state) => {
const props = { validationState: state } as SpiritCheckboxProps;
const { result } = renderHook(() => useCheckboxStyleProps(props));
expect(result.current.classProps.root).toBe(`Checkbox Checkbox--inputPositionStart Checkbox--${state}`);
});
it('should return field with inputPosition start', () => {
const props = { inputPosition: 'start' } as SpiritCheckboxProps;
const { result } = renderHook(() => useCheckboxStyleProps(props));
expect(result.current.classProps.root).toBe('Checkbox Checkbox--inputPositionStart');
});
it('should return field with inputPosition end', () => {
const props = { inputPosition: 'end' } as SpiritCheckboxProps;
const { result } = renderHook(() => useCheckboxStyleProps(props));
expect(result.current.classProps.root).toBe('Checkbox Checkbox--inputPositionEnd');
});
it('should return field with responsive inputPosition', () => {
const props = { inputPosition: { mobile: 'start', tablet: 'end', desktop: 'start' } } as SpiritCheckboxProps;
const { result } = renderHook(() => useCheckboxStyleProps(props));
expect(result.current.classProps.root).toBe(
'Checkbox Checkbox--inputPositionStart Checkbox--tablet--inputPositionEnd Checkbox--desktop--inputPositionStart',
);
});
});