Skip to content

Commit

Permalink
Merge branch 'featur/expand-action' of https://github.com/NE-SmallTow…
Browse files Browse the repository at this point in the history
…n/ant-design into featur/expand-action
  • Loading branch information
NE-SmallTown committed Jun 1, 2022
2 parents 48e6e9a + c076b2d commit c901a79
Show file tree
Hide file tree
Showing 44 changed files with 1,201 additions and 642 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ jobs:
key: dist-${{ github.sha }}

- name: dist
run: npm run dist
run: CI=1 npm run dist
env:
NODE_OPTIONS: --max_old_space_size=4096
needs: setup
Expand Down Expand Up @@ -236,6 +236,7 @@ jobs:
matrix:
react: ['16', '17', '18']
module: ['dom', 'node', 'dist']
shard: ['1/4', '2/4', '3/4', '4/4']
env:
REACT: ${{ matrix.react }}
runs-on: ubuntu-latest
Expand Down Expand Up @@ -288,12 +289,11 @@ jobs:
# dom test
- name: dom test
if: ${{ matrix.module == 'dom' }}
run: npm test -- -w 1 --coverage
run: npm test -- --maxWorkers=2 --shard=${{matrix.shard}} --coverage

# > 17 only
- name: coverage
uses: codecov/codecov-action@v3
if: ${{ matrix.module == 'dom' && matrix.react == '17' }}
run: bash <(curl -s https://codecov.io/bash)

# node test
- name: node test
Expand Down Expand Up @@ -353,6 +353,7 @@ jobs:
matrix:
react: ['16', '17', '18']
module: [lib, es]
shard: ['1/4', '2/4', '3/4', '4/4']
env:
REACT: ${{ matrix.react }}
steps:
Expand Down Expand Up @@ -400,7 +401,7 @@ jobs:
- name: test
# lib only run in master branch not in pull request
if: ${{ github.event_name != 'pull_request' || matrix.module != 'lib' }}
run: npm test
run: npm test -- --maxWorkers=2 --shard=${{matrix.shard}}
env:
LIB_DIR: ${{ matrix.module }}
needs: compile
59 changes: 31 additions & 28 deletions components/alert/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from 'react';
import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
import Alert from '..';
import accessibilityTest from '../../../tests/shared/accessibilityTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { fireEvent, render, sleep } from '../../../tests/utils';
import Button from '../../button';
import Tooltip from '../../tooltip';
import Popconfirm from '../../popconfirm';
import rtlTest from '../../../tests/shared/rtlTest';
import accessibilityTest from '../../../tests/shared/accessibilityTest';
import { sleep } from '../../../tests/utils';
import Alert from '..';
import Tooltip from '../../tooltip';

const { ErrorBoundary } = Alert;

Expand All @@ -25,17 +24,18 @@ describe('Alert', () => {

it('could be closed', () => {
const onClose = jest.fn();
const wrapper = mount(
const { container } = render(
<Alert
message="Warning Text Warning Text Warning TextW arning Text Warning Text Warning TextWarning Text"
type="warning"
closable
onClose={onClose}
/>,
);

act(() => {
jest.useFakeTimers();
wrapper.find('.ant-alert-close-icon').simulate('click');
fireEvent.click(container.querySelector('.ant-alert-close-icon')!);
jest.runAllTimers();
jest.useRealTimers();
});
Expand All @@ -44,7 +44,7 @@ describe('Alert', () => {

describe('action of Alert', () => {
it('custom action', () => {
const wrapper = mount(
const { container } = render(
<Alert
message="Success Tips"
type="success"
Expand All @@ -57,39 +57,39 @@ describe('Alert', () => {
closable
/>,
);
expect(wrapper.render()).toMatchSnapshot();
expect(container.firstChild).toMatchSnapshot();
});
});

it('support closeIcon', () => {
const wrapper = mount(
const { container } = render(
<Alert
closable
closeIcon={<span>close</span>}
message="Warning Text Warning Text Warning TextW arning Text Warning Text Warning TextWarning Text"
type="warning"
/>,
);
expect(wrapper.render()).toMatchSnapshot();
expect(container.firstChild).toMatchSnapshot();
});

describe('data and aria props', () => {
it('sets data attributes on input', () => {
const wrapper = mount(<Alert data-test="test-id" data-id="12345" message={null} />);
const input = wrapper.find('.ant-alert').getDOMNode();
const { container } = render(<Alert data-test="test-id" data-id="12345" message={null} />);
const input = container.querySelector('.ant-alert')!;
expect(input.getAttribute('data-test')).toBe('test-id');
expect(input.getAttribute('data-id')).toBe('12345');
});

it('sets aria attributes on input', () => {
const wrapper = mount(<Alert aria-describedby="some-label" message={null} />);
const input = wrapper.find('.ant-alert').getDOMNode();
const { container } = render(<Alert aria-describedby="some-label" message={null} />);
const input = container.querySelector('.ant-alert')!;
expect(input.getAttribute('aria-describedby')).toBe('some-label');
});

it('sets role attribute on input', () => {
const wrapper = mount(<Alert role="status" message={null} />);
const input = wrapper.find('.ant-alert').getDOMNode();
const { container } = render(<Alert role="status" message={null} />);
const input = container.querySelector('.ant-alert')!;
expect(input.getAttribute('role')).toBe('status');
});
});
Expand All @@ -101,29 +101,30 @@ describe('Alert', () => {
// @ts-expect-error
// eslint-disable-next-line react/jsx-no-undef
const ThrowError = () => <NotExisted />;
const wrapper = mount(
const { container } = render(
<ErrorBoundary>
<ThrowError />
</ErrorBoundary>,
);
// eslint-disable-next-line jest/no-standalone-expect
expect(wrapper.text()).toContain('ReferenceError: NotExisted is not defined');
expect(container.textContent).toContain('ReferenceError: NotExisted is not defined');
// eslint-disable-next-line no-console
(console.error as any).mockRestore();
});

it('could be used with Tooltip', async () => {
const ref = React.createRef<any>();
jest.useRealTimers();
const wrapper = mount(
const { container } = render(
<Tooltip title="xxx" mouseEnterDelay={0} ref={ref}>
<Alert
message="Warning Text Warning Text Warning TextW arning Text Warning Text Warning TextWarning Text"
type="warning"
/>
</Tooltip>,
);
wrapper.find('.ant-alert').simulate('mouseenter');
// wrapper.find('.ant-alert').simulate('mouseenter');
fireEvent.mouseEnter(container.querySelector('.ant-alert')!);
await sleep(0);
expect(ref.current.getPopupDomNode()).toBeTruthy();
jest.useFakeTimers();
Expand All @@ -132,27 +133,29 @@ describe('Alert', () => {
it('could be used with Popconfirm', async () => {
const ref = React.createRef<any>();
jest.useRealTimers();
const wrapper = mount(
const { container } = render(
<Popconfirm ref={ref} title="xxx">
<Alert
message="Warning Text Warning Text Warning TextW arning Text Warning Text Warning TextWarning Text"
type="warning"
/>
</Popconfirm>,
);
wrapper.find('.ant-alert').simulate('click');
fireEvent.click(container.querySelector('.ant-alert')!);
await sleep(0);
expect(ref.current.getPopupDomNode()).toBeTruthy();
jest.useFakeTimers();
});

it('could accept none react element icon', () => {
const wrapper = mount(<Alert message="Success Tips" type="success" showIcon icon="icon" />);
expect(wrapper.render()).toMatchSnapshot();
const { container } = render(
<Alert message="Success Tips" type="success" showIcon icon="icon" />,
);
expect(container.firstChild).toMatchSnapshot();
});

it('should not render message div when no message', () => {
const wrapper = mount(<Alert description="description" />);
expect(wrapper.exists('.ant-alert-message')).toBe(false);
const { container } = render(<Alert description="description" />);
expect(!!container.querySelector('.ant-alert-message')).toBe(false);
});
});
4 changes: 4 additions & 0 deletions components/back-top/demo/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ title:

可以自定义回到顶部按钮的样式,限制宽高:`40px * 40px`

> 注意:`BackTop` 需要一个可接受 `onClick` 事件的元素作为 `children`。 如果您直接将文本作为子项放置,则该组件将无法正常运行。
## en-US

You can customize the style of the button, just note the size limit: no more than `40px * 40px`.

> Note: `BackTop` expects a element could accept `onClick` propety as children. If you put a text directly as children the component will not function properly.
```tsx
import { BackTop } from 'antd';
import React from 'react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ exports[`renders ./components/breadcrumb/demo/overlay.md extend context correctl
>
<ul
class="ant-dropdown-menu ant-dropdown-menu-root ant-dropdown-menu-vertical ant-dropdown-menu-light"
data-dropdown-inject="true"
data-menu-list="true"
role="menu"
tabindex="0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,6 @@ Array [
>
<ul
class="ant-dropdown-menu ant-dropdown-menu-root ant-dropdown-menu-vertical ant-dropdown-menu-light"
data-dropdown-inject="true"
data-menu-list="true"
role="menu"
tabindex="0"
Expand Down
Loading

0 comments on commit c901a79

Please sign in to comment.