diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index 8df6debf22..cdffe311a3 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -15,6 +15,16 @@ timeline: true --- +## 4.20.7 + +`2022-05-30` + +- 🐞 Fix Drawer form instance lost bug when opened. [#35706](https://github.com/ant-design/ant-design/pull/35706) [@crazyair](https://github.com/crazyair) +- 🐞 Fix Segmented options invalid space between icon and text when using the icon prop. [#35701](https://github.com/ant-design/ant-design/pull/35701) +- 💄 Optimize Popover arrow style. [#35717](https://github.com/ant-design/ant-design/pull/35717) +- TypeScript + - 🤖 Fix Card type hints problem. [#35753](https://github.com/ant-design/ant-design/pull/35753) + ## 4.20.6 `2022-05-22` diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index 290f1996b5..0e4d7ef369 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -15,6 +15,16 @@ timeline: true --- +## 4.20.7 + +`2022-05-30` + +- 🐞 修复 Drawer 打开时 form 实例为 null 的问题。[#35706](https://github.com/ant-design/ant-design/pull/35706) [@crazyair](https://github.com/crazyair) +- 🐞 修复 Segmented 组件中选项使用 icon 属性时图标与文字之间的间距失效问题。[#35701](https://github.com/ant-design/ant-design/pull/35701) +- 💄 优化 Popover 的箭头效果。[#35717](https://github.com/ant-design/ant-design/pull/35717) +- TypeScript + - 🤖 修复 Card 组件的类型提示。[#35753](https://github.com/ant-design/ant-design/pull/35753) + ## 4.20.6 `2022-05-22` diff --git a/components/drawer/__tests__/Drawer.test.js b/components/drawer/__tests__/Drawer.test.js index 35ad2c9f63..8f5a8447e8 100644 --- a/components/drawer/__tests__/Drawer.test.js +++ b/components/drawer/__tests__/Drawer.test.js @@ -1,5 +1,4 @@ import React from 'react'; -import { mount } from 'enzyme'; import { render } from '../../../tests/utils'; import Drawer from '..'; import ConfigProvider from '../../config-provider'; @@ -19,71 +18,71 @@ describe('Drawer', () => { rtlTest(Drawer); it('render correctly', () => { - const wrapper = mount( + const { container: wrapper } = render( Here is content of Drawer , ); - expect(wrapper.render()).toMatchSnapshot(); + expect(wrapper.firstChild).toMatchSnapshot(); }); it('getContainer return undefined', () => { - let wrapper = mount( undefined} />); - expect(wrapper.render()).toMatchSnapshot(); - wrapper = mount(); - expect(wrapper.render()).toMatchSnapshot(); + const { container: wrapper, rerender } = render( undefined} />); + expect(wrapper.firstChild).toMatchSnapshot(); + rerender(); + expect(wrapper.firstChild).toMatchSnapshot(); }); it('render top drawer', () => { - const wrapper = mount( + const { container: wrapper } = render( Here is content of Drawer , ); - expect(wrapper.render()).toMatchSnapshot(); + expect(wrapper.firstChild).toMatchSnapshot(); }); it('have a title', () => { - const wrapper = mount( + const { container: wrapper } = render( Here is content of Drawer , ); - expect(wrapper.render()).toMatchSnapshot(); + expect(wrapper.firstChild).toMatchSnapshot(); }); it('closable is false', () => { - const wrapper = mount( + const { container: wrapper } = render( Here is content of Drawer , ); - expect(wrapper.render()).toMatchSnapshot(); + expect(wrapper.firstChild).toMatchSnapshot(); }); it('destroyOnClose is true', () => { - const wrapper = mount( + const { container: wrapper } = render( Here is content of Drawer , ); - expect(wrapper.render()).toMatchSnapshot(); + expect(wrapper.firstChild).toMatchSnapshot(); }); it('className is test_drawer', () => { - const wrapper = mount( + const { container: wrapper } = render( Here is content of Drawer , ); - expect(wrapper.render()).toMatchSnapshot(); + expect(wrapper.firstChild).toMatchSnapshot(); }); it('style/drawerStyle/headerStyle/bodyStyle should work', () => { const style = { backgroundColor: '#08c', }; - const wrapper = mount( + const { container: wrapper } = render( { Here is content of Drawer , ); - expect(wrapper.render()).toMatchSnapshot(); + expect(wrapper.firstChild).toMatchSnapshot(); }); it('have a footer', () => { - const wrapper = mount( + const { container: wrapper } = render( Here is content of Drawer , ); - expect(wrapper.render()).toMatchSnapshot(); + expect(wrapper.firstChild).toMatchSnapshot(); }); it('forceRender works', () => { - const wrapper = mount( + const { baseElement, rerender } = render( , ); - expect(wrapper.find('button.forceRender').length).toBe(0); - const wrapper2 = mount( + expect(baseElement.querySelectorAll('button.forceRender').length).toBe(0); + rerender( , ); - expect(wrapper2.find('button.forceRender').length).toBe(1); + expect(baseElement.querySelectorAll('button.forceRender').length).toBe(1); }); it('support closeIcon', () => { - const wrapper = mount( + const { container: wrapper } = render( close} width={400} getContainer={false}> Here is content of Drawer , ); - expect(wrapper.render()).toMatchSnapshot(); + expect(wrapper.firstChild).toMatchSnapshot(); }); it('ConfigProvider should not warning', () => { @@ -151,7 +150,7 @@ describe('Drawer', () => { it('should support ref', () => { const ref = React.createRef(); - mount( + render( Here is content of Drawer , diff --git a/components/drawer/__tests__/DrawerEvent.test.js b/components/drawer/__tests__/DrawerEvent.test.js index 18815e4400..a0c9cc15dc 100644 --- a/components/drawer/__tests__/DrawerEvent.test.js +++ b/components/drawer/__tests__/DrawerEvent.test.js @@ -68,6 +68,25 @@ describe('Drawer', () => { expect(container.querySelector('.ant-drawer-wrapper-body')).toBeTruthy(); }); + it('dom should be existed after close twice when getContainer is false', () => { + const { container, rerender } = render(getDrawer({ visible: true, getContainer: false })); + rerender(getDrawer({ visible: false, getContainer: false })); + const ev = new TransitionEvent('transitionend', { bubbles: true }); + ev.propertyName = 'transform'; + fireEvent(document.querySelector('.ant-drawer-content-wrapper'), ev); + + rerender(getDrawer({ visible: true, getContainer: false })); + const ev2 = new TransitionEvent('transitionend', { bubbles: true }); + ev2.propertyName = 'transform'; + fireEvent(document.querySelector('.ant-drawer-content-wrapper'), ev2); + + rerender(getDrawer({ visible: false, getContainer: false })); + const ev3 = new TransitionEvent('transitionend', { bubbles: true }); + ev3.propertyName = 'transform'; + fireEvent(document.querySelector('.ant-drawer-content-wrapper'), ev3); + + expect(container.querySelector('.ant-drawer-wrapper-body')).toBeTruthy(); + }); it('test afterVisibleChange', async () => { const afterVisibleChange = jest.fn(); const { rerender } = render(getDrawer({ afterVisibleChange, visible: true })); diff --git a/components/drawer/__tests__/MultiDrawer.test.js b/components/drawer/__tests__/MultiDrawer.test.js index 601ac19a7f..0dbe3a0ee6 100644 --- a/components/drawer/__tests__/MultiDrawer.test.js +++ b/components/drawer/__tests__/MultiDrawer.test.js @@ -1,7 +1,7 @@ import React from 'react'; -import { mount } from 'enzyme'; import Drawer from '..'; import Button from '../../button'; +import { render, fireEvent } from '../../../tests/utils'; class MultiDrawer extends React.Component { state = { visible: false, childrenDrawer: false, hasChildren: true }; @@ -110,68 +110,68 @@ class MultiDrawer extends React.Component { describe('Drawer', () => { it('render right MultiDrawer', () => { - const wrapper = mount(); - wrapper.find('button#open_drawer').simulate('click'); - wrapper.find('button#open_two_drawer').simulate('click'); - const translateX = wrapper.find('.ant-drawer.test_drawer').get(0).props.style.transform; + const { container: wrapper } = render(); + fireEvent.click(wrapper.querySelector('button#open_drawer')); + fireEvent.click(wrapper.querySelector('button#open_two_drawer')); + const translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform; expect(translateX).toEqual('translateX(-180px)'); - expect(wrapper.find('#two_drawer_text').exists()).toBe(true); + expect(wrapper.querySelectorAll('#two_drawer_text').length).toBe(1); }); it('render left MultiDrawer', () => { - const wrapper = mount(); - wrapper.find('button#open_drawer').simulate('click'); - wrapper.find('button#open_two_drawer').simulate('click'); - const translateX = wrapper.find('.ant-drawer.test_drawer').get(0).props.style.transform; + const { container: wrapper } = render(); + fireEvent.click(wrapper.querySelector('button#open_drawer')); + fireEvent.click(wrapper.querySelector('button#open_two_drawer')); + const translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform; expect(translateX).toEqual('translateX(180px)'); - expect(wrapper.find('#two_drawer_text').exists()).toBe(true); - wrapper.find('.Two-level .ant-drawer-close').simulate('click'); - expect(wrapper.find('.childrenDrawer').text()).toEqual('false'); + expect(wrapper.querySelectorAll('#two_drawer_text').length).toBe(1); + fireEvent.click(wrapper.querySelector('.Two-level .ant-drawer-close')); + expect(wrapper.querySelector('.childrenDrawer').innerHTML).toEqual('false'); }); it('render top MultiDrawer', () => { - const wrapper = mount(); - wrapper.find('button#open_drawer').simulate('click'); - wrapper.find('button#open_two_drawer').simulate('click'); - const translateX = wrapper.find('.ant-drawer.test_drawer').get(0).props.style.transform; + const { container: wrapper } = render(); + fireEvent.click(wrapper.querySelector('button#open_drawer')); + fireEvent.click(wrapper.querySelector('button#open_two_drawer')); + const translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform; expect(translateX).toEqual('translateY(180px)'); - expect(wrapper.find('#two_drawer_text').exists()).toBe(true); + expect(wrapper.querySelectorAll('#two_drawer_text').length).toBe(1); }); it('render MultiDrawer is child in unmount', () => { - const wrapper = mount(); - wrapper.find('button#open_drawer').simulate('click'); - wrapper.find('button#open_two_drawer').simulate('click'); - wrapper.find('button#remove_drawer').simulate('click'); - let translateX = wrapper.find('.ant-drawer.test_drawer').get(0).props.style.transform; - expect(translateX).toEqual(undefined); - wrapper.find('button#open_two_drawer').simulate('click'); - translateX = wrapper.find('.ant-drawer.test_drawer').get(0).props.style.transform; + const { container: wrapper } = render(); + fireEvent.click(wrapper.querySelector('button#open_drawer')); + fireEvent.click(wrapper.querySelector('button#open_two_drawer')); + fireEvent.click(wrapper.querySelector('button#remove_drawer')); + let translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform; + expect(translateX).toEqual(''); + fireEvent.click(wrapper.querySelector('button#open_two_drawer')); + translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform; expect(translateX).toEqual('translateY(180px)'); - expect(wrapper.find('#two_drawer_text').exists()).toBe(true); + expect(wrapper.querySelectorAll('#two_drawer_text').length).toBe(1); }); it('custom MultiDrawer push distance', () => { - const wrapper = mount(); - wrapper.find('button#open_drawer').simulate('click'); - wrapper.find('button#open_two_drawer').simulate('click'); - const translateX = wrapper.find('.ant-drawer.test_drawer').get(0).props.style.transform; + const { container: wrapper } = render(); + fireEvent.click(wrapper.querySelector('button#open_drawer')); + fireEvent.click(wrapper.querySelector('button#open_two_drawer')); + const translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform; expect(translateX).toEqual('translateX(-256px)'); }); it('custom MultiDrawer push with true', () => { - const wrapper = mount(); - wrapper.find('button#open_drawer').simulate('click'); - wrapper.find('button#open_two_drawer').simulate('click'); - const translateX = wrapper.find('.ant-drawer.test_drawer').get(0).props.style.transform; + const { container: wrapper } = render(); + fireEvent.click(wrapper.querySelector('button#open_drawer')); + fireEvent.click(wrapper.querySelector('button#open_two_drawer')); + const translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform; expect(translateX).toEqual('translateX(-180px)'); }); it('custom MultiDrawer push with false', () => { - const wrapper = mount(); - wrapper.find('button#open_drawer').simulate('click'); - wrapper.find('button#open_two_drawer').simulate('click'); - const translateX = wrapper.find('.ant-drawer.test_drawer').get(0).props.style.transform; - expect(translateX).toBeUndefined(); + const { container: wrapper } = render(); + fireEvent.click(wrapper.querySelector('button#open_drawer')); + fireEvent.click(wrapper.querySelector('button#open_two_drawer')); + const translateX = wrapper.querySelectorAll('.ant-drawer.test_drawer')[0].style.transform; + expect(translateX).toEqual(''); }); }); diff --git a/components/drawer/index.tsx b/components/drawer/index.tsx index eb1575a3c3..ab3d95b595 100644 --- a/components/drawer/index.tsx +++ b/components/drawer/index.tsx @@ -319,14 +319,11 @@ const Drawer = React.forwardRef( className={drawerClassName} getContainer={getContainer} afterVisibleChange={open => { - if (!open) { - if (destroyCloseRef.current === false) { - // set true only once - destroyCloseRef.current = true; - } - if (destroyOnClose) { - setLoad(false); - } + if (open) { + destroyCloseRef.current = false; + } else if (destroyOnClose) { + destroyCloseRef.current = true; + setLoad(false); } afterVisibleChange?.(open); }} diff --git a/components/image/__tests__/index.test.js b/components/image/__tests__/index.test.js index 39028231b5..91093149ed 100644 --- a/components/image/__tests__/index.test.js +++ b/components/image/__tests__/index.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { mount } from 'enzyme'; +import { render, fireEvent } from '../../../tests/utils'; import Image from '..'; import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; @@ -10,49 +10,60 @@ describe('Image', () => { mountTest(Image); rtlTest(Image); it('Image preview props set false', () => { - const wrapper = mount(); + const { container: wrapper } = render(); - expect(wrapper.find('Image').at(0).prop('preview')).toBe(false); - expect(wrapper.find('Image').at(1).prop('preview')).toBe(false); + fireEvent.click(wrapper.querySelector('.ant-image')); + expect(wrapper.querySelector('.ant-image-preview-root')).toBe(null); }); it('Group preview props set false', () => { - const wrapper = mount( + const { container: wrapper } = render( , ); - expect(wrapper.find('Group').prop('preview')).toBe(false); + + fireEvent.click(wrapper.querySelector('.ant-image')); + + expect(wrapper.querySelector('.ant-image-preview-root')).toBe(null); }); it('Default preview props', () => { - const wrapper = mount(); + const { container: wrapper, baseElement } = render( + , + ); - expect(wrapper.find('Preview').prop('transitionName')).toBe('ant-zoom'); - expect(wrapper.find('Preview').prop('maskTransitionName')).toBe('ant-fade'); + fireEvent.click(wrapper.querySelector('.ant-image')); + + expect(baseElement.querySelector('.ant-image-preview-mask')).toHaveClass('ant-fade'); + expect(baseElement.querySelector('.ant-image-preview')).toHaveClass('ant-zoom'); }); it('Default Group preview props', () => { - const wrapper = mount( + const { container: wrapper, baseElement } = render( , ); - expect(wrapper.find('Preview').prop('transitionName')).toBe('ant-zoom'); - expect(wrapper.find('Preview').prop('maskTransitionName')).toBe('ant-fade'); + fireEvent.click(wrapper.querySelector('.ant-image')); + + expect(baseElement.querySelector('.ant-image-preview-mask')).toHaveClass('ant-fade'); + expect(baseElement.querySelector('.ant-image-preview')).toHaveClass('ant-zoom'); }); it('Customize preview props', () => { - const wrapper = mount( + const { container: wrapper, baseElement } = render( , ); - expect(wrapper.find('Preview').prop('transitionName')).toBe('abc'); - expect(wrapper.find('Preview').prop('maskTransitionName')).toBe('def'); + fireEvent.click(wrapper.querySelector('.ant-image')); + + expect(baseElement.querySelector('.ant-image-preview')).toHaveClass('abc'); + expect(baseElement.querySelector('.ant-image-preview-mask')).toHaveClass('def'); }); it('Customize Group preview props', () => { - const wrapper = mount( + const { container: wrapper, baseElement } = render( @@ -60,7 +71,9 @@ describe('Image', () => { , ); - expect(wrapper.find('Preview').prop('transitionName')).toBe('abc'); - expect(wrapper.find('Preview').prop('maskTransitionName')).toBe('def'); + fireEvent.click(wrapper.querySelector('.ant-image')); + + expect(baseElement.querySelector('.ant-image-preview')).toHaveClass('abc'); + expect(baseElement.querySelector('.ant-image-preview-mask')).toHaveClass('def'); }); }); diff --git a/components/list/__tests__/Item.test.js b/components/list/__tests__/Item.test.js index 22eaa6b075..78de8887bf 100644 --- a/components/list/__tests__/Item.test.js +++ b/components/list/__tests__/Item.test.js @@ -1,5 +1,4 @@ import React from 'react'; -import { mount } from 'enzyme'; import List from '..'; import ConfigProvider from '../../config-provider'; import { render } from '../../../tests/utils'; @@ -20,7 +19,7 @@ describe('List Item Layout', () => { ]; it('horizontal itemLayout List which contains string nodes should not be flex container', () => { - const wrapper = mount( + const { container: wrapper } = render( ( @@ -30,11 +29,13 @@ describe('List Item Layout', () => { )} />, ); - expect(wrapper.find('.ant-list-item').at(0).hasClass('ant-list-item-no-flex')).toBe(true); + expect( + wrapper.querySelectorAll('.ant-list-item')[0].classList.contains('ant-list-item-no-flex'), + ).toBe(true); }); - it('horizontal itemLayout List should be flex container defaultly', () => { - const wrapper = mount( + it('horizontal itemLayout List should be flex container by default', () => { + const { container: wrapper } = render( ( @@ -47,11 +48,13 @@ describe('List Item Layout', () => { )} />, ); - expect(wrapper.find('.ant-list-item').at(0).hasClass('ant-list-item-no-flex')).toBe(false); + expect( + wrapper.querySelector('.ant-list-item').classList.contains('ant-list-item-no-flex'), + ).toBe(false); }); it('vertical itemLayout List should be flex container when there is extra node', () => { - const wrapper = mount( + const { container: wrapper } = render( { )} />, ); - expect(wrapper.find('.ant-list-item').at(0).hasClass('ant-list-item-no-flex')).toBe(false); + expect( + wrapper.querySelectorAll('.ant-list-item')[0].classList.contains('ant-list-item-no-flex'), + ).toBe(false); }); it('vertical itemLayout List should not be flex container when there is not extra node', () => { - const wrapper = mount( + const { container: wrapper } = render( { )} />, ); - expect(wrapper.find('.ant-list-item').at(0).hasClass('ant-list-item-no-flex')).toBe(true); + expect( + wrapper.querySelectorAll('.ant-list-item')[0].classList.contains('ant-list-item-no-flex'), + ).toBe(true); }); it('horizontal itemLayout List should accept extra node', () => { - const wrapper = mount( + const { container: wrapper } = render( ( @@ -104,11 +111,11 @@ describe('List Item Layout', () => { )} />, ); - expect(wrapper.render()).toMatchSnapshot(); + expect(wrapper.firstChild).toMatchSnapshot(); }); it('should render in RTL direction', () => { - const wrapper = mount( + const { container: wrapper } = render( { /> , ); - expect(wrapper.render()).toMatchSnapshot(); + expect(wrapper.firstChild).toMatchSnapshot(); }); it('rowKey could be string', () => { @@ -145,14 +152,14 @@ describe('List Item Layout', () => { title: `ant design`, }, ]; - const wrapper = mount( + const { container: wrapper } = render( {item.title}} />, ); - expect(wrapper.render()).toMatchSnapshot(); + expect(wrapper.firstChild).toMatchSnapshot(); }); it('rowKey could be function', () => { @@ -170,14 +177,14 @@ describe('List Item Layout', () => { title: `ant design`, }, ]; - const wrapper = mount( + const { container: wrapper } = render( item.id} renderItem={item => {item.title}} />, ); - expect(wrapper.render()).toMatchSnapshot(); + expect(wrapper.firstChild).toMatchSnapshot(); }); it('should ref', () => { diff --git a/components/list/__tests__/empty.test.js b/components/list/__tests__/empty.test.js index da1d6d79c4..00d770c312 100644 --- a/components/list/__tests__/empty.test.js +++ b/components/list/__tests__/empty.test.js @@ -1,10 +1,10 @@ import React from 'react'; -import { render } from 'enzyme'; +import { render } from '../../../tests/utils'; import List from '..'; describe('List', () => { it('renders empty list', () => { - const wrapper = render( } />); - expect(wrapper).toMatchSnapshot(); + const { container } = render( } />); + expect(container.firstChild).toMatchSnapshot(); }); }); diff --git a/components/list/__tests__/index.test.js b/components/list/__tests__/index.test.js index 6ff8527356..60c3fd3c20 100644 --- a/components/list/__tests__/index.test.js +++ b/components/list/__tests__/index.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { mount } from 'enzyme'; +import { render } from '../../../tests/utils'; import List from '..'; import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; @@ -16,7 +16,9 @@ describe('List', () => { const renderItem = item => {item}; const dataSource = []; - const wrapper = mount(); - expect(wrapper.find('div').first().props().locale).toBe(undefined); + const { container } = render( + , + ); + expect(container.querySelector('div.ant-list').getAttribute('locale')).toBe(null); }); }); diff --git a/components/list/__tests__/loading.test.js b/components/list/__tests__/loading.test.js index 6692355d99..5702441753 100644 --- a/components/list/__tests__/loading.test.js +++ b/components/list/__tests__/loading.test.js @@ -1,6 +1,6 @@ import React from 'react'; -import { render } from 'enzyme'; import { LoadingOutlined } from '@ant-design/icons'; +import { render } from '../../../tests/utils'; import List from '..'; @@ -9,20 +9,20 @@ describe('List', () => { const loading = { spinning: true, }; - const wrapper = render( + const { container: wrapper } = render( } />, ); - expect(wrapper.find('.ant-list-empty-text')).toHaveLength(0); + expect(wrapper.querySelectorAll('.ant-list-empty-text')).toHaveLength(0); }); it('renders object loading', () => { const loading = { spinning: true, }; - const wrapper = render( + const { container: wrapper } = render( } />, ); - expect(wrapper.find('.ant-spin-spinning')).toHaveLength(1); + expect(wrapper.querySelectorAll('.ant-spin-spinning')).toHaveLength(1); }); it('renders object loading with indicator', () => { @@ -32,9 +32,9 @@ describe('List', () => { spinning: true, indicator: antIcon, }; - const wrapper = render( + const { container: wrapper } = render( } />, ); - expect(wrapper.find('.anticon-loading')).toHaveLength(1); + expect(wrapper.querySelectorAll('.anticon-loading')).toHaveLength(1); }); }); diff --git a/components/list/__tests__/pagination.test.js b/components/list/__tests__/pagination.test.js index 682d89c7a5..bfc08e401b 100644 --- a/components/list/__tests__/pagination.test.js +++ b/components/list/__tests__/pagination.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { render, mount } from 'enzyme'; +import { fireEvent, render } from '../../../tests/utils'; import List from '..'; import { noop } from '../../_util/warning'; @@ -26,47 +26,58 @@ describe('List.pagination', () => { } function renderedNames(wrapper) { - return wrapper.find('.ant-list-item').map(row => row.text()); + return Array.prototype.map.call( + wrapper.querySelectorAll('.ant-list-item'), + row => row.textContent, + ); } it('renders pagination correctly', () => { - const wrapper = render(createList()); - expect(wrapper).toMatchSnapshot(); + const { container } = render(createList()); + expect(container.firstChild).toMatchSnapshot(); }); it('should not show pager if pagination.hideOnSinglePage is true and only 1 page', () => { - const wrapper = mount(createList({ pagination: { pageSize: 3, hideOnSinglePage: true } })); - expect(wrapper.find('.ant-pagination')).toHaveLength(1); - wrapper.setProps({ pagination: { pageSize: 3, hideOnSinglePage: false } }); - expect(wrapper.find('.ant-pagination')).toHaveLength(1); - wrapper.setProps({ pagination: { pageSize: 4, hideOnSinglePage: true } }); - expect(wrapper.find('.ant-pagination')).toHaveLength(0); - wrapper.setProps({ pagination: { pageSize: 4, hideOnSinglePage: false } }); - expect(wrapper.find('.ant-pagination')).toHaveLength(1); - wrapper.setProps({ pagination: { pageSize: 5, hideOnSinglePage: true } }); - expect(wrapper.find('.ant-pagination')).toHaveLength(0); - wrapper.setProps({ pagination: { pageSize: 5, hideOnSinglePage: false } }); - expect(wrapper.find('.ant-pagination')).toHaveLength(1); + const { container: wrapper, rerender } = render( + createList({ + pagination: { + pageSize: 3, + hideOnSinglePage: true, + }, + }), + ); + expect(wrapper.querySelectorAll('.ant-pagination')).toHaveLength(1); + rerender(createList({ pagination: { pageSize: 3, hideOnSinglePage: false } })); + expect(wrapper.querySelectorAll('.ant-pagination')).toHaveLength(1); + rerender(createList({ pagination: { pageSize: 4, hideOnSinglePage: true } })); + expect(wrapper.querySelectorAll('.ant-pagination')).toHaveLength(0); + rerender(createList({ pagination: { pageSize: 4, hideOnSinglePage: false } })); + expect(wrapper.querySelectorAll('.ant-pagination')).toHaveLength(1); + rerender(createList({ pagination: { pageSize: 5, hideOnSinglePage: true } })); + expect(wrapper.querySelectorAll('.ant-pagination')).toHaveLength(0); + rerender(createList({ pagination: { pageSize: 5, hideOnSinglePage: false } })); + expect(wrapper.querySelectorAll('.ant-pagination')).toHaveLength(1); }); it('paginate data', () => { - const wrapper = mount(createList()); - + const { container: wrapper } = render(createList()); expect(renderedNames(wrapper)).toEqual(['Jack', 'Lucy']); - wrapper.find('Pager').last().simulate('click'); + + const paginationItems = wrapper.querySelectorAll('.ant-pagination-item'); + fireEvent.click(paginationItems[paginationItems.length - 1]); expect(renderedNames(wrapper)).toEqual(['Tom', 'Jerry']); }); it('repaginates when pageSize change', () => { - const wrapper = mount(createList()); + const { container: wrapper, rerender } = render(createList()); - wrapper.setProps({ pagination: { pageSize: 1 } }); + rerender(createList({ pagination: { pageSize: 1 } })); expect(renderedNames(wrapper)).toEqual(['Jack']); }); it('fires change event', () => { const handlePaginationChange = jest.fn(); - const wrapper = mount( + const { container: wrapper } = render( createList({ pagination: { ...pagination, @@ -76,7 +87,8 @@ describe('List.pagination', () => { }), ); - wrapper.find('Pager').last().simulate('click'); + const paginationItems = wrapper.querySelectorAll('.ant-pagination-item'); + fireEvent.click(paginationItems[paginationItems.length - 1]); expect(handlePaginationChange).toHaveBeenCalledWith(2, 2); }); @@ -84,56 +96,70 @@ describe('List.pagination', () => { // https://github.com/ant-design/ant-design/issues/4532 // https://codepen.io/afc163/pen/pWVRJV?editors=001 it('should display pagination as prop pagination change between true and false', () => { - const wrapper = mount(createList()); - expect(wrapper.find('.ant-pagination')).toHaveLength(1); - expect(wrapper.find('.ant-pagination-item')).toHaveLength(2); - wrapper.setProps({ pagination: false }); - expect(wrapper.find('.ant-pagination')).toHaveLength(0); - wrapper.setProps({ pagination }); - wrapper.update(); - expect(wrapper.find('.ant-pagination')).toHaveLength(1); - expect(wrapper.find('.ant-pagination-item')).toHaveLength(2); - wrapper.find('.ant-pagination-item-2').simulate('click'); + const { container: wrapper, rerender } = render(createList()); + expect(wrapper.querySelectorAll('.ant-pagination')).toHaveLength(1); + expect(wrapper.querySelectorAll('.ant-pagination-item')).toHaveLength(2); + + rerender(createList({ pagination: false })); + expect(wrapper.querySelectorAll('.ant-pagination')).toHaveLength(0); + + rerender(createList({ pagination })); + expect(wrapper.querySelectorAll('.ant-pagination')).toHaveLength(1); + expect(wrapper.querySelectorAll('.ant-pagination-item')).toHaveLength(2); + + fireEvent.click(wrapper.querySelector('.ant-pagination-item-2')); expect(renderedNames(wrapper)).toEqual(['Tom', 'Jerry']); - wrapper.setProps({ pagination: false }); - expect(wrapper.find('.ant-pagination')).toHaveLength(0); - wrapper.setProps({ pagination: true }); - expect(wrapper.find('.ant-pagination')).toHaveLength(1); + + rerender(createList({ pagination: false })); + expect(wrapper.querySelectorAll('.ant-pagination')).toHaveLength(0); + + rerender(createList({ pagination: true })); + expect(wrapper.querySelectorAll('.ant-pagination')).toHaveLength(1); // Legacy code will make pageSize ping with 10, here we fixed to keep sync by current one - expect(wrapper.find('.ant-pagination-item')).toHaveLength(2); + expect(wrapper.querySelectorAll('.ant-pagination-item')).toHaveLength(2); expect(renderedNames(wrapper)).toEqual(['Tom', 'Jerry']); }); // https://github.com/ant-design/ant-design/issues/5259 it('change to correct page when data source changes', () => { - const wrapper = mount(createList({ pagination: { pageSize: 1 } })); - wrapper.find('.ant-pagination-item-3').simulate('click'); - wrapper.setProps({ dataSource: [data[0]] }); - expect(wrapper.find('.ant-pagination-item-1').hasClass('ant-pagination-item-active')).toBe( - true, + const { container: wrapper, rerender } = render(createList({ pagination: { pageSize: 1 } })); + fireEvent.click(wrapper.querySelector('.ant-pagination-item-3')); + rerender(createList({ dataSource: [data[0]] })); + expect(wrapper.querySelector('.ant-pagination-item-1')).toHaveClass( + 'ant-pagination-item-active', ); }); it('specify the position of pagination', () => { - const wrapper = mount(createList({ pagination: { position: 'top' } })); - expect(wrapper.find('.ant-list').childAt(0).find('.ant-pagination')).toHaveLength(1); - wrapper.setProps({ pagination: { position: 'bottom' } }); - expect(wrapper.find('.ant-list').children().last().find('.ant-pagination')).toHaveLength(1); - wrapper.setProps({ pagination: { position: 'both' } }); - expect(wrapper.find('.ant-pagination')).toHaveLength(2); - expect(wrapper.find('.ant-list').childAt(0).find('.ant-pagination')).toHaveLength(1); - expect(wrapper.find('.ant-list').children().last().find('.ant-pagination')).toHaveLength(1); + const { container: wrapper, rerender } = render( + createList({ pagination: { position: 'top' } }), + ); + expect(wrapper.querySelector('.ant-list').querySelectorAll('.ant-pagination')).toHaveLength(1); + + rerender(createList({ pagination: { position: 'bottom' } })); + expect( + wrapper.querySelector('.ant-list').lastElementChild.querySelectorAll('.ant-pagination'), + ).toHaveLength(1); + + rerender(createList({ pagination: { position: 'both' } })); + expect(wrapper.querySelectorAll('.ant-pagination')).toHaveLength(2); + expect( + wrapper.querySelector('.ant-list').firstElementChild.querySelectorAll('.ant-pagination'), + ).toHaveLength(1); + expect( + wrapper.querySelector('.ant-list').lastElementChild.querySelectorAll('.ant-pagination'), + ).toHaveLength(1); }); it('should change page size work', () => { - const wrapper = mount(createList({ pagination: { showSizeChanger: true } })); - expect(wrapper.find('Pagination').first().render()).toMatchSnapshot(); + const { container: wrapper } = render(createList({ pagination: { showSizeChanger: true } })); + expect(wrapper.querySelector('.ant-pagination')).toMatchSnapshot(); - wrapper.find('.ant-select-selector').simulate('mousedown'); - wrapper.find('.ant-select-item-option').at(2).simulate('click'); + fireEvent.mouseDown(wrapper.querySelector('.ant-select-selector')); + fireEvent.click(wrapper.querySelectorAll('.ant-select-item-option')[2]); - wrapper.find('.ant-select-selector').simulate('mousedown'); - expect(wrapper.find('Pagination').first().render()).toMatchSnapshot(); + fireEvent.mouseDown(wrapper.querySelector('.ant-select-selector')); + expect(wrapper.querySelector('.ant-pagination')).toMatchSnapshot(); }); // https://github.com/ant-design/ant-design/issues/24913 @@ -141,7 +167,7 @@ describe('List.pagination', () => { it('should onChange called when pageSize change', () => { const handlePaginationChange = jest.fn(); const handlePageSizeChange = () => {}; - const wrapper = mount( + const { container: wrapper } = render( createList({ pagination: { ...pagination, @@ -152,13 +178,13 @@ describe('List.pagination', () => { }), ); - wrapper.find('.ant-select-selector').simulate('mousedown'); - wrapper.find('.ant-select-item-option').at(1).simulate('click'); + fireEvent.mouseDown(wrapper.querySelector('.ant-select-selector')); + fireEvent.click(wrapper.querySelectorAll('.ant-select-item-option')[1]); expect(handlePaginationChange).toHaveBeenCalledWith(1, 10); }); it('should default work', () => { - const wrapper = mount( + const { container: wrapper } = render( createList({ pagination: { defaultPageSize: 3, @@ -169,11 +195,11 @@ describe('List.pagination', () => { }), ); - expect(wrapper.find('Pagination').first().render()).toMatchSnapshot(); + expect(wrapper.querySelector('.ant-pagination')).toMatchSnapshot(); }); it('should not crash when pagination is null', () => { - mount( + render( createList({ pagination: null, }), diff --git a/components/locale-provider/__tests__/__snapshots__/index.test.js.snap b/components/locale-provider/__tests__/__snapshots__/index.test.js.snap index 93c70509ae..e65134336d 100644 --- a/components/locale-provider/__tests__/__snapshots__/index.test.js.snap +++ b/components/locale-provider/__tests__/__snapshots__/index.test.js.snap @@ -6854,11 +6854,11 @@ exports[`Locale Provider should display the text as ar 1`] = ` class="ant-modal-mask ant-fade-appear ant-fade-appear-start ant-fade" />