2020-08-03 03:41:42 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
2020-03-07 11:45:13 +00:00
|
|
|
import PageHeader from '..';
|
|
|
|
|
|
|
|
describe('PageHeader', () => {
|
|
|
|
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({
|
|
|
|
render() {
|
2020-08-03 03:41:42 +00:00
|
|
|
return <PageHeader title="Page Title" breadcrumb={{ routes }} />;
|
2020-03-07 11:45:13 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.findAll('.ant-page-header-back')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('pageHeader should have breadcrumb', () => {
|
|
|
|
const routes = [
|
|
|
|
{
|
|
|
|
path: 'index',
|
|
|
|
breadcrumbName: 'First-level Menu',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
2020-08-03 03:41:42 +00:00
|
|
|
return <PageHeader title="Page Title" breadcrumb={{ routes }} />;
|
2020-03-07 11:45:13 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.findAll('.ant-breadcrumb')).toHaveLength(1);
|
|
|
|
expect(wrapper.findAll('.ant-page-header-back')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('pageHeader should no contain back', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <PageHeader title="Page Title" backIcon={false} />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.findAll('.ant-page-header-back')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('pageHeader should contain back it back', () => {
|
|
|
|
const callback = jest.fn(() => true);
|
|
|
|
const wrapper = mount(
|
|
|
|
{
|
|
|
|
render() {
|
|
|
|
return <PageHeader title="Page Title" onBack={callback} />;
|
|
|
|
},
|
|
|
|
},
|
2020-08-03 03:41:42 +00:00
|
|
|
{ sync: false },
|
2020-03-07 11:45:13 +00:00
|
|
|
);
|
|
|
|
expect(wrapper.findAll('.ant-page-header-back')).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('pageHeader onBack transfer', () => {
|
|
|
|
const callback = jest.fn(() => true);
|
|
|
|
const wrapper = mount(
|
|
|
|
{
|
|
|
|
render() {
|
|
|
|
return <PageHeader title="Page Title" onBack={callback} />;
|
|
|
|
},
|
|
|
|
},
|
2020-08-03 03:41:42 +00:00
|
|
|
{ sync: false },
|
2020-03-07 11:45:13 +00:00
|
|
|
);
|
|
|
|
wrapper.find('div.ant-page-header-back-button').trigger('click');
|
|
|
|
expect(callback).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('pageHeader should support class', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <PageHeader title="Page Title" class="not-works" backIcon={false} />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('pageHeader should not render blank dom', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <PageHeader title={false} />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('breadcrumbs and back icon can coexist', () => {
|
|
|
|
const routes = [
|
|
|
|
{
|
|
|
|
path: 'index',
|
|
|
|
breadcrumbName: 'First-level Menu',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'first',
|
|
|
|
breadcrumbName: 'Second-level Menu',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'second',
|
|
|
|
breadcrumbName: 'Third-level Menu',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
2020-08-03 03:41:42 +00:00
|
|
|
return <PageHeader title="Title" breadcrumb={{ routes }} />;
|
2020-03-07 11:45:13 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.findAll('.ant-breadcrumb')).toHaveLength(1);
|
|
|
|
|
2020-08-03 03:41:42 +00:00
|
|
|
const wrapperBack = mount({
|
|
|
|
render() {
|
|
|
|
return <PageHeader title="Title" breadcrumb={{ routes }} onBack={() => {}} />;
|
2020-03-07 11:45:13 +00:00
|
|
|
},
|
2020-08-03 03:41:42 +00:00
|
|
|
});
|
2020-03-07 11:45:13 +00:00
|
|
|
expect(wrapperBack.findAll('.ant-breadcrumb')).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|