mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-15 17:31:25 +08:00
8501b708ea
* 📦 samller bundlesize limit * 🗑️ remove React static PropTypes * 🗑️ remove react-lifecycles-compat * 🗑️ remove matchMedia polyfill * 🗑️ remove Transfer buggy lazy prop * 🗑️ remove enquire.js dep * 🗑️ remove Transfer lazy related code and fix ci * 🗑️ remove used dom-closest * ⚡ replace dom-scroll-into-view to scroll-into-view for bundle size * ✅ fix eslint * 🆙 upgrade browserslist * ✅ fix test cases * 🗑️ remove @ant-design/create-react-context * 🆙 upgrade @ant-design/bisheng-plugin * 🆙 upgrade rc-slider * ✅ fix ci * 🆙 upgrade rc-tabs and rc-mentions * 📦 scroll-into-view -> scroll-into-view-if-needed * remove unused devDep * docs: 📝 update instruction about IE9/10 * 📦 reduce css bundle size by drop IE9/10 support * 🆙 upgrade rc-upload * 🗑️ drop unused swing motion css * ✅ update upload snapshots * 📦 lift css bundlesize limit to 55kb
191 lines
6.0 KiB
JavaScript
191 lines
6.0 KiB
JavaScript
import React from 'react';
|
||
import MockDate from 'mockdate';
|
||
import { mount } from 'enzyme';
|
||
import Descriptions from '..';
|
||
import mountTest from '../../../tests/shared/mountTest';
|
||
import { resetWarned } from '../../_util/warning';
|
||
|
||
describe('Descriptions', () => {
|
||
mountTest(Descriptions);
|
||
|
||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||
|
||
jest.spyOn(window, 'matchMedia').mockImplementationOnce(query => ({
|
||
addListener: (listener) => {
|
||
if (query === '(max-width: 575px)') {
|
||
listener({ matches: true });
|
||
}
|
||
},
|
||
removeListener: jest.fn(),
|
||
}));
|
||
|
||
afterEach(() => {
|
||
MockDate.reset();
|
||
errorSpy.mockReset();
|
||
});
|
||
|
||
afterAll(() => {
|
||
errorSpy.mockRestore();
|
||
});
|
||
|
||
it('when max-width: 575px,column=1', () => {
|
||
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>
|
||
<Descriptions.Item>No-Label</Descriptions.Item>
|
||
</Descriptions>,
|
||
);
|
||
expect(wrapper.find('tr')).toHaveLength(5);
|
||
expect(wrapper.find('.ant-descriptions-item-no-label')).toHaveLength(1);
|
||
wrapper.unmount();
|
||
});
|
||
|
||
it('when max-width: 575px,column=2', () => {
|
||
// eslint-disable-next-line global-require
|
||
const wrapper = mount(
|
||
<Descriptions column={{ xs: 2 }}>
|
||
<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>,
|
||
);
|
||
expect(wrapper.find('tr')).toHaveLength(2);
|
||
wrapper.unmount();
|
||
});
|
||
|
||
it('column is number', () => {
|
||
// eslint-disable-next-line global-require
|
||
const wrapper = mount(
|
||
<Descriptions column="3">
|
||
<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>,
|
||
);
|
||
expect(wrapper).toMatchSnapshot();
|
||
wrapper.unmount();
|
||
});
|
||
|
||
it('when typeof column is object', () => {
|
||
const wrapper = mount(
|
||
<Descriptions column={{ xs: 8, sm: 16, md: 24 }}>
|
||
<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>,
|
||
);
|
||
expect(wrapper.instance().getColumn()).toBe(8);
|
||
wrapper.unmount();
|
||
});
|
||
|
||
it('warning if ecceed the row span', () => {
|
||
resetWarned();
|
||
|
||
mount(
|
||
<Descriptions column={3}>
|
||
<Descriptions.Item label="Product" span={2}>
|
||
Cloud Database
|
||
</Descriptions.Item>
|
||
<Descriptions.Item label="Billing" span={2}>
|
||
Prepaid
|
||
</Descriptions.Item>
|
||
</Descriptions>,
|
||
);
|
||
expect(errorSpy).toHaveBeenCalledWith(
|
||
'Warning: [antd: Descriptions] Sum of column `span` in a line exceeds `column` of Descriptions.',
|
||
);
|
||
});
|
||
|
||
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();
|
||
});
|
||
|
||
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>,
|
||
);
|
||
expect(wrapper).toMatchSnapshot();
|
||
wrapper.unmount();
|
||
});
|
||
|
||
it('Descriptions.Item support className', () => {
|
||
const wrapper = mount(
|
||
<Descriptions>
|
||
<Descriptions.Item label="Product" className="my-class">
|
||
Cloud Database
|
||
</Descriptions.Item>
|
||
</Descriptions>,
|
||
);
|
||
expect(wrapper).toMatchSnapshot();
|
||
});
|
||
|
||
it('Descriptions support colon', () => {
|
||
const wrapper = mount(
|
||
<Descriptions colon={false}>
|
||
<Descriptions.Item label="Product">Cloud Database</Descriptions.Item>
|
||
</Descriptions>,
|
||
);
|
||
expect(wrapper).toMatchSnapshot();
|
||
});
|
||
|
||
it('Descriptions support style', () => {
|
||
const wrapper = mount(
|
||
<Descriptions style={{ backgroundColor: '#e8e8e8' }}>
|
||
<Descriptions.Item>Cloud Database</Descriptions.Item>
|
||
</Descriptions>,
|
||
);
|
||
expect(wrapper).toMatchSnapshot();
|
||
});
|
||
|
||
it('keep key', () => {
|
||
const wrapper = mount(
|
||
<Descriptions>
|
||
<Descriptions.Item key="bamboo" />
|
||
</Descriptions>,
|
||
);
|
||
|
||
expect(wrapper.find('Col').key()).toBe('label-bamboo');
|
||
});
|
||
|
||
// 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();
|
||
});
|
||
});
|