Skip to content

Commit

Permalink
chore: improve code style (ant-design#27266)
Browse files Browse the repository at this point in the history
  • Loading branch information
hengkx authored Oct 21, 2020
1 parent d44f404 commit b5dc079
Show file tree
Hide file tree
Showing 24 changed files with 62 additions and 192 deletions.
1 change: 0 additions & 1 deletion README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

一套企业级 UI 设计语言和 React 组件库。


[![CircleCI status][circleci-image]][circleci-url] [![CI status][github-action-image]][github-action-url] [![codecov][codecov-image]][codecov-url] [![NPM version][npm-image]][npm-url] [![NPM downloads][download-image]][download-url]

[![david deps][david-image]][david-url] [![david devDeps][david-dev-image]][david-dev-url] [![Total alerts][lgtm-image]][lgtm-url] [![FOSSA Status][fossa-image]][fossa-url] [![Issues need help][help-wanted-image]][help-wanted-url]
Expand Down
15 changes: 3 additions & 12 deletions components/auto-complete/__tests__/focus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,17 @@ describe('AutoComplete children could be focus', () => {
it('focus() and onFocus', () => {
const handleFocus = jest.fn();
const wrapper = mount(<AutoComplete onFocus={handleFocus} />, { attachTo: container });
wrapper
.find('input')
.instance()
.focus();
wrapper.find('input').instance().focus();
jest.runAllTimers();
expect(handleFocus).toHaveBeenCalled();
});

it('blur() and onBlur', () => {
const handleBlur = jest.fn();
const wrapper = mount(<AutoComplete onBlur={handleBlur} />, { attachTo: container });
wrapper
.find('input')
.instance()
.focus();
wrapper.find('input').instance().focus();
jest.runAllTimers();
wrapper
.find('input')
.instance()
.blur();
wrapper.find('input').instance().blur();
jest.runAllTimers();
expect(handleBlur).toHaveBeenCalled();
});
Expand Down
21 changes: 5 additions & 16 deletions components/breadcrumb/__tests__/router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,12 @@ describe('react router', () => {
</MemoryRouter>,
);
expect(wrapper.find('BreadcrumbItem').length).toBe(1);
expect(
wrapper
.find('BreadcrumbItem .ant-breadcrumb-link')
.at(0)
.text(),
).toBe('Home');
wrapper
.find('.demo-nav a')
.at(1)
.simulate('click');
expect(wrapper.find('BreadcrumbItem .ant-breadcrumb-link').at(0).text()).toBe('Home');
wrapper.find('.demo-nav a').at(1).simulate('click');
expect(wrapper.find('BreadcrumbItem').length).toBe(2);
expect(
wrapper
.find('BreadcrumbItem .ant-breadcrumb-link')
.at(1)
.text(),
).toBe('Application List');
expect(wrapper.find('BreadcrumbItem .ant-breadcrumb-link').at(1).text()).toBe(
'Application List',
);
});

it('react router 3', () => {
Expand Down
5 changes: 1 addition & 4 deletions components/card/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ describe('Card', () => {
xxx
</Card>,
);
wrapper
.find('.ant-tabs-tab')
.at(1)
.simulate('click');
wrapper.find('.ant-tabs-tab').at(1).simulate('click');
expect(onTabChange).toHaveBeenCalledWith('tab2');
});

Expand Down
1 change: 0 additions & 1 deletion components/cascader/__tests__/type.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ describe('Cascader.typescript', () => {
},
];


const result = <Cascader options={options} defaultValue={[1, 'hangzhou']} />;

expect(result).toBeTruthy();
Expand Down
18 changes: 2 additions & 16 deletions components/date-picker/__tests__/other.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,13 @@ describe('MonthPicker and WeekPicker', () => {
const birthday = moment('2000-01-01', 'YYYY-MM-DD').locale('zh-cn');
const wrapper = mount(<MonthPicker open />);
wrapper.setProps({ value: birthday });
expect(
render(
wrapper
.find('Trigger')
.instance()
.getComponent(),
),
).toMatchSnapshot();
expect(render(wrapper.find('Trigger').instance().getComponent())).toMatchSnapshot();
});

it('render WeekPicker', () => {
const birthday = moment('2000-01-01', 'YYYY-MM-DD').locale('zh-cn');
const wrapper = mount(<WeekPicker open />);
wrapper.setProps({ value: birthday });
expect(
render(
wrapper
.find('Trigger')
.instance()
.getComponent(),
),
).toMatchSnapshot();
expect(render(wrapper.find('Trigger').instance().getComponent())).toMatchSnapshot();
});
});
16 changes: 3 additions & 13 deletions components/date-picker/__tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ export function openPanel(wrapper) {
}

export function clearInput(wrapper) {
wrapper
.find('.ant-calendar-picker-clear')
.hostNodes()
.simulate('click');
wrapper.find('.ant-calendar-picker-clear').hostNodes().simulate('click');
}

export function nextYear(wrapper) {
Expand All @@ -33,17 +30,10 @@ export function nextMonth(wrapper) {
}

export function openPicker(wrapper, index = 0) {
wrapper
.find('input')
.at(index)
.simulate('mousedown')
.simulate('focus');
wrapper.find('input').at(index).simulate('mousedown').simulate('focus');
}
export function closePicker(wrapper, index = 0) {
wrapper
.find('input')
.at(index)
.simulate('blur');
wrapper.find('input').at(index).simulate('blur');
}

export function selectCell(wrapper, text, index = 0) {
Expand Down
2 changes: 1 addition & 1 deletion components/descriptions/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
font-size: @font-size-base;
line-height: @line-height-base;
word-break: break-word;
overflow-wrap: break-word;
overflow-wrap: break-word;
}

&-item {
Expand Down
7 changes: 1 addition & 6 deletions components/list/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ describe('List', () => {
const dataSource = [];

const wrapper = mount(<List renderItem={renderItem} dataSource={dataSource} locale={locale} />);
expect(
wrapper
.find('div')
.first()
.props().locale,
).toBe(undefined);
expect(wrapper.find('div').first().props().locale).toBe(undefined);
});
});
2 changes: 1 addition & 1 deletion components/locale-provider/by_BY.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import locale from '../locale/by_BY';

export default locale;
export default locale;
4 changes: 2 additions & 2 deletions components/locale/ar_EG.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ const localeValues: Locale = {
},
Form: {
defaultValidateMessages: {
"default": 'خطأ في حقل الإدخال ${label}',
default: 'خطأ في حقل الإدخال ${label}',
required: 'يرجى إدخال ${label}',
"enum": '${label} يجب أن يكون واحدا من [${enum}]',
enum: '${label} يجب أن يكون واحدا من [${enum}]',
whitespace: '${label} لا يمكن أن يكون حرفًا فارغًا',
date: {
format: '${label} تنسيق التاريخ غير صحيح',
Expand Down
12 changes: 2 additions & 10 deletions components/result/__tests__/type.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ describe('Result.typescript', () => {
it('status', () => {
const result = (
<>
<Result
status="404"
title="404"
subTitle="Sorry, the page you visited does not exist."
/>
<Result
status={404}
title="404"
subTitle="Sorry, the page you visited does not exist."
/>
<Result status="404" title="404" subTitle="Sorry, the page you visited does not exist." />
<Result status={404} title="404" subTitle="Sorry, the page you visited does not exist." />
</>
);

Expand Down
42 changes: 6 additions & 36 deletions components/select/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,14 @@ describe('Select', () => {
it('should support set notFoundContent to null', () => {
const wrapper = mount(<Select mode="multiple" notFoundContent={null} />);
toggleOpen(wrapper);
const dropdownWrapper = mount(
wrapper
.find('Trigger')
.instance()
.getComponent(),
);
const dropdownWrapper = mount(wrapper.find('Trigger').instance().getComponent());
expect(dropdownWrapper.find('MenuItem').length).toBe(0);
});

it('should not have default notFoundContent when mode is combobox', () => {
const wrapper = mount(<Select mode={Select.SECRET_COMBOBOX_MODE_DO_NOT_USE} />);
toggleOpen(wrapper);
const dropdownWrapper = mount(
wrapper
.find('Trigger')
.instance()
.getComponent(),
);
const dropdownWrapper = mount(wrapper.find('Trigger').instance().getComponent());
expect(dropdownWrapper.find('MenuItem').length).toBe(0);
});

Expand All @@ -66,19 +56,9 @@ describe('Select', () => {
<Select mode={Select.SECRET_COMBOBOX_MODE_DO_NOT_USE} notFoundContent="not at all" />,
);
toggleOpen(wrapper);
const dropdownWrapper = mount(
wrapper
.find('Trigger')
.instance()
.getComponent(),
);
const dropdownWrapper = mount(wrapper.find('Trigger').instance().getComponent());
expect(dropdownWrapper.find('.ant-select-item-option').length).toBeFalsy();
expect(
dropdownWrapper
.find('.ant-select-item-empty')
.at(0)
.text(),
).toBe('not at all');
expect(dropdownWrapper.find('.ant-select-item-empty').at(0).text()).toBe('not at all');
});

it('should be controlled by open prop', () => {
Expand All @@ -88,24 +68,14 @@ describe('Select', () => {
<Option value="1">1</Option>
</Select>,
);
let dropdownWrapper = mount(
wrapper
.find('Trigger')
.instance()
.getComponent(),
);
let dropdownWrapper = mount(wrapper.find('Trigger').instance().getComponent());
expect(dropdownWrapper.props().visible).toBe(true);
toggleOpen(wrapper);
expect(onDropdownVisibleChange).toHaveBeenLastCalledWith(false);
expect(dropdownWrapper.props().visible).toBe(true);

wrapper.setProps({ open: false });
dropdownWrapper = mount(
wrapper
.find('Trigger')
.instance()
.getComponent(),
);
dropdownWrapper = mount(wrapper.find('Trigger').instance().getComponent());
expect(dropdownWrapper.props().visible).toBe(false);
toggleOpen(wrapper);
expect(onDropdownVisibleChange).toHaveBeenLastCalledWith(true);
Expand Down
2 changes: 1 addition & 1 deletion components/skeleton/Paragraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Paragraph = (props: SkeletonParagraphProps) => {
const { prefixCls, className, style, rows } = props;
const rowList = [...Array(rows)].map((_, index) => (
// eslint-disable-next-line react/no-array-index-key
<li key={index} style={{ width: getWidth(index) }}/>
<li key={index} style={{ width: getWidth(index) }} />
));
return (
<ul className={classNames(prefixCls, className)} style={style}>
Expand Down
21 changes: 3 additions & 18 deletions components/spin/__tests__/delay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,20 @@ import Spin from '..';
describe('delay spinning', () => {
it("should render with delay when it's mounted with spinning=true and delay", () => {
const wrapper = mount(<Spin spinning delay={500} />);
expect(
wrapper
.find('.ant-spin')
.at(0)
.hasClass('ant-spin-spinning'),
).toEqual(false);
expect(wrapper.find('.ant-spin').at(0).hasClass('ant-spin-spinning')).toEqual(false);
});

it('should render when delay is init set', async () => {
const wrapper = mount(<Spin spinning delay={100} />);

expect(
wrapper
.find('.ant-spin')
.at(0)
.hasClass('ant-spin-spinning'),
).toEqual(false);
expect(wrapper.find('.ant-spin').at(0).hasClass('ant-spin-spinning')).toEqual(false);

// use await not jest.runAllTimers()
// because of https://github.com/facebook/jest/issues/3465
await new Promise(resolve => setTimeout(resolve, 500));
wrapper.update();

expect(
wrapper
.find('.ant-spin')
.at(0)
.hasClass('ant-spin-spinning'),
).toEqual(true);
expect(wrapper.find('.ant-spin').at(0).hasClass('ant-spin-spinning')).toEqual(true);
});

it('should cancel debounce function when unmount', async () => {
Expand Down
14 changes: 2 additions & 12 deletions components/spin/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,8 @@ describe('Spin', () => {
<div>content</div>
</Spin>,
);
expect(
wrapper
.find('.ant-spin-nested-loading')
.at(0)
.prop('style'),
).toBeFalsy();
expect(
wrapper
.find('.ant-spin')
.at(0)
.prop('style').background,
).toBe('red');
expect(wrapper.find('.ant-spin-nested-loading').at(0).prop('style')).toBeFalsy();
expect(wrapper.find('.ant-spin').at(0).prop('style').background).toBe('red');
});

it("should render custom indicator when it's set", () => {
Expand Down
4 changes: 3 additions & 1 deletion components/statistic/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ describe('Statistic', () => {
it('responses hover events for Countdown', () => {
const onMouseEnter = jest.fn();
const onMouseLeave = jest.fn();
const wrapper = mount(<Statistic.Countdown onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} />);
const wrapper = mount(
<Statistic.Countdown onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} />,
);
wrapper.simulate('mouseenter');
expect(onMouseEnter).toHaveBeenCalled();
wrapper.simulate('mouseleave');
Expand Down
14 changes: 11 additions & 3 deletions components/style/mixins/customize.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// customize dark components background in popover containers(like Modal, Drawer, Card, Popover, Popconfirm, Notification, ...)
// for dark theme
.popover-customize-bg(@containerClass, @background: @popover-background, @prefix: @ant-prefix) when (@theme = dark) {
.popover-customize-bg(@containerClass, @background: @popover-background, @prefix: @ant-prefix)
when
(@theme = dark) {
@picker-prefix-cls: ~'@{prefix}-picker';
@slider-prefix-cls: ~'@{prefix}-slider';
@anchor-prefix-cls: ~'@{prefix}-anchor';
Expand All @@ -18,7 +20,12 @@
@popover-border: @border-width-base @border-style-base @popover-customize-border-color;

.@{containerClass} {
.@{picker-prefix-cls}-clear, .@{slider-prefix-cls}-handle, .@{anchor-prefix-cls}-wrapper, .@{collapse-prefix-cls}-content, .@{timeline-prefix-cls}-item-head, .@{card-prefix-cls} {
.@{picker-prefix-cls}-clear,
.@{slider-prefix-cls}-handle,
.@{anchor-prefix-cls}-wrapper,
.@{collapse-prefix-cls}-content,
.@{timeline-prefix-cls}-item-head,
.@{card-prefix-cls} {
background-color: @background;
}

Expand Down Expand Up @@ -77,7 +84,8 @@
> tr {
> td {
border-bottom: @popover-border;
&.@{table-prefix-cls}-cell-fix-left, &.@{table-prefix-cls}-cell-fix-right {
&.@{table-prefix-cls}-cell-fix-left,
&.@{table-prefix-cls}-cell-fix-right {
background-color: @background;
}
}
Expand Down
Loading

0 comments on commit b5dc079

Please sign in to comment.