2019-03-02 15:51:08 +08:00
|
|
|
import React from 'react';
|
2019-03-04 14:54:28 +08:00
|
|
|
import { mount, render } from 'enzyme';
|
2019-03-02 15:51:08 +08:00
|
|
|
import PageHeader from '..';
|
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);
|
|
|
|
expect(wrapper.find('.ant-page-header-back')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
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', () => {
|
|
|
|
const wrapper = render(
|
|
|
|
<PageHeader title="Page Title" className="not-works" backIcon={false} />,
|
|
|
|
);
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
2019-05-09 23:19:10 +08:00
|
|
|
|
|
|
|
it('pageHeader should not render blank dom', () => {
|
|
|
|
const wrapper = render(<PageHeader title={false} />);
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
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>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(render(wrapper)).toMatchSnapshot();
|
|
|
|
});
|
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();
|
|
|
|
expect(wrapper.find('.ant-page-header').hasClass('ant-page-header-compact')).toBe(true);
|
|
|
|
});
|
2019-03-02 15:51:08 +08:00
|
|
|
});
|