2021-02-01 10:15:39 +08:00
|
|
|
import React from 'react';
|
2021-03-02 20:29:00 +08:00
|
|
|
import ReactDOMServer from 'react-dom/server';
|
2021-02-01 10:15:39 +08:00
|
|
|
import { Col, Row } from '..';
|
2022-05-23 14:37:16 +08:00
|
|
|
import { render, screen } from '../../../tests/utils';
|
2021-02-01 10:15:39 +08:00
|
|
|
|
|
|
|
jest.mock('../../_util/styleChecker', () => ({
|
|
|
|
canUseDocElement: () => true,
|
|
|
|
isStyleSupport: () => true,
|
2021-02-03 15:39:51 +08:00
|
|
|
detectFlexGapSupported: () => true,
|
2021-02-01 10:15:39 +08:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('Grid.Gap', () => {
|
2022-05-07 11:44:48 +08:00
|
|
|
it('should not have `row-gap: 0px` style', () => {
|
|
|
|
render(
|
2022-05-19 10:05:40 +08:00
|
|
|
<Row role="row">
|
2022-05-07 11:44:48 +08:00
|
|
|
<Col />
|
|
|
|
</Row>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(screen.getByRole('row').style.rowGap).toBe('');
|
|
|
|
});
|
|
|
|
|
2021-02-01 10:15:39 +08:00
|
|
|
it('should use gap', () => {
|
2022-08-16 10:14:41 +08:00
|
|
|
const { container } = render(
|
2021-02-01 10:15:39 +08:00
|
|
|
<Row gutter={[16, 8]}>
|
|
|
|
<Col />
|
|
|
|
</Row>,
|
|
|
|
);
|
|
|
|
|
2022-08-16 10:14:41 +08:00
|
|
|
expect((container.querySelector('.ant-row') as HTMLElement)!.style.marginLeft).toEqual('-8px');
|
|
|
|
expect((container.querySelector('.ant-row') as HTMLElement)!.style.marginRight).toEqual('-8px');
|
|
|
|
expect((container.querySelector('.ant-row') as HTMLElement)!.style.rowGap).toEqual('8px');
|
2021-02-01 10:15:39 +08:00
|
|
|
});
|
2021-03-02 20:29:00 +08:00
|
|
|
|
|
|
|
it('not break ssr', () => {
|
|
|
|
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
|
|
|
|
const Demo = () => (
|
|
|
|
<Row gutter={[16, 8]}>
|
|
|
|
<Col />
|
|
|
|
</Row>
|
|
|
|
);
|
|
|
|
|
|
|
|
const div = document.createElement('div');
|
|
|
|
|
|
|
|
const ssrTxt = ReactDOMServer.renderToString(<Demo />);
|
|
|
|
div.innerHTML = ssrTxt;
|
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
const { unmount } = render(<Demo />, { container: div, hydrate: true });
|
2021-03-02 20:29:00 +08:00
|
|
|
|
|
|
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
warnSpy.mockRestore();
|
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
unmount();
|
2021-03-02 20:29:00 +08:00
|
|
|
});
|
2021-02-01 10:15:39 +08:00
|
|
|
});
|