Skip to content

Commit a6f0ca7

Browse files
author
liquanwei.lqw
committed
fix: field test
1 parent 7279f00 commit a6f0ca7

File tree

2 files changed

+106
-152
lines changed

2 files changed

+106
-152
lines changed

tests/field/__snapshots__/field.test.tsx.snap

+88-104
Original file line numberDiff line numberDiff line change
@@ -684,33 +684,29 @@ exports[`Field > 🐴 edit and no plain 1`] = `
684684
class="ant-select-selector"
685685
>
686686
<span
687-
class="ant-select-selection-wrap"
687+
class="ant-select-selection-search"
688688
>
689-
<span
690-
class="ant-select-selection-search"
691-
>
692-
<input
693-
aria-autocomplete="list"
694-
aria-controls="rc_select_TEST_OR_SSR_list"
695-
aria-expanded="false"
696-
aria-haspopup="listbox"
697-
aria-owns="rc_select_TEST_OR_SSR_list"
698-
autocomplete="off"
699-
class="ant-select-selection-search-input"
700-
id="rc_select_TEST_OR_SSR"
701-
readonly=""
702-
role="combobox"
703-
style="opacity: 0;"
704-
type="search"
705-
unselectable="on"
706-
value=""
707-
/>
708-
</span>
709-
<span
710-
class="ant-select-selection-placeholder"
711-
>
712-
请选择
713-
</span>
689+
<input
690+
aria-autocomplete="list"
691+
aria-controls="rc_select_TEST_OR_SSR_list"
692+
aria-expanded="false"
693+
aria-haspopup="listbox"
694+
aria-owns="rc_select_TEST_OR_SSR_list"
695+
autocomplete="off"
696+
class="ant-select-selection-search-input"
697+
id="rc_select_TEST_OR_SSR"
698+
readonly=""
699+
role="combobox"
700+
style="opacity: 0;"
701+
type="search"
702+
unselectable="on"
703+
value=""
704+
/>
705+
</span>
706+
<span
707+
class="ant-select-selection-placeholder"
708+
>
709+
请选择
714710
</span>
715711
</div>
716712
<span
@@ -770,33 +766,29 @@ exports[`Field > 🐴 edit and no plain 1`] = `
770766
class="ant-select-selector"
771767
>
772768
<span
773-
class="ant-select-selection-wrap"
769+
class="ant-select-selection-search"
774770
>
775-
<span
776-
class="ant-select-selection-search"
777-
>
778-
<input
779-
aria-autocomplete="list"
780-
aria-controls="rc_select_TEST_OR_SSR_list"
781-
aria-expanded="false"
782-
aria-haspopup="listbox"
783-
aria-owns="rc_select_TEST_OR_SSR_list"
784-
autocomplete="off"
785-
class="ant-select-selection-search-input"
786-
id="rc_select_TEST_OR_SSR"
787-
readonly=""
788-
role="combobox"
789-
style="opacity: 0;"
790-
type="search"
791-
unselectable="on"
792-
value=""
793-
/>
794-
</span>
795-
<span
796-
class="ant-select-selection-placeholder"
797-
>
798-
请选择
799-
</span>
771+
<input
772+
aria-autocomplete="list"
773+
aria-controls="rc_select_TEST_OR_SSR_list"
774+
aria-expanded="false"
775+
aria-haspopup="listbox"
776+
aria-owns="rc_select_TEST_OR_SSR_list"
777+
autocomplete="off"
778+
class="ant-select-selection-search-input"
779+
id="rc_select_TEST_OR_SSR"
780+
readonly=""
781+
role="combobox"
782+
style="opacity: 0;"
783+
type="search"
784+
unselectable="on"
785+
value=""
786+
/>
787+
</span>
788+
<span
789+
class="ant-select-selection-placeholder"
790+
>
791+
请选择
800792
</span>
801793
</div>
802794
<span
@@ -1909,33 +1901,29 @@ exports[`Field > 🐴 edit and plain=true 1`] = `
19091901
class="ant-select-selector"
19101902
>
19111903
<span
1912-
class="ant-select-selection-wrap"
1904+
class="ant-select-selection-search"
19131905
>
1914-
<span
1915-
class="ant-select-selection-search"
1916-
>
1917-
<input
1918-
aria-autocomplete="list"
1919-
aria-controls="rc_select_TEST_OR_SSR_list"
1920-
aria-expanded="false"
1921-
aria-haspopup="listbox"
1922-
aria-owns="rc_select_TEST_OR_SSR_list"
1923-
autocomplete="off"
1924-
class="ant-select-selection-search-input"
1925-
id="rc_select_TEST_OR_SSR"
1926-
readonly=""
1927-
role="combobox"
1928-
style="opacity: 0;"
1929-
type="search"
1930-
unselectable="on"
1931-
value=""
1932-
/>
1933-
</span>
1934-
<span
1935-
class="ant-select-selection-placeholder"
1936-
>
1937-
请选择
1938-
</span>
1906+
<input
1907+
aria-autocomplete="list"
1908+
aria-controls="rc_select_TEST_OR_SSR_list"
1909+
aria-expanded="false"
1910+
aria-haspopup="listbox"
1911+
aria-owns="rc_select_TEST_OR_SSR_list"
1912+
autocomplete="off"
1913+
class="ant-select-selection-search-input"
1914+
id="rc_select_TEST_OR_SSR"
1915+
readonly=""
1916+
role="combobox"
1917+
style="opacity: 0;"
1918+
type="search"
1919+
unselectable="on"
1920+
value=""
1921+
/>
1922+
</span>
1923+
<span
1924+
class="ant-select-selection-placeholder"
1925+
>
1926+
请选择
19391927
</span>
19401928
</div>
19411929
<span
@@ -1995,33 +1983,29 @@ exports[`Field > 🐴 edit and plain=true 1`] = `
19951983
class="ant-select-selector"
19961984
>
19971985
<span
1998-
class="ant-select-selection-wrap"
1986+
class="ant-select-selection-search"
19991987
>
2000-
<span
2001-
class="ant-select-selection-search"
2002-
>
2003-
<input
2004-
aria-autocomplete="list"
2005-
aria-controls="rc_select_TEST_OR_SSR_list"
2006-
aria-expanded="false"
2007-
aria-haspopup="listbox"
2008-
aria-owns="rc_select_TEST_OR_SSR_list"
2009-
autocomplete="off"
2010-
class="ant-select-selection-search-input"
2011-
id="rc_select_TEST_OR_SSR"
2012-
readonly=""
2013-
role="combobox"
2014-
style="opacity: 0;"
2015-
type="search"
2016-
unselectable="on"
2017-
value=""
2018-
/>
2019-
</span>
2020-
<span
2021-
class="ant-select-selection-placeholder"
2022-
>
2023-
请选择
2024-
</span>
1988+
<input
1989+
aria-autocomplete="list"
1990+
aria-controls="rc_select_TEST_OR_SSR_list"
1991+
aria-expanded="false"
1992+
aria-haspopup="listbox"
1993+
aria-owns="rc_select_TEST_OR_SSR_list"
1994+
autocomplete="off"
1995+
class="ant-select-selection-search-input"
1996+
id="rc_select_TEST_OR_SSR"
1997+
readonly=""
1998+
role="combobox"
1999+
style="opacity: 0;"
2000+
type="search"
2001+
unselectable="on"
2002+
value=""
2003+
/>
2004+
</span>
2005+
<span
2006+
class="ant-select-selection-placeholder"
2007+
>
2008+
请选择
20252009
</span>
20262010
</div>
20272011
<span

tests/field/field.test.tsx

+18-48
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import React, { act, useState } from 'react';
1212
import { waitForWaitTime, waitTime } from '../util';
1313
import Demo from './fixtures/demo';
1414
import { TreeSelectDemo } from './fixtures/treeSelectDemo';
15+
import userEvent from '@testing-library/user-event';
1516

1617
const domRef = React.createRef();
1718

@@ -2024,57 +2025,26 @@ describe('Field', () => {
20242025
valueType="select"
20252026
mode="edit"
20262027
light
2027-
options={[
2028-
{ label: '全部', value: 'all' },
2029-
{ label: '未解决', value: 'open' },
2030-
{ label: '已解决', value: 'closed' },
2031-
{ label: '解决中', value: 'processing' },
2032-
]}
2028+
fieldProps={{
2029+
options: [
2030+
{ label: '全部', value: 'all' },
2031+
{ label: '未解决', value: 'open' },
2032+
{ label: '已解决', value: 'closed' },
2033+
{ label: '解决中', value: 'processing' },
2034+
]
2035+
}}
20332036
/>,
20342037
);
20352038
await waitForWaitTime(100);
2036-
2037-
act(() => {
2038-
// 点击label打开DatePicker
2039-
// jest环境下,click 不会触发mousedown和mouseup,需要手动触发以覆盖相关逻辑代码
2040-
fireEvent.mouseDown(
2041-
html.baseElement.querySelector('.ant-pro-core-field-label')!,
2042-
);
2043-
fireEvent.click(
2044-
html.baseElement.querySelector('.ant-pro-core-field-label')!,
2045-
);
2046-
fireEvent.mouseUp(
2047-
html.baseElement.querySelector('.ant-pro-core-field-label')!,
2048-
);
2049-
});
2050-
await waitFor(() => {
2051-
expect(
2052-
html.baseElement.querySelectorAll('.ant-select-dropdown').length,
2053-
).toEqual(1);
2054-
expect(
2055-
html.baseElement.querySelectorAll(
2056-
'.ant-select-dropdown.ant-select-dropdown-hidden',
2057-
).length,
2058-
).toEqual(0);
2059-
});
2060-
act(() => {
2061-
fireEvent.mouseDown(
2062-
html.baseElement.querySelector('.ant-pro-core-field-label')!,
2063-
);
2064-
fireEvent.click(
2065-
html.baseElement.querySelector('.ant-pro-core-field-label')!,
2066-
);
2067-
fireEvent.mouseUp(
2068-
html.baseElement.querySelector('.ant-pro-core-field-label')!,
2069-
);
2070-
});
2071-
await waitFor(() => {
2072-
expect(
2073-
html.baseElement.querySelectorAll(
2074-
'.ant-select-dropdown.ant-select-dropdown-hidden',
2075-
).length,
2076-
).toEqual(1);
2077-
});
2039+
await userEvent.click(
2040+
html.baseElement.querySelector('.ant-pro-core-field-label')!,
2041+
);
2042+
await waitFor(() => expect(html.baseElement.querySelectorAll('.ant-select-dropdown.ant-slide-up-appear')[0]).toBeInTheDocument());
2043+
await userEvent.click(
2044+
html.baseElement.querySelector('.ant-pro-core-field-label')!,
2045+
);
2046+
// 第二次点击后组件没有到最终的隐藏态,这里检查动画的中间状态可通过
2047+
await waitFor(() => expect(html.baseElement.querySelectorAll('.ant-select-dropdown.ant-slide-up-enter')[0]).toBeInTheDocument());
20782048
});
20792049

20802050
it(`🐴 FieldSelect support clear`, async () => {

0 commit comments

Comments
 (0)