Skip to content

Commit c91c43b

Browse files
committed
test: update snapshot
1 parent 2b14e52 commit c91c43b

File tree

4 files changed

+52
-73
lines changed

4 files changed

+52
-73
lines changed

src/SelectInput/Content/SingleContent.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import useBaseProps from '../../hooks/useBaseProps';
66
import Placeholder from './Placeholder';
77
import type { SharedContentProps } from '.';
88
import SelectContext from '../../SelectContext';
9+
import { getTitle } from '../../utils/commonUtil';
910

1011
const SingleContent = React.forwardRef<HTMLInputElement, SharedContentProps>(
1112
({ inputProps }, ref) => {
1213
const { prefixCls, searchValue, activeValue, displayValues, maxLength, mode } =
1314
useSelectInputContext();
14-
const { triggerOpen } = useBaseProps();
15+
const { triggerOpen, title: rootTitle } = useBaseProps();
1516
const selectContext = React.useContext(SelectContext);
1617

1718
const [inputChanged, setInputChanged] = React.useState(false);
@@ -45,14 +46,23 @@ const SingleContent = React.forwardRef<HTMLInputElement, SharedContentProps>(
4546
restProps = {
4647
...restProps,
4748
...rest,
49+
title: getTitle(option.data),
4850
className: clsx(restProps.className, className),
4951
style: { ...restProps.style, ...style },
5052
};
5153
}
5254
}
5355

56+
if (displayValue && !restProps.title) {
57+
restProps.title = getTitle(displayValue);
58+
}
59+
60+
if (rootTitle !== undefined) {
61+
restProps.title = rootTitle;
62+
}
63+
5464
return restProps;
55-
}, [displayValue, selectContext?.flattenOptions, prefixCls, mergedSearchValue]);
65+
}, [displayValue, selectContext?.flattenOptions, prefixCls, mergedSearchValue, rootTitle]);
5666

5767
React.useEffect(() => {
5868
if (combobox) {

tests/Select.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,15 +2295,17 @@ describe('Select.Basic', () => {
22952295
it('should support title', () => {
22962296
const { container: container1 } = render(<Select defaultValue="lucy" options={[]} />);
22972297
expect(container1.querySelector('.rc-select').getAttribute('title')).toBeFalsy();
2298-
expect(container1.querySelector('.rc-select-item').getAttribute('title')).toBe('lucy');
2298+
expect(container1.querySelector('.rc-select-content-value').getAttribute('title')).toBe('lucy');
22992299
const { container: container2 } = render(<Select defaultValue="lucy" options={[]} title="" />);
23002300
expect(container2.querySelector('.rc-select').getAttribute('title')).toBeFalsy();
2301-
expect(container2.querySelector('.rc-select-item').getAttribute('title')).toBe('');
2301+
expect(container2.querySelector('.rc-select-content-value').getAttribute('title')).toBe('');
23022302
const { container: container3 } = render(
23032303
<Select defaultValue="lucy" options={[]} title="title" />,
23042304
);
23052305
expect(container3.querySelector('.rc-select').getAttribute('title')).toBe('title');
2306-
expect(container3.querySelector('.rc-select-item').getAttribute('title')).toBe('title');
2306+
expect(container3.querySelector('.rc-select-content-value').getAttribute('title')).toBe(
2307+
'title',
2308+
);
23072309
});
23082310

23092311
it('scrollbar should be left position with rtl direction', () => {

tests/__snapshots__/Select.test.tsx.snap

Lines changed: 30 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -187,48 +187,27 @@ exports[`Select.Basic render renders correctly 1`] = `
187187
class="antd select-test antd-single antd-allow-clear antd-show-search"
188188
>
189189
<div
190-
class="antd-selector"
190+
class="antd-content"
191191
>
192-
<span
193-
class="antd-selection-wrap"
192+
<div
193+
class="antd-content-value"
194+
style="visibility: visible;"
195+
title="2"
194196
>
195-
<span
196-
class="antd-selection-search"
197-
>
198-
<input
199-
aria-autocomplete="list"
200-
aria-controls="test-id_list"
201-
aria-expanded="false"
202-
aria-haspopup="listbox"
203-
aria-owns="test-id_list"
204-
autocomplete="off"
205-
class="antd-selection-search-input"
206-
id="test-id"
207-
role="combobox"
208-
type="search"
209-
value=""
210-
/>
211-
</span>
212-
<span
213-
class="antd-selection-item"
214-
title="2"
215-
>
216-
2
217-
</span>
218-
</span>
197+
2
198+
</div>
199+
<input
200+
class="antd-input"
201+
id="test-id"
202+
type="search"
203+
value=""
204+
/>
219205
</div>
220-
<span
221-
aria-hidden="true"
206+
<div
222207
class="antd-clear"
223-
style="user-select: none;"
224-
unselectable="on"
225208
>
226-
<span
227-
class="antd-clear-icon"
228-
>
229-
×
230-
</span>
231-
</span>
209+
×
210+
</div>
232211
</div>
233212
`;
234213

@@ -286,39 +265,24 @@ exports[`Select.Basic render renders data-attributes correctly 1`] = `
286265

287266
exports[`Select.Basic render renders disabled select correctly 1`] = `
288267
<div
289-
class="antd select-test antd-single antd-allow-clear antd-disabled antd-show-search"
268+
class="antd select-test antd-single antd-disabled antd-show-search"
290269
>
291270
<div
292-
class="antd-selector"
271+
class="antd-content"
293272
>
294-
<span
295-
class="antd-selection-wrap"
273+
<div
274+
class="antd-content-value"
275+
style="visibility: visible;"
276+
title="2"
296277
>
297-
<span
298-
class="antd-selection-search"
299-
>
300-
<input
301-
aria-autocomplete="list"
302-
aria-controls="test-id_list"
303-
aria-expanded="false"
304-
aria-haspopup="listbox"
305-
aria-owns="test-id_list"
306-
autocomplete="off"
307-
class="antd-selection-search-input"
308-
disabled=""
309-
id="test-id"
310-
role="combobox"
311-
type="search"
312-
value=""
313-
/>
314-
</span>
315-
<span
316-
class="antd-selection-item"
317-
title="2"
318-
>
319-
2
320-
</span>
321-
</span>
278+
2
279+
</div>
280+
<input
281+
class="antd-input"
282+
id="test-id"
283+
type="search"
284+
value=""
285+
/>
322286
</div>
323287
</div>
324288
`;

tests/shared/blurTest.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import Option from '../../src/Option';
33
import Select from '../../src/Select';
44
import { injectRunAllTimers } from '../utils/common';
5-
import { type RenderResult, render, fireEvent, createEvent } from '@testing-library/react';
5+
import { type RenderResult, render, fireEvent, createEvent, act } from '@testing-library/react';
66

77
export default function blurTest(mode: any) {
88
describe(`blur of ${mode}`, () => {
@@ -34,8 +34,11 @@ export default function blurTest(mode: any) {
3434
it('clears inputValue', () => {
3535
fireEvent.change(wrapper.container.querySelector('input'), { target: { value: '1' } });
3636
fireEvent.blur(wrapper.container.querySelector('input'));
37+
act(() => {
38+
jest.runAllTimers();
39+
});
3740

38-
expect(wrapper.container.querySelector('input').value).toBe('');
41+
expect(wrapper.container.querySelector('input')).toHaveValue('');
3942
});
4043

4144
it('blur()', () => {

0 commit comments

Comments
 (0)