mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-25 19:50:05 +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
99 lines
2.6 KiB
JavaScript
99 lines
2.6 KiB
JavaScript
import React from 'react';
|
|
import { render, mount } from 'enzyme';
|
|
import { Col, Row } from '..';
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
|
|
jest.spyOn(window, 'matchMedia').mockImplementationOnce(query => ({
|
|
addListener: (listener) => {
|
|
if (query === '(max-width: 575px)') {
|
|
listener({ matches: true });
|
|
}
|
|
},
|
|
removeListener: jest.fn(),
|
|
}));
|
|
|
|
describe('Grid', () => {
|
|
mountTest(Row);
|
|
mountTest(Col);
|
|
|
|
it('should render Col', () => {
|
|
const wrapper = render(<Col span={2} />);
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render Row', () => {
|
|
const wrapper = render(<Row />);
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
|
|
it('when typeof gutter is object', () => {
|
|
const wrapper = mount(<Row gutter={{ xs: 8, sm: 16, md: 24 }} />);
|
|
expect(wrapper.instance().getGutter()).toEqual([8, 0]);
|
|
});
|
|
|
|
it('when typeof gutter is object array', () => {
|
|
const wrapper = mount(
|
|
<Row
|
|
gutter={[
|
|
{ xs: 8, sm: 16, md: 24, lg: 32, xl: 40 },
|
|
{ xs: 8, sm: 16, md: 24, lg: 32, xl: 40 },
|
|
]}
|
|
/>,
|
|
);
|
|
expect(wrapper.instance().getGutter()).toEqual([8, 8]);
|
|
});
|
|
|
|
it('when typeof gutter is object array in large screen', () => {
|
|
const wrapper = mount(
|
|
<Row
|
|
gutter={[
|
|
{ xs: 8, sm: 16, md: 24, lg: 32, xl: 40 },
|
|
{ xs: 8, sm: 16, md: 24, lg: 100, xl: 400 },
|
|
]}
|
|
/>,
|
|
);
|
|
wrapper.setState({
|
|
screens: { md: true, lg: true, xl: true },
|
|
});
|
|
expect(wrapper.instance().getGutter()).toEqual([40, 400]);
|
|
});
|
|
|
|
it('renders wrapped Col correctly', () => {
|
|
const MyCol = () => <Col span={12} />;
|
|
const wrapper = render(
|
|
<Row gutter={20}>
|
|
<div>
|
|
<Col span={12} />
|
|
</div>
|
|
<MyCol />
|
|
</Row>,
|
|
);
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
|
|
it('when component has been unmounted, componentWillUnmount should be called', () => {
|
|
const wrapper = mount(<Row />);
|
|
const willUnmount = jest.spyOn(wrapper.instance(), 'componentWillUnmount');
|
|
wrapper.unmount();
|
|
expect(willUnmount).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should work correct when gutter is object', () => {
|
|
const wrapper = mount(<Row gutter={{ xs: 20 }} />);
|
|
expect(wrapper.find('div').prop('style')).toEqual({
|
|
marginLeft: -10,
|
|
marginRight: -10,
|
|
});
|
|
});
|
|
|
|
it('should work currect when gutter is array', () => {
|
|
const wrapper = mount(<Row gutter={[16, 20]} />);
|
|
expect(wrapper.find('div').prop('style')).toEqual({
|
|
marginLeft: -8,
|
|
marginRight: -8,
|
|
marginTop: -10,
|
|
marginBottom: 10,
|
|
});
|
|
});
|
|
});
|