Skip to content

Commit fa96660

Browse files
keanrainliquanwei.lqw
and
liquanwei.lqw
authored
Dev/v3.0 (#8874)
* feat: add valueType map for table * fix: test case * feat: add await for test * feat: table继承外部的valueTypeMap设置 --------- Co-authored-by: liquanwei.lqw <[email protected]>
1 parent 06705ac commit fa96660

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

packages/table/src/Table.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ProCard from '@ant-design/pro-card';
22
import ProForm, { GridContext } from '@ant-design/pro-form';
33
import type { ParamsType } from '@ant-design/pro-provider';
4-
import { ProConfigProvider, proTheme, useIntl } from '@ant-design/pro-provider';
4+
import ProConfigContext, { ProConfigProvider, proTheme, useIntl } from '@ant-design/pro-provider';
55
import {
66
ErrorBoundary,
77
editableRowByKey,
@@ -1020,9 +1020,10 @@ const ProviderTableContainer = <
10201020
? React.Fragment
10211021
: props.ErrorBoundary || ErrorBoundary;
10221022

1023+
const context = useContext(ProConfigContext);
10231024
return (
10241025
<Container initValue={props}>
1025-
<ProConfigProvider valueTypeMap={ValueTypeToComponent} needDeps>
1026+
<ProConfigProvider valueTypeMap={{...context.valueTypeMap, ...ValueTypeToComponent}} needDeps>
10261027
<ErrorComponent>
10271028
<ProTable<DataType, Params, ValueType>
10281029
defaultClassName={`${getPrefixCls('pro-table')}`}

tests/table/index.test.tsx

+20-20
Original file line numberDiff line numberDiff line change
@@ -1521,14 +1521,14 @@ describe('BasicTable', () => {
15211521
rowKey="key"
15221522
/>,
15231523
);
1524-
1524+
const input = await waitFor(() => html.baseElement.querySelector(
1525+
'.ant-pro-table-list-toolbar-search input',
1526+
)!)
15251527
await html.findByText('查 询');
15261528

15271529
act(() => {
15281530
fireEvent.change(
1529-
html.baseElement.querySelector(
1530-
'.ant-pro-table-list-toolbar-search input',
1531-
)!,
1531+
input,
15321532
{
15331533
target: {
15341534
value: 'name',
@@ -1541,9 +1541,7 @@ describe('BasicTable', () => {
15411541

15421542
act(() => {
15431543
fireEvent.keyDown(
1544-
html.baseElement.querySelector(
1545-
'.ant-pro-table-list-toolbar-search input',
1546-
)!,
1544+
input,
15471545
{ key: 'Enter', keyCode: 13 },
15481546
);
15491547
});
@@ -1554,9 +1552,7 @@ describe('BasicTable', () => {
15541552

15551553
act(() => {
15561554
fireEvent.change(
1557-
html.baseElement.querySelector(
1558-
'.ant-pro-table-list-toolbar-search input',
1559-
)!,
1555+
input,
15601556
{
15611557
target: {
15621558
value: 'name1',
@@ -1565,16 +1561,20 @@ describe('BasicTable', () => {
15651561
);
15661562
});
15671563

1568-
// await html.findByDisplayValue('name1');
1569-
1570-
// act(() => {
1571-
// fireEvent.keyDown(
1572-
// html.baseElement.querySelector(
1573-
// '.ant-pro-table-list-toolbar-search input',
1574-
// )!,
1575-
// { key: 'Enter', keyCode: 13 },
1576-
// );
1577-
// });
1564+
await html.findByDisplayValue('name1');
1565+
// 下一次keyDown前需要一次keyUp,除非是设置了长按
1566+
act(() => {
1567+
fireEvent.keyUp(
1568+
input,
1569+
{ key: 'Enter', keyCode: 13 },
1570+
);
1571+
});
1572+
act(() => {
1573+
fireEvent.keyDown(
1574+
input,
1575+
{ key: 'Enter', keyCode: 13 },
1576+
);
1577+
});
15781578

15791579
await waitFor(() => {
15801580
expect(fn).toHaveBeenCalledWith('name1');

tests/table/valueType.test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ describe('BasicTable valueType', () => {
126126
html.unmount();
127127
});
128128

129+
// 使用valueTypeMap包裹protable后,这里的context不会使用导致单测失败
129130
it('🎏 table valueType render support fieldProps', async () => {
130131
const html = render(
131132
<ProProvider.Provider

0 commit comments

Comments
 (0)