-
-
Notifications
You must be signed in to change notification settings - Fork 486
Expand file tree
/
Copy pathsemantic.test.tsx
More file actions
162 lines (136 loc) · 4.84 KB
/
semantic.test.tsx
File metadata and controls
162 lines (136 loc) · 4.84 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import React from 'react';
import { render } from '@testing-library/react';
import Select from '../src';
describe('Select Semantic Styles', () => {
const defaultProps = {
prefixCls: 'rc-select',
displayValues: [],
emptyOptions: true,
id: 'test',
onDisplayValuesChange: () => {},
onSearch: () => {},
searchValue: '',
};
it('should apply semantic classNames correctly', () => {
const classNames = {
prefix: 'custom-prefix',
suffix: 'custom-suffix',
input: 'custom-input',
clear: 'custom-clear',
placeholder: 'custom-placeholder',
content: 'custom-content',
item: 'custom-item',
itemContent: 'custom-item-content',
itemRemove: 'custom-item-remove',
};
const { container } = render(
<Select
{...defaultProps}
classNames={classNames}
placeholder="Test placeholder"
prefix={<span>Prefix</span>}
suffix={<span>Suffix</span>}
/>,
);
// Test prefix className
expect(container.querySelector('.rc-select-prefix')).toHaveClass('custom-prefix');
// Test suffix className
expect(container.querySelector('.rc-select-suffix')).toHaveClass('custom-suffix');
// Test input className
expect(container.querySelector('.rc-select-input')).toHaveClass('custom-input');
// Test content className
expect(container.querySelector('.rc-select-content')).toHaveClass('custom-content');
// Test placeholder className
expect(container.querySelector('.rc-select-placeholder')).toHaveClass('custom-placeholder');
});
it('should apply semantic styles correctly', () => {
const styles = {
prefix: { color: 'red' },
suffix: { color: 'blue' },
input: { fontSize: '16px' },
clear: { cursor: 'pointer' },
placeholder: { opacity: 0.6 },
content: { padding: '4px' },
item: { margin: '2px' },
itemContent: { fontWeight: 'bold' },
itemRemove: { background: 'transparent' },
};
const { container } = render(
<Select
{...defaultProps}
styles={styles}
placeholder="Test placeholder"
prefix={<span>Prefix</span>}
suffix={<span>Suffix</span>}
/>,
);
// Test prefix style
expect(container.querySelector('.rc-select-prefix')).toHaveStyle({ color: 'red' });
// Test suffix style
expect(container.querySelector('.rc-select-suffix')).toHaveStyle({ color: 'blue' });
// Test input style
expect(container.querySelector('.rc-select-input')).toHaveStyle({ fontSize: '16px' });
// Test content style
expect(container.querySelector('.rc-select-content')).toHaveStyle({ padding: '4px' });
// Test placeholder style
expect(container.querySelector('.rc-select-placeholder')).toHaveStyle({ opacity: 0.6 });
});
it('should apply item semantic styles in multiple mode', () => {
const classNames = {
item: 'custom-item',
itemContent: 'custom-item-content',
itemRemove: 'custom-item-remove',
};
const styles = {
item: { margin: '2px' },
itemContent: { fontWeight: 'bold' },
itemRemove: { background: 'transparent' },
};
const displayValues = [
{ key: '1', label: 'Option 1', value: '1' },
{ key: '2', label: 'Option 2', value: '2' },
];
const { container } = render(
<Select
{...defaultProps}
mode="multiple"
value={displayValues}
classNames={classNames}
styles={styles}
/>,
);
// Test item className and style
const items = container.querySelectorAll('.rc-select-selection-item');
expect(items[0]).toHaveClass('custom-item');
expect(items[0]).toHaveStyle({ margin: '2px' });
// Test item content className and style
const itemContents = container.querySelectorAll('.rc-select-selection-item-content');
expect(itemContents[0]).toHaveClass('custom-item-content');
expect(itemContents[0]).toHaveStyle({ fontWeight: 'bold' });
// Test item remove className and style
const removeButtons = container.querySelectorAll('.rc-select-selection-item-remove');
expect(removeButtons[0]).toHaveClass('custom-item-remove');
expect(removeButtons[0]).toHaveStyle({ background: 'transparent' });
});
it('should apply clear icon semantic styles when allowClear is enabled', () => {
const classNames = {
clear: 'custom-clear',
};
const styles = {
clear: { cursor: 'pointer' },
};
const { container } = render(
<Select
{...defaultProps}
value={[{ key: '1', label: 'Option 1', value: '1' }]}
allowClear
classNames={classNames}
styles={styles}
/>,
);
// Test clear icon className and style
const clearIcon = container.querySelector('.rc-select-clear');
expect(clearIcon).toHaveClass('custom-clear');
expect(clearIcon).toHaveStyle({ cursor: 'pointer' });
});
});