Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Descriptions warning should work as expect #16819

Merged
merged 2 commits into from May 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions components/descriptions/__tests__/index.test.js
@@ -1,4 +1,5 @@
import React from 'react';
import MockDate from 'mockdate';
import { mount } from 'enzyme';
import Descriptions from '..';

Expand All @@ -23,6 +24,17 @@ jest.mock('enquire.js', () => {
});

describe('Descriptions', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

afterEach(() => {
MockDate.reset();
errorSpy.mockReset();
});

afterAll(() => {
errorSpy.mockRestore();
});

it('when max-width: 575px,column=1', () => {
// eslint-disable-next-line global-require
const enquire = require('enquire.js');
Expand Down Expand Up @@ -83,4 +95,20 @@ describe('Descriptions', () => {
expect(wrapper.instance().getColumn()).toBe(8);
wrapper.unmount();
});

it('warning if ecceed the row span', () => {
mount(
<Descriptions column={3}>
<DescriptionsItem label="Product" span={2}>
Cloud Database
</DescriptionsItem>
<DescriptionsItem label="Billing" span={2}>
Prepaid
</DescriptionsItem>
</Descriptions>,
);
expect(errorSpy).toHaveBeenCalledWith(
'Warning: [antd: Descriptions] Sum of column `span` in a line exceeds `column` of Descriptions.',
);
});
});
9 changes: 5 additions & 4 deletions components/descriptions/index.tsx
Expand Up @@ -48,14 +48,15 @@ const generateChildrenRows = (
totalRowSpan += 1;
}
if (totalRowSpan >= column) {
childrenArray.push(columnArray);
columnArray = [];
totalRowSpan = 0;
warning(
totalRowSpan > column,
totalRowSpan <= column,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

居然是反的..

'Descriptions',
'Sum of column `span` in a line exceeds `column` of Descriptions.',
);

childrenArray.push(columnArray);
columnArray = [];
totalRowSpan = 0;
}
});
if (columnArray.length > 0) {
Expand Down