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 '..';
|
|
|
|
|
|
|
|
|
|
jest.mock('enquire.js', () => {
|
|
|
|
|
let that;
|
|
|
|
|
let unmatchFun;
|
|
|
|
|
return {
|
|
|
|
|
unregister: jest.fn(),
|
|
|
|
|
register: (media, options) => {
|
|
|
|
|
if (media === '(max-width: 575px)') {
|
|
|
|
|
that = this;
|
|
|
|
|
options.match.call(that);
|
|
|
|
|
unmatchFun = options.unmatch;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
callunmatch() {
|
|
|
|
|
unmatchFun.call(that);
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('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', () => {
|
|
|
|
|
// eslint-disable-next-line global-require
|
|
|
|
|
const enquire = require('enquire.js');
|
|
|
|
|
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-05-22 23:22:09 +08:00
|
|
|
|
</Descriptions>,
|
|
|
|
|
);
|
|
|
|
|
expect(wrapper.find('tr')).toHaveLength(4);
|
|
|
|
|
|
|
|
|
|
enquire.callunmatch();
|
|
|
|
|
wrapper.unmount();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('when max-width: 575px,column=2', () => {
|
|
|
|
|
// eslint-disable-next-line global-require
|
|
|
|
|
const enquire = require('enquire.js');
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
enquire.callunmatch();
|
|
|
|
|
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>,
|
|
|
|
|
);
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
|
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>,
|
|
|
|
|
);
|
|
|
|
|
expect(wrapper.instance().getColumn()).toBe(8);
|
|
|
|
|
wrapper.unmount();
|
|
|
|
|
});
|
2019-05-27 16:41:56 +08:00
|
|
|
|
|
|
|
|
|
it('warning if ecceed the row span', () => {
|
|
|
|
|
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(
|
|
|
|
|
'Warning: [antd: Descriptions] Sum of column `span` in a line exceeds `column` of Descriptions.',
|
|
|
|
|
);
|
|
|
|
|
});
|
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>,
|
|
|
|
|
);
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
|
wrapper.unmount();
|
|
|
|
|
});
|
2019-05-22 23:22:09 +08:00
|
|
|
|
});
|