2019-05-22 23:22:09 +08:00
|
|
|
|
import React from 'react';
|
2019-05-27 16:41:56 +08:00
|
|
|
|
import MockDate from 'mockdate';
|
2019-05-22 23:22:09 +08:00
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
|
import Descriptions from '..';
|
2019-08-26 22:53:20 +08:00
|
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2022-05-10 15:43:29 +08:00
|
|
|
|
import { resetWarned } from '../../_util/warning';
|
2019-05-22 23:22:09 +08:00
|
|
|
|
|
|
|
|
|
describe('Descriptions', () => {
|
2019-08-26 22:53:20 +08:00
|
|
|
|
mountTest(Descriptions);
|
|
|
|
|
|
2019-05-27 16:41:56 +08:00
|
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
MockDate.reset();
|
|
|
|
|
errorSpy.mockReset();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
|
errorSpy.mockRestore();
|
|
|
|
|
});
|
|
|
|
|
|
2019-05-22 23:22:09 +08:00
|
|
|
|
it('when max-width: 575px,column=1', () => {
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
<Descriptions>
|
2019-05-27 21:32:45 +08:00
|
|
|
|
<Descriptions.Item label="Product">Cloud Database</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="Billing">Prepaid</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="time">18:00:00</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="Amount">$80.00</Descriptions.Item>
|
2019-06-27 16:06:34 +08:00
|
|
|
|
<Descriptions.Item>No-Label</Descriptions.Item>
|
2019-05-22 23:22:09 +08:00
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
2019-06-27 16:06:34 +08:00
|
|
|
|
expect(wrapper.find('tr')).toHaveLength(5);
|
2020-02-23 20:48:16 +08:00
|
|
|
|
expect(wrapper.find('.ant-descriptions-item-label')).toHaveLength(4);
|
2019-05-22 23:22:09 +08:00
|
|
|
|
wrapper.unmount();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('when max-width: 575px,column=2', () => {
|
|
|
|
|
// eslint-disable-next-line global-require
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
<Descriptions column={{ xs: 2 }}>
|
2019-05-27 21:32:45 +08:00
|
|
|
|
<Descriptions.Item label="Product">Cloud Database</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="Billing">Prepaid</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="time">18:00:00</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="Amount">$80.00</Descriptions.Item>
|
2019-05-22 23:22:09 +08:00
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
|
|
|
|
expect(wrapper.find('tr')).toHaveLength(2);
|
|
|
|
|
wrapper.unmount();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('column is number', () => {
|
|
|
|
|
// eslint-disable-next-line global-require
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
<Descriptions column="3">
|
2019-05-27 21:32:45 +08:00
|
|
|
|
<Descriptions.Item label="Product">Cloud Database</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="Billing">Prepaid</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="time">18:00:00</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="Amount">$80.00</Descriptions.Item>
|
2019-05-22 23:22:09 +08:00
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
2020-02-23 17:07:55 +08:00
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2019-05-22 23:22:09 +08:00
|
|
|
|
wrapper.unmount();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('when typeof column is object', () => {
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
<Descriptions column={{ xs: 8, sm: 16, md: 24 }}>
|
2019-05-27 21:32:45 +08:00
|
|
|
|
<Descriptions.Item label="Product">Cloud Database</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="Billing">Prepaid</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="time">18:00:00</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="Amount">$80.00</Descriptions.Item>
|
2019-05-22 23:22:09 +08:00
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
2020-02-23 20:48:16 +08:00
|
|
|
|
expect(wrapper.find('td').reduce((total, td) => total + td.props().colSpan, 0)).toBe(8);
|
2019-05-22 23:22:09 +08:00
|
|
|
|
wrapper.unmount();
|
|
|
|
|
});
|
2019-05-27 16:41:56 +08:00
|
|
|
|
|
|
|
|
|
it('warning if ecceed the row span', () => {
|
2019-08-30 12:31:10 +08:00
|
|
|
|
resetWarned();
|
|
|
|
|
|
2019-05-27 16:41:56 +08:00
|
|
|
|
mount(
|
|
|
|
|
<Descriptions column={3}>
|
2019-05-27 21:32:45 +08:00
|
|
|
|
<Descriptions.Item label="Product" span={2}>
|
2019-05-27 16:41:56 +08:00
|
|
|
|
Cloud Database
|
2019-05-27 21:32:45 +08:00
|
|
|
|
</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="Billing" span={2}>
|
2019-05-27 16:41:56 +08:00
|
|
|
|
Prepaid
|
2019-05-27 21:32:45 +08:00
|
|
|
|
</Descriptions.Item>
|
2019-05-27 16:41:56 +08:00
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
|
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
2020-01-10 10:35:20 +08:00
|
|
|
|
'Warning: [antd: Descriptions] Sum of column `span` in a line not match `column` of Descriptions.',
|
2019-05-27 16:41:56 +08:00
|
|
|
|
);
|
|
|
|
|
});
|
2019-06-21 13:49:01 +08:00
|
|
|
|
|
|
|
|
|
it('when item is rendered conditionally', () => {
|
|
|
|
|
const hasDiscount = false;
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
<Descriptions>
|
|
|
|
|
<Descriptions.Item label="Product">Cloud Database</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="Billing">Prepaid</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="time">18:00:00</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="Amount">$80.00</Descriptions.Item>
|
|
|
|
|
{hasDiscount && <Descriptions.Item label="Discount">$20.00</Descriptions.Item>}
|
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
2020-02-23 17:07:55 +08:00
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2019-06-21 13:49:01 +08:00
|
|
|
|
wrapper.unmount();
|
|
|
|
|
});
|
2019-06-27 11:29:33 +08:00
|
|
|
|
|
|
|
|
|
it('vertical layout', () => {
|
|
|
|
|
// eslint-disable-next-line global-require
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
<Descriptions layout="vertical">
|
|
|
|
|
<Descriptions.Item label="Product">Cloud Database</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="Billing">Prepaid</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="time">18:00:00</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="Amount">$80.00</Descriptions.Item>
|
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
2020-02-23 17:07:55 +08:00
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2019-06-27 11:29:33 +08:00
|
|
|
|
wrapper.unmount();
|
|
|
|
|
});
|
2019-06-28 21:55:15 +08:00
|
|
|
|
|
2019-06-26 16:05:46 +08:00
|
|
|
|
it('Descriptions.Item support className', () => {
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
<Descriptions>
|
|
|
|
|
<Descriptions.Item label="Product" className="my-class">
|
|
|
|
|
Cloud Database
|
|
|
|
|
</Descriptions.Item>
|
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
2020-02-23 17:07:55 +08:00
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2019-06-26 16:05:46 +08:00
|
|
|
|
});
|
2019-07-10 10:32:02 +08:00
|
|
|
|
|
|
|
|
|
it('Descriptions support colon', () => {
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
<Descriptions colon={false}>
|
|
|
|
|
<Descriptions.Item label="Product">Cloud Database</Descriptions.Item>
|
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
2020-02-23 17:07:55 +08:00
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2019-07-10 10:32:02 +08:00
|
|
|
|
});
|
2019-07-15 10:01:37 +08:00
|
|
|
|
|
2019-07-10 10:01:31 +08:00
|
|
|
|
it('Descriptions support style', () => {
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
<Descriptions style={{ backgroundColor: '#e8e8e8' }}>
|
|
|
|
|
<Descriptions.Item>Cloud Database</Descriptions.Item>
|
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
2020-02-23 17:07:55 +08:00
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2019-07-10 10:01:31 +08:00
|
|
|
|
});
|
2019-08-30 15:56:44 +08:00
|
|
|
|
|
|
|
|
|
it('keep key', () => {
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
<Descriptions>
|
|
|
|
|
<Descriptions.Item key="bamboo" />
|
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
|
|
|
|
|
2020-02-23 20:48:16 +08:00
|
|
|
|
expect(wrapper.find('Cell').key()).toBe('item-bamboo');
|
2019-08-30 15:56:44 +08:00
|
|
|
|
});
|
2019-11-30 18:10:56 +08:00
|
|
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/19887
|
|
|
|
|
it('should work with React Fragment', () => {
|
|
|
|
|
if (!React.Fragment) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
<Descriptions>
|
|
|
|
|
<Descriptions.Item label="bamboo">bamboo</Descriptions.Item>
|
|
|
|
|
<>
|
|
|
|
|
<Descriptions.Item label="bamboo">bamboo</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="bamboo">bamboo</Descriptions.Item>
|
|
|
|
|
</>
|
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
|
});
|
2020-02-23 20:48:16 +08:00
|
|
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/20255
|
|
|
|
|
it('columns 5 with customize', () => {
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
<Descriptions layout="vertical" column={4}>
|
|
|
|
|
{/* 1 1 1 1 */}
|
|
|
|
|
<Descriptions.Item label="bamboo">bamboo</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="bamboo">bamboo</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="bamboo">bamboo</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="bamboo">bamboo</Descriptions.Item>
|
|
|
|
|
{/* 2 2 */}
|
|
|
|
|
<Descriptions.Item label="bamboo" span={2}>
|
|
|
|
|
bamboo
|
|
|
|
|
</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="bamboo" span={2}>
|
|
|
|
|
bamboo
|
|
|
|
|
</Descriptions.Item>
|
|
|
|
|
{/* 3 1 */}
|
|
|
|
|
<Descriptions.Item label="bamboo" span={3}>
|
|
|
|
|
bamboo
|
|
|
|
|
</Descriptions.Item>
|
|
|
|
|
<Descriptions.Item label="bamboo">bamboo</Descriptions.Item>
|
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
function matchSpan(rowIndex, spans) {
|
|
|
|
|
const tr = wrapper.find('tr').at(rowIndex);
|
|
|
|
|
const tds = tr.find('th');
|
|
|
|
|
expect(tds).toHaveLength(spans.length);
|
|
|
|
|
tds.forEach((td, index) => {
|
|
|
|
|
expect(td.props().colSpan).toEqual(spans[index]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
matchSpan(0, [1, 1, 1, 1]);
|
|
|
|
|
matchSpan(2, [2, 2]);
|
|
|
|
|
matchSpan(4, [3, 1]);
|
|
|
|
|
});
|
2020-03-05 17:54:58 +08:00
|
|
|
|
|
|
|
|
|
it('number value should render correct', () => {
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
<Descriptions bordered>
|
|
|
|
|
<Descriptions.Item label={0}>{0}</Descriptions.Item>
|
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(wrapper.find('th').hasClass('ant-descriptions-item-label')).toBeTruthy();
|
|
|
|
|
expect(wrapper.find('td').hasClass('ant-descriptions-item-content')).toBeTruthy();
|
|
|
|
|
});
|
2020-07-14 20:37:21 +08:00
|
|
|
|
|
|
|
|
|
it('Descriptions support extra', () => {
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
<Descriptions extra="Edit">
|
|
|
|
|
<Descriptions.Item label="UserName">Zhou Maomao</Descriptions.Item>
|
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
|
|
|
|
expect(wrapper.find('.ant-descriptions-extra').exists()).toBe(true);
|
|
|
|
|
wrapper.setProps({ extra: undefined });
|
|
|
|
|
expect(wrapper.find('.ant-descriptions-extra').exists()).toBe(false);
|
|
|
|
|
});
|
2022-03-25 09:38:55 +08:00
|
|
|
|
|
|
|
|
|
it('number 0 should render correct', () => {
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
<Descriptions>
|
|
|
|
|
<Descriptions.Item label={0} labelStyle={{ color: 'red' }} contentStyle={{ color: 'red' }}>
|
|
|
|
|
{0}
|
|
|
|
|
</Descriptions.Item>
|
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
|
});
|
2019-05-22 23:22:09 +08:00
|
|
|
|
});
|