import { mount, render } from 'enzyme'; import React from 'react'; import ProTable, { ListToolBar } from '@ant-design/pro-table'; import { SettingOutlined, FullscreenOutlined } from '@ant-design/icons'; import { Button, Input } from 'antd'; import { act } from 'react-dom/test-utils'; import { waitForComponentToPaint } from '../util'; describe('Table valueEnum', () => { it('ListToolBar onAction', async () => { const onAction = jest.fn(); const wrapper = mount( 批量导入, , ]} />, ); await waitForComponentToPaint(wrapper); act(() => { wrapper.find('button.ant-btn-primary').simulate('click'); }); expect(onAction).toHaveBeenLastCalledWith('add'); }); it('ListToolBar onAction', async () => { const onSearch = jest.fn(); const wrapper = mount( columns={[ { title: '应用名称', dataIndex: 'name', }, ]} request={() => { return Promise.resolve({ data: [], success: true, }); }} toolbar={{ title: '这里是标题', search: { onSearch: (value: string) => { onSearch(value); }, }, }} rowKey="key" />, ); await waitForComponentToPaint(wrapper); act(() => { wrapper.find('.ant-pro-table-list-toolbar-search input').simulate('change', { target: { value: '1111111', }, }); }); await waitForComponentToPaint(wrapper); act(() => { wrapper.find('.ant-pro-table-list-toolbar-search input').simulate('keyDown', { keyCode: 13 }); }); await waitForComponentToPaint(wrapper); expect(onSearch).toBeCalledWith('1111111'); }); it('ListToolBar action no array', async () => { const wrapper = render( 添加 } />, ); expect(wrapper).toMatchSnapshot(); }); it('ListToolBar action is empty array', async () => { const wrapper = render( []} />, ); expect(wrapper).toMatchSnapshot(); }); it('ListToolBar action no jsx', async () => { const wrapper = render( 添加 , 'shuaxin', ]} />, ); expect(wrapper).toMatchSnapshot(); }); it('ListToolBar onSettingClick', async () => { const onClick = jest.fn(); const wrapper = mount( , tooltip: '设置', onClick, key: 's-value', }, { icon: , key: 'm-value', }, // 测试空的情况 null, ]} />, ); await waitForComponentToPaint(wrapper, 1000); act(() => { wrapper.find('.anticon-setting').simulate('click'); }); expect(onClick).toHaveBeenLastCalledWith('s-value'); expect(wrapper.find('.ant-divider').length).toEqual(0); }); it('ListToolBar search left', async () => { const onSearch = jest.fn(); const wrapper = mount( , ); await waitForComponentToPaint(wrapper, 1000); const inputEle = wrapper.find('input'); act(() => { inputEle.simulate('focus'); }); act(() => { inputEle.simulate('change', { target: { value: 'input 值' } }); }); act(() => { inputEle.simulate('keyDown', { keyCode: 13 }); }); expect(wrapper.find('.ant-pro-table-list-toolbar-left input').prop('value')).toEqual( 'input 值', ); expect(onSearch).toHaveBeenCalled(); expect(wrapper.find('input').prop('placeholder')).toEqual('自定义 placeholder'); }); it('ListToolBar search right and custom input search', async () => { const onSearch = jest.fn(); const wrapper = mount( } />, ); await waitForComponentToPaint(wrapper, 1000); const inputEle = wrapper.find('input'); act(() => { inputEle.simulate('focus'); }); act(() => { inputEle.simulate('change', { target: { value: 'input 值' } }); }); act(() => { inputEle.simulate('keyDown', { keyCode: 13 }); }); expect(wrapper.find('.ant-pro-table-list-toolbar-right input').prop('value')).toEqual( 'input 值', ); expect(onSearch).toHaveBeenCalled(); expect(wrapper.find('input').prop('placeholder')).toEqual('自定义 placeholder'); }); it('ListToolBar dropdown menu', async () => { const onChange = jest.fn(); const wrapper = mount( , ); await waitForComponentToPaint(wrapper, 1000); wrapper.find('div.ant-pro-table-list-toolbar-dropdownmenu-label').at(0).simulate('click'); act(() => { wrapper.find('li.ant-dropdown-menu-item').at(1).simulate('click'); }); expect(onChange).toHaveBeenCalledWith('done', undefined); }); it('ListToolBar tab menu', async () => { const onChange = jest.fn(); const wrapper = mount( , ); await waitForComponentToPaint(wrapper, 1000); act(() => { wrapper.find('.ant-tabs-tab').at(1).simulate('click'); }); expect(onChange).toHaveBeenCalledWith('done', undefined); }); it('ListToolBar inline menu', async () => { const onChange = jest.fn(); const wrapper = mount( , ); await waitForComponentToPaint(wrapper, 1000); act(() => { wrapper.find('.ant-pro-table-list-toolbar-inline-menu-item').at(1).simulate('click'); }); expect(onChange).toHaveBeenCalledWith('done', undefined); }); it('ListToolBar render no menu with item empty', async () => { const wrapper = mount( , ); await waitForComponentToPaint(wrapper, 1000); expect(wrapper.find('.ant-pro-table-list-toolbar-menu').length).toBe(0); }); });