2022-06-22 14:57:09 +08:00
|
|
|
import React from 'react';
|
|
|
|
import accessibilityTest from '../../../tests/shared/accessibilityTest';
|
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';
|
2022-06-22 14:57:09 +08:00
|
|
|
import { render } from '../../../tests/utils';
|
2022-09-05 19:41:32 +08:00
|
|
|
import type { Route } from '../Breadcrumb';
|
2022-06-22 14:57:09 +08:00
|
|
|
import Breadcrumb from '../index';
|
2017-01-27 17:08:05 +08:00
|
|
|
|
|
|
|
describe('Breadcrumb', () => {
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(Breadcrumb);
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(Breadcrumb);
|
2022-03-31 09:57:33 +08:00
|
|
|
accessibilityTest(Breadcrumb);
|
2019-08-26 22:53:20 +08:00
|
|
|
|
2017-03-17 18:56:30 +08:00
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
errorSpy.mockReset();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
errorSpy.mockRestore();
|
|
|
|
});
|
|
|
|
|
2019-07-31 10:47:34 +08:00
|
|
|
it('warns on non-Breadcrumb.Item and non-Breadcrumb.Separator children', () => {
|
2022-09-05 19:41:32 +08:00
|
|
|
const MyCom: React.FC = () => <div>foo</div>;
|
2022-04-06 11:07:15 +08:00
|
|
|
render(
|
2017-01-27 17:08:05 +08:00
|
|
|
<Breadcrumb>
|
|
|
|
<MyCom />
|
2018-12-07 16:17:45 +08:00
|
|
|
</Breadcrumb>,
|
2017-01-27 17:08:05 +08:00
|
|
|
);
|
2022-04-18 21:02:11 +08:00
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
2019-07-31 10:47:34 +08:00
|
|
|
"Warning: [antd: Breadcrumb] Only accepts Breadcrumb.Item and Breadcrumb.Separator as it's children",
|
2017-01-27 17:08:05 +08:00
|
|
|
);
|
|
|
|
});
|
2017-02-23 13:43:50 +08:00
|
|
|
|
2022-10-23 00:33:45 +08:00
|
|
|
it('overlay deprecation warning', () => {
|
|
|
|
render(
|
|
|
|
<Breadcrumb>
|
|
|
|
<Breadcrumb.Item overlay={<div>menu</div>}>
|
|
|
|
<a href="">General</a>
|
|
|
|
</Breadcrumb.Item>
|
|
|
|
</Breadcrumb>,
|
|
|
|
);
|
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
|
|
|
'Warning: [antd: Breadcrumb.Item] `overlay` is deprecated. Please use `menu` instead.',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2017-02-23 13:43:50 +08:00
|
|
|
// https://github.com/ant-design/ant-design/issues/5015
|
|
|
|
it('should allow Breadcrumb.Item is null or undefined', () => {
|
2022-04-06 11:07:15 +08:00
|
|
|
const { asFragment } = render(
|
2017-02-23 13:43:50 +08:00
|
|
|
<Breadcrumb>
|
|
|
|
{null}
|
|
|
|
<Breadcrumb.Item>Home</Breadcrumb.Item>
|
|
|
|
{undefined}
|
2018-12-07 16:17:45 +08:00
|
|
|
</Breadcrumb>,
|
2017-02-23 13:43:50 +08:00
|
|
|
);
|
2017-03-17 18:56:30 +08:00
|
|
|
expect(errorSpy).not.toHaveBeenCalled();
|
2022-04-06 11:07:15 +08:00
|
|
|
expect(asFragment().firstChild).toMatchSnapshot();
|
2017-02-23 13:43:50 +08:00
|
|
|
});
|
2017-03-29 15:13:20 +08:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/5542
|
|
|
|
it('should not display Breadcrumb Item when its children is falsy', () => {
|
2022-06-28 18:47:21 +08:00
|
|
|
const { asFragment } = render(
|
2017-03-29 15:13:20 +08:00
|
|
|
<Breadcrumb>
|
|
|
|
<Breadcrumb.Item />
|
|
|
|
<Breadcrumb.Item>xxx</Breadcrumb.Item>
|
|
|
|
<Breadcrumb.Item>yyy</Breadcrumb.Item>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Breadcrumb>,
|
2017-03-29 15:13:20 +08:00
|
|
|
);
|
2022-06-28 18:47:21 +08:00
|
|
|
expect(asFragment().firstChild).toMatchSnapshot();
|
2017-03-29 15:13:20 +08:00
|
|
|
});
|
2019-05-06 12:04:39 +08:00
|
|
|
|
2019-08-20 15:58:37 +08:00
|
|
|
// https://github.com/ant-design/ant-design/issues/18260
|
|
|
|
it('filter React.Fragment', () => {
|
2022-06-28 18:47:21 +08:00
|
|
|
const { asFragment } = render(
|
2019-08-20 15:58:37 +08:00
|
|
|
<Breadcrumb separator="">
|
|
|
|
<Breadcrumb.Item>Location</Breadcrumb.Item>
|
|
|
|
<Breadcrumb.Separator>:</Breadcrumb.Separator>
|
|
|
|
<>
|
|
|
|
<Breadcrumb.Item href="">Application Center</Breadcrumb.Item>
|
|
|
|
<Breadcrumb.Separator />
|
|
|
|
</>
|
|
|
|
</Breadcrumb>,
|
|
|
|
);
|
2022-06-28 18:47:21 +08:00
|
|
|
expect(asFragment().firstChild).toMatchSnapshot();
|
2019-08-20 15:58:37 +08:00
|
|
|
});
|
|
|
|
|
2019-05-06 12:04:39 +08:00
|
|
|
it('should render a menu', () => {
|
2022-09-05 19:41:32 +08:00
|
|
|
const routes: Route[] = [
|
2019-05-06 12:04:39 +08:00
|
|
|
{
|
|
|
|
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',
|
|
|
|
},
|
2020-03-29 22:17:55 +08:00
|
|
|
{
|
|
|
|
path: 'third',
|
2022-09-05 19:41:32 +08:00
|
|
|
breadcrumbName: '',
|
2020-03-29 22:17:55 +08:00
|
|
|
},
|
2019-05-06 12:04:39 +08:00
|
|
|
];
|
2022-06-28 18:47:21 +08:00
|
|
|
const { asFragment } = render(<Breadcrumb routes={routes} />);
|
|
|
|
expect(asFragment().firstChild).toMatchSnapshot();
|
2019-05-06 12:04:39 +08:00
|
|
|
});
|
2019-07-09 11:46:21 +08:00
|
|
|
|
2020-03-29 22:17:55 +08:00
|
|
|
it('should accept undefined routes', () => {
|
2022-06-28 18:47:21 +08:00
|
|
|
const { asFragment } = render(<Breadcrumb routes={undefined} />);
|
|
|
|
expect(asFragment().firstChild).toMatchSnapshot();
|
2019-07-09 11:46:21 +08:00
|
|
|
});
|
2019-09-26 22:28:08 +08:00
|
|
|
|
2019-09-23 11:52:29 +08:00
|
|
|
it('should support custom attribute', () => {
|
2022-06-28 18:47:21 +08:00
|
|
|
const { asFragment } = render(
|
2019-09-23 11:52:29 +08:00
|
|
|
<Breadcrumb data-custom="custom">
|
|
|
|
<Breadcrumb.Item data-custom="custom-item">xxx</Breadcrumb.Item>
|
|
|
|
<Breadcrumb.Item>yyy</Breadcrumb.Item>
|
|
|
|
</Breadcrumb>,
|
|
|
|
);
|
2022-06-28 18:47:21 +08:00
|
|
|
expect(asFragment().firstChild).toMatchSnapshot();
|
2019-09-23 11:52:29 +08:00
|
|
|
});
|
2020-03-29 22:17:55 +08:00
|
|
|
|
|
|
|
it('should support React.Fragment and falsy children', () => {
|
2022-06-28 18:47:21 +08:00
|
|
|
const { asFragment } = render(
|
2020-03-29 22:17:55 +08:00
|
|
|
<Breadcrumb>
|
|
|
|
<>
|
|
|
|
<Breadcrumb.Item>yyy</Breadcrumb.Item>
|
|
|
|
<Breadcrumb.Item>yyy</Breadcrumb.Item>
|
|
|
|
</>
|
|
|
|
<Breadcrumb.Item>yyy</Breadcrumb.Item>
|
|
|
|
{0}
|
|
|
|
{null}
|
|
|
|
{undefined}
|
|
|
|
</Breadcrumb>,
|
|
|
|
);
|
2022-06-28 18:47:21 +08:00
|
|
|
expect(asFragment().firstChild).toMatchSnapshot();
|
2020-03-29 22:17:55 +08:00
|
|
|
});
|
2020-08-03 21:34:29 +08:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/25975
|
|
|
|
it('should support Breadcrumb.Item default separator', () => {
|
2022-09-05 19:41:32 +08:00
|
|
|
const MockComponent: React.FC = () => (
|
2020-12-09 17:12:32 +08:00
|
|
|
<span>
|
|
|
|
<Breadcrumb.Item>Mock Node</Breadcrumb.Item>
|
|
|
|
</span>
|
|
|
|
);
|
2022-06-28 18:47:21 +08:00
|
|
|
const { asFragment } = render(
|
2020-08-03 21:34:29 +08:00
|
|
|
<Breadcrumb>
|
|
|
|
<Breadcrumb.Item>Location</Breadcrumb.Item>
|
|
|
|
<MockComponent />
|
|
|
|
<Breadcrumb.Item>Application Center</Breadcrumb.Item>
|
2020-08-03 21:53:13 +08:00
|
|
|
</Breadcrumb>,
|
2020-08-03 21:34:29 +08:00
|
|
|
);
|
2022-06-28 18:47:21 +08:00
|
|
|
expect(asFragment().firstChild).toMatchSnapshot();
|
2020-08-03 21:34:29 +08:00
|
|
|
});
|
2022-10-14 11:37:48 +08:00
|
|
|
it('should support string `0` and number `0`', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<Breadcrumb>
|
|
|
|
<Breadcrumb.Item>{0}</Breadcrumb.Item>
|
|
|
|
<Breadcrumb.Item>0</Breadcrumb.Item>
|
|
|
|
</Breadcrumb>,
|
|
|
|
);
|
|
|
|
expect(container.querySelectorAll('.ant-breadcrumb-link')[0].textContent).toBe('0');
|
|
|
|
expect(container.querySelectorAll('.ant-breadcrumb-link')[1].textContent).toBe('0');
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
|
|
|
});
|
2017-01-27 17:08:05 +08:00
|
|
|
});
|