2019-03-02 15:51:08 +08:00
|
|
|
import React from 'react';
|
2022-04-18 21:02:11 +08:00
|
|
|
import { mount } from 'enzyme';
|
2019-03-02 15:51:08 +08:00
|
|
|
import PageHeader from '..';
|
2021-05-24 16:24:00 +08:00
|
|
|
import Breadcrumb from '../../breadcrumb';
|
2020-01-02 19:10:16 +08:00
|
|
|
import ConfigProvider from '../../config-provider';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2019-03-02 15:51:08 +08:00
|
|
|
|
|
|
|
describe('PageHeader', () => {
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(PageHeader);
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(PageHeader);
|
2019-08-26 22:53:20 +08:00
|
|
|
|
2020-04-22 11:59:56 +08:00
|
|
|
const mockGetBoundingClientRect = jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect');
|
2020-04-15 12:44:35 +08:00
|
|
|
|
|
|
|
beforeAll(() => {
|
2020-04-22 11:59:56 +08:00
|
|
|
mockGetBoundingClientRect.mockReturnValue({ width: 100 });
|
2020-04-15 12:44:35 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
2020-04-22 11:59:56 +08:00
|
|
|
mockGetBoundingClientRect.mockRestore();
|
2020-04-15 12:44:35 +08:00
|
|
|
});
|
|
|
|
|
2019-03-02 15:51:08 +08:00
|
|
|
it('pageHeader should not contain back it back', () => {
|
|
|
|
const routes = [
|
|
|
|
{
|
|
|
|
path: 'index',
|
|
|
|
breadcrumbName: 'First-level Menu',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'first',
|
|
|
|
breadcrumbName: 'Second-level Menu',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'second',
|
|
|
|
breadcrumbName: 'Third-level Menu',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const wrapper = mount(<PageHeader title="Page Title" breadcrumb={{ routes }} />);
|
2019-04-25 15:13:13 +08:00
|
|
|
expect(wrapper.find('.ant-page-header-back')).toHaveLength(0);
|
2019-03-02 15:51:08 +08:00
|
|
|
});
|
2019-06-20 19:45:13 +08:00
|
|
|
|
|
|
|
it('pageHeader should have breadcrumb', () => {
|
|
|
|
const routes = [
|
|
|
|
{
|
|
|
|
path: 'index',
|
|
|
|
breadcrumbName: 'First-level Menu',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const wrapper = mount(<PageHeader title="Page Title" breadcrumb={{ routes }} />);
|
|
|
|
expect(wrapper.find('.ant-breadcrumb')).toHaveLength(1);
|
2021-05-24 16:24:00 +08:00
|
|
|
expect(wrapper.find('.ant-page-header-back')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('pageHeader should have breadcrumb (component)', () => {
|
|
|
|
const routes = [
|
|
|
|
{
|
|
|
|
path: 'index',
|
|
|
|
breadcrumbName: 'First-level Menu',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const wrapper = mount(
|
|
|
|
<PageHeader title="Page Title" breadcrumb={<Breadcrumb routes={routes} />} />,
|
|
|
|
);
|
|
|
|
expect(wrapper.find('.ant-breadcrumb')).toHaveLength(1);
|
2019-06-20 19:45:13 +08:00
|
|
|
expect(wrapper.find('.ant-page-header-back')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
2021-01-24 17:44:20 +08:00
|
|
|
it('pageHeader support breadcrumbRender', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<PageHeader title="Page Title" breadcrumbRender={() => <div id="test">test</div>} />,
|
|
|
|
);
|
|
|
|
expect(wrapper.find('#test')).toHaveLength(1);
|
|
|
|
expect(wrapper.find('.ant-page-header-back')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
2021-11-10 15:15:02 +08:00
|
|
|
it('pageHeader support breadcrumbRender return false', () => {
|
|
|
|
const wrapper = mount(<PageHeader title="Page Title" breadcrumbRender={() => false} />);
|
|
|
|
expect(wrapper.find('.ant-page-header-back')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
2020-11-01 22:47:10 +08:00
|
|
|
it('pageHeader do not has title', () => {
|
|
|
|
const routes = [
|
|
|
|
{
|
|
|
|
path: 'index',
|
|
|
|
breadcrumbName: 'First-level Menu',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const wrapper = mount(<PageHeader breadcrumb={{ routes }}>test</PageHeader>);
|
|
|
|
expect(wrapper.find('.ant-page-header-heading-lef').exists()).toBeFalsy();
|
|
|
|
expect(wrapper.find('.ant-page-header-heading').exists()).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
2019-04-25 12:18:01 +08:00
|
|
|
it('pageHeader should no contain back', () => {
|
2019-03-02 15:51:08 +08:00
|
|
|
const wrapper = mount(<PageHeader title="Page Title" backIcon={false} />);
|
2019-04-25 15:13:13 +08:00
|
|
|
expect(wrapper.find('.ant-page-header-back')).toHaveLength(0);
|
2019-03-02 15:51:08 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('pageHeader should contain back it back', () => {
|
|
|
|
const callback = jest.fn(() => true);
|
|
|
|
const wrapper = mount(<PageHeader title="Page Title" onBack={callback} />);
|
2019-04-25 15:13:13 +08:00
|
|
|
expect(wrapper.find('.ant-page-header-back')).toHaveLength(1);
|
2019-03-02 15:51:08 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('pageHeader onBack transfer', () => {
|
|
|
|
const callback = jest.fn(() => true);
|
|
|
|
const wrapper = mount(<PageHeader title="Page Title" onBack={callback} />);
|
2019-04-25 15:13:13 +08:00
|
|
|
wrapper.find('div.ant-page-header-back-button').simulate('click');
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(callback).toHaveBeenCalled();
|
2019-03-02 15:51:08 +08:00
|
|
|
});
|
2019-03-04 14:54:28 +08:00
|
|
|
|
|
|
|
it('pageHeader should support className', () => {
|
2022-04-18 21:02:11 +08:00
|
|
|
const wrapper = mount(<PageHeader title="Page Title" className="not-works" backIcon={false} />);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2019-03-04 14:54:28 +08:00
|
|
|
});
|
2019-05-09 23:19:10 +08:00
|
|
|
|
|
|
|
it('pageHeader should not render blank dom', () => {
|
2022-04-18 21:02:11 +08:00
|
|
|
const wrapper = mount(<PageHeader title={false} />);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2019-05-09 23:19:10 +08:00
|
|
|
});
|
2019-08-25 15:38:51 +08:00
|
|
|
|
2019-09-06 13:30:47 +08:00
|
|
|
it('breadcrumbs and back icon can coexist', () => {
|
2019-08-25 15:38:51 +08:00
|
|
|
const routes = [
|
|
|
|
{
|
|
|
|
path: 'index',
|
|
|
|
breadcrumbName: 'First-level Menu',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'first',
|
|
|
|
breadcrumbName: 'Second-level Menu',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'second',
|
|
|
|
breadcrumbName: 'Third-level Menu',
|
|
|
|
},
|
|
|
|
];
|
2019-09-06 13:30:47 +08:00
|
|
|
const wrapper = mount(<PageHeader title="Title" breadcrumb={{ routes }} />);
|
|
|
|
expect(wrapper.find('.ant-breadcrumb')).toHaveLength(1);
|
2019-08-25 15:38:51 +08:00
|
|
|
|
2019-09-06 13:30:47 +08:00
|
|
|
wrapper.setProps({ onBack: () => {} });
|
2019-08-25 15:38:51 +08:00
|
|
|
expect(wrapper.find('.ant-breadcrumb')).toHaveLength(1);
|
|
|
|
});
|
2020-01-02 19:10:16 +08:00
|
|
|
|
|
|
|
it('pageHeader should render correctly int RTL direction', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<ConfigProvider direction="rtl">
|
|
|
|
<PageHeader title="Page Title" />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
2022-04-18 21:02:11 +08:00
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2020-01-02 19:10:16 +08:00
|
|
|
});
|
2020-04-15 12:44:35 +08:00
|
|
|
|
2020-08-18 16:46:05 +08:00
|
|
|
it('change container width', async () => {
|
2020-04-15 12:44:35 +08:00
|
|
|
const wrapper = mount(<PageHeader title="Page Title" extra="extra" />);
|
|
|
|
wrapper.triggerResize();
|
2020-08-18 16:46:05 +08:00
|
|
|
await Promise.resolve();
|
2020-04-15 12:44:35 +08:00
|
|
|
wrapper.update();
|
2021-11-30 17:26:51 +08:00
|
|
|
expect(wrapper.find('.ant-page-header').hasClass('ant-page-header-compact')).toBeTruthy();
|
2020-04-15 12:44:35 +08:00
|
|
|
});
|
2019-03-02 15:51:08 +08:00
|
|
|
});
|