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-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2020-03-15 20:53:23 +08:00
|
|
|
import useBreakpoint from '../hooks/useBreakpoint';
|
2020-07-10 17:38:28 +08:00
|
|
|
import ResponsiveObserve from '../../_util/responsiveObserve';
|
2016-12-14 14:48:09 +08:00
|
|
|
|
|
|
|
describe('Grid', () => {
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(Row);
|
|
|
|
mountTest(Col);
|
|
|
|
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(Row);
|
|
|
|
rtlTest(Col);
|
|
|
|
|
2016-12-14 14:48:09 +08:00
|
|
|
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-10-20 14:38:35 +08:00
|
|
|
it('when typeof gutter is object', () => {
|
2019-05-22 23:22:09 +08:00
|
|
|
const wrapper = mount(<Row gutter={{ xs: 8, sm: 16, md: 24 }} />);
|
2020-07-10 17:38:28 +08:00
|
|
|
expect(wrapper.find('div').first().props().style).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
marginLeft: -4,
|
|
|
|
marginRight: -4,
|
|
|
|
}),
|
|
|
|
);
|
2019-10-20 14:38:35 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
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 },
|
|
|
|
]}
|
|
|
|
/>,
|
|
|
|
);
|
2020-07-10 17:38:28 +08:00
|
|
|
expect(wrapper.find('div').first().props().style).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
marginLeft: -4,
|
|
|
|
marginRight: -4,
|
|
|
|
}),
|
|
|
|
);
|
2019-10-20 14:38:35 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('when typeof gutter is object array in large screen', () => {
|
2020-07-10 17:38:28 +08:00
|
|
|
const wrapper = render(
|
2019-10-20 14:38:35 +08:00
|
|
|
<Row
|
|
|
|
gutter={[
|
|
|
|
{ xs: 8, sm: 16, md: 24, lg: 32, xl: 40 },
|
|
|
|
{ xs: 8, sm: 16, md: 24, lg: 100, xl: 400 },
|
|
|
|
]}
|
|
|
|
/>,
|
|
|
|
);
|
2020-07-10 17:38:28 +08:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
2019-03-01 15:59:32 +08:00
|
|
|
});
|
|
|
|
|
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', () => {
|
2020-07-10 17:38:28 +08:00
|
|
|
const Unmount = jest.spyOn(ResponsiveObserve, 'unsubscribe');
|
|
|
|
const wrapper = mount(<Row gutter={{ xs: 20 }} />);
|
2019-03-04 11:49:29 +08:00
|
|
|
wrapper.unmount();
|
2020-07-10 17:38:28 +08:00
|
|
|
expect(Unmount).toHaveBeenCalled();
|
2019-03-04 11:49:29 +08:00
|
|
|
});
|
|
|
|
|
2019-05-22 23:22:09 +08:00
|
|
|
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,
|
|
|
|
});
|
2019-03-04 11:49:29 +08:00
|
|
|
});
|
2019-09-24 21:44:20 +08:00
|
|
|
|
|
|
|
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,
|
2019-11-20 11:13:24 +08:00
|
|
|
marginBottom: 10,
|
2019-09-24 21:44:20 +08:00
|
|
|
});
|
|
|
|
});
|
2020-03-15 20:53:23 +08:00
|
|
|
|
|
|
|
// By jsdom mock, actual jsdom not implemented matchMedia
|
|
|
|
// https://jestjs.io/docs/en/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
|
|
|
|
it('should work with useBreakpoint', () => {
|
|
|
|
function Demo() {
|
|
|
|
const screens = useBreakpoint();
|
|
|
|
|
|
|
|
return JSON.stringify(screens);
|
|
|
|
}
|
|
|
|
const wrapper = mount(<Demo />);
|
|
|
|
|
|
|
|
expect(wrapper.text()).toEqual(
|
|
|
|
JSON.stringify({
|
|
|
|
xs: true,
|
|
|
|
sm: false,
|
|
|
|
md: false,
|
|
|
|
lg: false,
|
|
|
|
xl: false,
|
|
|
|
xxl: false,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
2016-12-14 14:48:09 +08:00
|
|
|
});
|