2016-12-14 14:48:09 +08:00
|
|
|
import React from 'react';
|
2019-03-01 15:59:32 +08:00
|
|
|
import { render, mount } from 'enzyme';
|
2016-12-14 14:48:09 +08:00
|
|
|
import { Col, Row } from '..';
|
|
|
|
|
2019-03-01 15:59:32 +08:00
|
|
|
jest.mock('enquire.js', () => {
|
|
|
|
let that;
|
|
|
|
let unmatchFun;
|
|
|
|
return {
|
|
|
|
unregister: jest.fn(),
|
2019-05-22 23:22:09 +08:00
|
|
|
register: (media, options) => {
|
|
|
|
if (media === '(max-width: 575px)') {
|
2019-03-01 15:59:32 +08:00
|
|
|
that = this;
|
|
|
|
options.match.call(that);
|
|
|
|
unmatchFun = options.unmatch;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
callunmatch() {
|
|
|
|
unmatchFun.call(that);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2016-12-14 14:48:09 +08:00
|
|
|
describe('Grid', () => {
|
|
|
|
it('should render Col', () => {
|
2018-12-26 21:44:34 +08:00
|
|
|
const wrapper = render(<Col span={2} />);
|
2017-09-15 10:56:00 +08:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
2016-12-14 14:48:09 +08:00
|
|
|
});
|
2018-09-21 19:30:39 +08:00
|
|
|
|
2016-12-14 14:48:09 +08:00
|
|
|
it('should render Row', () => {
|
2018-12-07 16:17:45 +08:00
|
|
|
const wrapper = render(<Row />);
|
2017-09-15 10:56:00 +08:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
2016-12-14 14:48:09 +08:00
|
|
|
});
|
2018-09-21 19:30:39 +08:00
|
|
|
|
2019-05-22 23:22:09 +08:00
|
|
|
it('when typeof getGutter is object', () => {
|
|
|
|
const wrapper = mount(<Row gutter={{ xs: 8, sm: 16, md: 24 }} />);
|
|
|
|
expect(wrapper.instance().getGutter()).toBe(8);
|
2019-03-01 15:59:32 +08:00
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
2018-09-21 19:30:39 +08:00
|
|
|
it('renders wrapped Col correctly', () => {
|
2018-12-26 21:44:34 +08:00
|
|
|
const MyCol = () => <Col span={12} />;
|
2018-09-21 19:30:39 +08:00
|
|
|
const wrapper = render(
|
|
|
|
<Row gutter={20}>
|
|
|
|
<div>
|
2018-12-26 21:44:34 +08:00
|
|
|
<Col span={12} />
|
2018-09-21 19:30:39 +08:00
|
|
|
</div>
|
|
|
|
<MyCol />
|
2018-12-07 16:17:45 +08:00
|
|
|
</Row>,
|
2018-09-21 19:30:39 +08:00
|
|
|
);
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
2019-03-04 11:49:29 +08:00
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2019-05-22 23:22:09 +08:00
|
|
|
it('should work correct when gutter is object', () => {
|
|
|
|
// eslint-disable-next-line global-require
|
|
|
|
const enquire = require('enquire.js');
|
|
|
|
const wrapper = mount(<Row gutter={{ xs: 20 }} />);
|
|
|
|
expect(wrapper.find('div').prop('style')).toEqual({
|
|
|
|
marginLeft: -10,
|
|
|
|
marginRight: -10,
|
|
|
|
});
|
|
|
|
enquire.callunmatch();
|
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.update()
|
|
|
|
.find('div')
|
|
|
|
.prop('style'),
|
|
|
|
).toEqual(undefined);
|
|
|
|
wrapper.unmount();
|
|
|
|
expect(enquire.unregister).toHaveBeenCalled();
|
2019-03-04 11:49:29 +08:00
|
|
|
});
|
2016-12-14 14:48:09 +08:00
|
|
|
});
|