import { render, mount } from 'enzyme'; import React from 'react'; import type { BasicLayoutProps } from '@ant-design/pro-layout'; import BasicLayout, { PageContainer, FooterToolbar } from '@ant-design/pro-layout'; import { act } from 'react-dom/test-utils'; import { waitForComponentToPaint } from '../util'; describe('PageContainer', () => { it('💄 base use', async () => { const html = render(); expect(html).toMatchSnapshot(); }); it('💄 config is null', async () => { const html = render(); expect(html).toMatchSnapshot(); }); it('⚡️ support footer', async () => { const html = render( right , ]} />, ); expect(html).toMatchSnapshot(); }); it('⚡️ support fixedHeader', async () => { const html = render(); expect(html).toMatchSnapshot(); }); it('⚡️ support fixHeader', async () => { const html = render(); expect(html).toMatchSnapshot(); }); it('⚡️ support loading', async () => { const html = render(); expect(html).toMatchSnapshot(); }); it('⚡️ support more loading props', async () => { const html = render(); expect(html).toMatchSnapshot(); }); it('🔥 support footer and breadcrumb', async () => { const html = render( right , ]} />, ); expect(html).toMatchSnapshot(); }); it('🔥 footer bar support extra', async () => { const html = render( } > , ); expect(html).toMatchSnapshot(); }); it('🔥 footer bar support renderContent', async () => { const html = render( } renderContent={() => { return 'home_toolbar'; }} > , ); expect(html).toMatchSnapshot(); }); it('🐲 footer should know width', async () => { const wrapper = mount( qixian , ]} /> , ); await waitForComponentToPaint(wrapper); expect(wrapper?.find('.ant-pro-footer-bar')?.props()?.style?.width).toBe('calc(100% - 208px)'); wrapper.setProps({ collapsed: true, }); await waitForComponentToPaint(wrapper); expect(wrapper?.find('.ant-pro-footer-bar')?.props()?.style?.width).toBe('calc(100% - 48px)'); wrapper.setProps({ layout: 'top', }); expect(wrapper?.find('.ant-pro-footer-bar')?.props()?.style?.width).toBe('100%'); expect(wrapper.render()).toMatchSnapshot(); }); it('🐲 FooterToolbar should know width', async () => { const wrapper = mount( , ); await waitForComponentToPaint(wrapper); expect(wrapper?.find('.ant-pro-footer-bar')?.props()?.style?.width).toBe('calc(100% - 208px)'); wrapper.setProps({ collapsed: true, }); await waitForComponentToPaint(wrapper); expect(wrapper.find('.ant-pro-footer-bar')?.props()?.style?.width).toBe('calc(100% - 48px)'); wrapper.setProps({ layout: 'top', }); expect(wrapper.find('.ant-pro-footer-bar')?.props()?.style?.width).toBe('100%'); expect(wrapper.render()).toMatchSnapshot(); // test useUseEffect render function act(() => { wrapper.unmount(); }); }); it('🐲 footer is null, do not render footerToolbar ', async () => { const wrapper = mount( qixian , ]} />, ); await waitForComponentToPaint(wrapper); expect(wrapper.render()).toMatchSnapshot(); wrapper.setProps({ footer: undefined, }); await waitForComponentToPaint(wrapper); expect(wrapper.render()).toMatchSnapshot(); }); it('🐲 prolayout support breadcrumbProps', async () => { const wrapper = mount( ', routes: [ { path: 'index', breadcrumbName: 'home', }, { path: 'first', breadcrumbName: 'first', children: [ { path: '/general', breadcrumbName: 'General', }, { path: '/layout', breadcrumbName: 'Layout', }, { path: '/navigation', breadcrumbName: 'Navigation', }, ], }, { path: 'second', breadcrumbName: 'second', }, ], }} > , ); expect(wrapper.render()).toMatchSnapshot(); }); it('🐲 header.footer is null, do not render footerToolbar ', async () => { const wrapper = mount( qixian , ]} />, ); await waitForComponentToPaint(wrapper); expect(wrapper.find('.ant-pro-footer-bar').exists()).toBeTruthy(); wrapper.setProps({ footer: undefined }); await waitForComponentToPaint(wrapper); expect(wrapper.find('.ant-pro-footer-bar').exists()).toBeFalsy(); }); it('🐲 tabList and onTabChange is run', async () => { const fn = jest.fn(); const wrapper = mount( , ); await waitForComponentToPaint(wrapper); act(() => { wrapper.find('.ant-tabs-nav-list .ant-tabs-tab').at(1).simulate('click'); }); expect(fn).toBeCalledWith('info'); }); it('content is text and title is null', () => { const html = render(); expect(html).toMatchSnapshot(); const html2 = render(extraContent} />); expect(html2).toMatchSnapshot(); }); });