mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-10 19:19:20 +08:00
refator: update rc-dialog to remove rc-animate
(#26940)
* chore: bump rc-dialog * fix 1 test case * test case * more test * fix confirm test case * clean up * fix snapshot * update local-provider snapshot * update Modal snapshot * fix test of dialog hook * fix lint
This commit is contained in:
parent
01d757b660
commit
442c146e3c
@ -16275,12 +16275,12 @@ exports[`ConfigProvider components Modal configProvider 1`] = `
|
|||||||
class="config-modal-mask"
|
class="config-modal-mask"
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class="config-modal-wrap "
|
class="config-modal-wrap"
|
||||||
role="dialog"
|
role="dialog"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="config-modal "
|
class="config-modal"
|
||||||
role="document"
|
role="document"
|
||||||
style="width:520px"
|
style="width:520px"
|
||||||
>
|
>
|
||||||
@ -16368,12 +16368,12 @@ exports[`ConfigProvider components Modal configProvider componentSize large 1`]
|
|||||||
class="config-modal-mask"
|
class="config-modal-mask"
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class="config-modal-wrap "
|
class="config-modal-wrap"
|
||||||
role="dialog"
|
role="dialog"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="config-modal "
|
class="config-modal"
|
||||||
role="document"
|
role="document"
|
||||||
style="width:520px"
|
style="width:520px"
|
||||||
>
|
>
|
||||||
@ -16461,12 +16461,12 @@ exports[`ConfigProvider components Modal configProvider componentSize middle 1`]
|
|||||||
class="config-modal-mask"
|
class="config-modal-mask"
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class="config-modal-wrap "
|
class="config-modal-wrap"
|
||||||
role="dialog"
|
role="dialog"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="config-modal "
|
class="config-modal"
|
||||||
role="document"
|
role="document"
|
||||||
style="width:520px"
|
style="width:520px"
|
||||||
>
|
>
|
||||||
@ -16554,12 +16554,12 @@ exports[`ConfigProvider components Modal configProvider virtual and dropdownMatc
|
|||||||
class="ant-modal-mask"
|
class="ant-modal-mask"
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class="ant-modal-wrap "
|
class="ant-modal-wrap"
|
||||||
role="dialog"
|
role="dialog"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-modal "
|
class="ant-modal"
|
||||||
role="document"
|
role="document"
|
||||||
style="width:520px"
|
style="width:520px"
|
||||||
>
|
>
|
||||||
@ -16647,12 +16647,12 @@ exports[`ConfigProvider components Modal normal 1`] = `
|
|||||||
class="ant-modal-mask"
|
class="ant-modal-mask"
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class="ant-modal-wrap "
|
class="ant-modal-wrap"
|
||||||
role="dialog"
|
role="dialog"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-modal "
|
class="ant-modal"
|
||||||
role="document"
|
role="document"
|
||||||
style="width:520px"
|
style="width:520px"
|
||||||
>
|
>
|
||||||
@ -16740,12 +16740,12 @@ exports[`ConfigProvider components Modal prefixCls 1`] = `
|
|||||||
class="prefix-Modal-mask"
|
class="prefix-Modal-mask"
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class="prefix-Modal-wrap "
|
class="prefix-Modal-wrap"
|
||||||
role="dialog"
|
role="dialog"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="prefix-Modal "
|
class="prefix-Modal"
|
||||||
role="document"
|
role="document"
|
||||||
style="width:520px"
|
style="width:520px"
|
||||||
>
|
>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -8,15 +8,15 @@ exports[`Modal render correctly 1`] = `
|
|||||||
class="ant-modal-root"
|
class="ant-modal-root"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-modal-mask fade-appear"
|
class="ant-modal-mask fade-appear fade-appear-start fade"
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class="ant-modal-wrap "
|
class="ant-modal-wrap"
|
||||||
role="dialog"
|
role="dialog"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-modal zoom-appear"
|
class="ant-modal zoom-appear zoom-appear-prepare zoom"
|
||||||
role="document"
|
role="document"
|
||||||
style="width: 520px;"
|
style="width: 520px;"
|
||||||
>
|
>
|
||||||
@ -105,15 +105,15 @@ exports[`Modal render without footer 1`] = `
|
|||||||
class="ant-modal-root"
|
class="ant-modal-root"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-modal-mask fade-appear"
|
class="ant-modal-mask fade-appear fade-appear-start fade"
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class="ant-modal-wrap "
|
class="ant-modal-wrap"
|
||||||
role="dialog"
|
role="dialog"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-modal zoom-appear"
|
class="ant-modal zoom-appear zoom-appear-prepare zoom"
|
||||||
role="document"
|
role="document"
|
||||||
style="width: 520px;"
|
style="width: 520px;"
|
||||||
>
|
>
|
||||||
@ -181,15 +181,15 @@ exports[`Modal support closeIcon 1`] = `
|
|||||||
class="ant-modal-root"
|
class="ant-modal-root"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-modal-mask fade-appear"
|
class="ant-modal-mask fade-appear fade-appear-start fade"
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class="ant-modal-wrap "
|
class="ant-modal-wrap"
|
||||||
role="dialog"
|
role="dialog"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-modal zoom-appear"
|
class="ant-modal zoom-appear zoom-appear-prepare zoom"
|
||||||
role="document"
|
role="document"
|
||||||
style="width: 520px;"
|
style="width: 520px;"
|
||||||
>
|
>
|
||||||
|
@ -1,12 +1,45 @@
|
|||||||
import TestUtils from 'react-dom/test-utils';
|
import TestUtils, { act } from 'react-dom/test-utils';
|
||||||
|
import CSSMotion from 'rc-motion';
|
||||||
|
import { genCSSMotion } from 'rc-motion/lib/CSSMotion';
|
||||||
|
import KeyCode from 'rc-util/lib/KeyCode';
|
||||||
import Modal from '..';
|
import Modal from '..';
|
||||||
import { destroyFns } from '../Modal';
|
import { destroyFns } from '../Modal';
|
||||||
|
import { sleep } from '../../../tests/utils';
|
||||||
|
|
||||||
const { confirm } = Modal;
|
const { confirm } = Modal;
|
||||||
|
|
||||||
|
jest.mock('rc-motion');
|
||||||
|
|
||||||
describe('Modal.confirm triggers callbacks correctly', () => {
|
describe('Modal.confirm triggers callbacks correctly', () => {
|
||||||
|
// Inject CSSMotion to replace with No transition support
|
||||||
|
const MockCSSMotion = genCSSMotion(false);
|
||||||
|
Object.keys(MockCSSMotion).forEach(key => {
|
||||||
|
CSSMotion[key] = MockCSSMotion[key];
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mock for rc-util raf
|
||||||
|
window.requestAnimationFrame = callback => {
|
||||||
|
return window.setTimeout(callback, 16);
|
||||||
|
};
|
||||||
|
window.cancelAnimationFrame = id => {
|
||||||
|
window.clearTimeout(id);
|
||||||
|
};
|
||||||
|
|
||||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||||
|
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
// Hack error to remove act warning
|
||||||
|
const originError = console.error;
|
||||||
|
console.error = (...args) => {
|
||||||
|
const errorStr = String(args[0]);
|
||||||
|
if (errorStr.includes('was not wrapped in act(...)')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
originError(...args);
|
||||||
|
};
|
||||||
|
/* eslint-enable */
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
errorSpy.mockReset();
|
errorSpy.mockReset();
|
||||||
document.body.innerHTML = '';
|
document.body.innerHTML = '';
|
||||||
@ -68,20 +101,39 @@ describe('Modal.confirm triggers callbacks correctly', () => {
|
|||||||
expect(onOk.mock.calls.length).toBe(1);
|
expect(onOk.mock.calls.length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow Modal.comfirm without onCancel been set', () => {
|
it('should allow Modal.confirm without onCancel been set', () => {
|
||||||
open();
|
open();
|
||||||
// Third Modal
|
// Third Modal
|
||||||
$$('.ant-btn')[0].click();
|
$$('.ant-btn')[0].click();
|
||||||
expect(errorSpy).not.toHaveBeenCalled();
|
expect(errorSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow Modal.comfirm without onOk been set', () => {
|
it('should allow Modal.confirm without onOk been set', () => {
|
||||||
open();
|
open();
|
||||||
// Fourth Modal
|
// Fourth Modal
|
||||||
$$('.ant-btn-primary')[0].click();
|
$$('.ant-btn-primary')[0].click();
|
||||||
expect(errorSpy).not.toHaveBeenCalled();
|
expect(errorSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should close confirm modal when press ESC', () => {
|
||||||
|
jest.useFakeTimers();
|
||||||
|
const onCancel = jest.fn();
|
||||||
|
Modal.confirm({
|
||||||
|
title: 'title',
|
||||||
|
content: 'content',
|
||||||
|
onCancel,
|
||||||
|
});
|
||||||
|
jest.runAllTimers();
|
||||||
|
expect($$(`.ant-modal-confirm-confirm`)).toHaveLength(1);
|
||||||
|
TestUtils.Simulate.keyDown($$('.ant-modal')[0], {
|
||||||
|
keyCode: KeyCode.ESC,
|
||||||
|
});
|
||||||
|
jest.runAllTimers();
|
||||||
|
expect($$(`.ant-modal-confirm-confirm`)).toHaveLength(0);
|
||||||
|
expect(onCancel).toHaveBeenCalledTimes(1);
|
||||||
|
jest.useRealTimers();
|
||||||
|
});
|
||||||
|
|
||||||
it('should not hide confirm when onOk return Promise.resolve', () => {
|
it('should not hide confirm when onOk return Promise.resolve', () => {
|
||||||
open({
|
open({
|
||||||
onOk: () => Promise.resolve(''),
|
onOk: () => Promise.resolve(''),
|
||||||
@ -90,23 +142,27 @@ describe('Modal.confirm triggers callbacks correctly', () => {
|
|||||||
expect($$('.ant-modal-confirm')).toHaveLength(1);
|
expect($$('.ant-modal-confirm')).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit error when onOk return Promise.reject', () => {
|
it('should emit error when onOk return Promise.reject', async () => {
|
||||||
const error = new Error('something wrong');
|
const error = new Error('something wrong');
|
||||||
open({
|
open({
|
||||||
onOk: () => Promise.reject(error),
|
onOk: () => {
|
||||||
|
return Promise.reject(error);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
$$('.ant-btn-primary')[0].click();
|
$$('.ant-btn-primary')[0].click();
|
||||||
|
|
||||||
// wait promise
|
// wait promise
|
||||||
return Promise.resolve().then(() => {
|
await sleep();
|
||||||
|
|
||||||
expect(errorSpy).toHaveBeenCalledWith(error);
|
expect(errorSpy).toHaveBeenCalledWith(error);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('shows animation when close', () => {
|
it('shows animation when close', () => {
|
||||||
open();
|
open();
|
||||||
jest.useFakeTimers();
|
jest.useFakeTimers();
|
||||||
expect($$('.ant-modal-confirm')).toHaveLength(1);
|
expect($$('.ant-modal-confirm')).toHaveLength(1);
|
||||||
$$('.ant-btn')[0].click();
|
$$('.ant-btn')[0].click();
|
||||||
|
|
||||||
jest.runAllTimers();
|
jest.runAllTimers();
|
||||||
expect($$('.ant-modal-confirm')).toHaveLength(0);
|
expect($$('.ant-modal-confirm')).toHaveLength(0);
|
||||||
jest.useRealTimers();
|
jest.useRealTimers();
|
||||||
@ -158,25 +214,6 @@ describe('Modal.confirm triggers callbacks correctly', () => {
|
|||||||
jest.useRealTimers();
|
jest.useRealTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should close confirm modal when press ESC', () => {
|
|
||||||
jest.useFakeTimers();
|
|
||||||
const onCancel = jest.fn();
|
|
||||||
Modal.confirm({
|
|
||||||
title: 'title',
|
|
||||||
content: 'content',
|
|
||||||
onCancel,
|
|
||||||
});
|
|
||||||
jest.runAllTimers();
|
|
||||||
expect($$(`.ant-modal-confirm-confirm`)).toHaveLength(1);
|
|
||||||
TestUtils.Simulate.keyDown($$('.ant-modal')[0], {
|
|
||||||
keyCode: 27,
|
|
||||||
});
|
|
||||||
jest.runAllTimers();
|
|
||||||
expect($$(`.ant-modal-confirm-confirm`)).toHaveLength(0);
|
|
||||||
expect(onCancel).toHaveBeenCalledTimes(1);
|
|
||||||
jest.useRealTimers();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not close modals when click confirm button when onOk has argument', () => {
|
it('should not close modals when click confirm button when onOk has argument', () => {
|
||||||
jest.useFakeTimers();
|
jest.useFakeTimers();
|
||||||
['info', 'success', 'warning', 'error'].forEach(type => {
|
['info', 'success', 'warning', 'error'].forEach(type => {
|
||||||
@ -268,23 +305,35 @@ describe('Modal.confirm triggers callbacks correctly', () => {
|
|||||||
|
|
||||||
it('destroyFns should reduce when instance.destroy', () => {
|
it('destroyFns should reduce when instance.destroy', () => {
|
||||||
jest.useFakeTimers();
|
jest.useFakeTimers();
|
||||||
|
|
||||||
Modal.destroyAll(); // clear destroyFns
|
Modal.destroyAll(); // clear destroyFns
|
||||||
jest.runAllTimers();
|
jest.runAllTimers();
|
||||||
|
|
||||||
const instances = [];
|
const instances = [];
|
||||||
['info', 'success', 'warning', 'error'].forEach(type => {
|
['info', 'success', 'warning', 'error'].forEach(type => {
|
||||||
const instance = Modal[type]({
|
const instance = Modal[type]({
|
||||||
title: 'title',
|
title: 'title',
|
||||||
content: 'content',
|
content: 'content',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Render modal
|
||||||
|
act(() => {
|
||||||
|
jest.runAllTimers();
|
||||||
|
});
|
||||||
|
|
||||||
instances.push(instance);
|
instances.push(instance);
|
||||||
});
|
});
|
||||||
const { length } = instances;
|
const { length } = instances;
|
||||||
instances.forEach((instance, index) => {
|
instances.forEach((instance, index) => {
|
||||||
expect(destroyFns.length).toBe(length - index);
|
expect(destroyFns.length).toBe(length - index);
|
||||||
|
|
||||||
|
act(() => {
|
||||||
instance.destroy();
|
instance.destroy();
|
||||||
jest.runAllTimers();
|
jest.runAllTimers();
|
||||||
|
});
|
||||||
expect(destroyFns.length).toBe(length - index - 1);
|
expect(destroyFns.length).toBe(length - index - 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
jest.useRealTimers();
|
jest.useRealTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,11 +1,20 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import CSSMotion from 'rc-motion';
|
||||||
|
import { genCSSMotion } from 'rc-motion/lib/CSSMotion';
|
||||||
import { mount } from 'enzyme';
|
import { mount } from 'enzyme';
|
||||||
import Modal from '..';
|
import Modal from '..';
|
||||||
import Button from '../../button';
|
import Button from '../../button';
|
||||||
|
|
||||||
jest.mock('rc-util/lib/Portal');
|
jest.mock('rc-util/lib/Portal');
|
||||||
|
jest.mock('rc-motion');
|
||||||
|
|
||||||
describe('Modal.hook', () => {
|
describe('Modal.hook', () => {
|
||||||
|
// Inject CSSMotion to replace with No transition support
|
||||||
|
const MockCSSMotion = genCSSMotion(false);
|
||||||
|
Object.keys(MockCSSMotion).forEach(key => {
|
||||||
|
CSSMotion[key] = MockCSSMotion[key];
|
||||||
|
});
|
||||||
|
|
||||||
it('hooks support context', () => {
|
it('hooks support context', () => {
|
||||||
jest.useFakeTimers();
|
jest.useFakeTimers();
|
||||||
const Context = React.createContext('light');
|
const Context = React.createContext('light');
|
||||||
|
@ -121,7 +121,7 @@
|
|||||||
"rc-cascader": "~1.4.0",
|
"rc-cascader": "~1.4.0",
|
||||||
"rc-checkbox": "~2.3.0",
|
"rc-checkbox": "~2.3.0",
|
||||||
"rc-collapse": "~2.0.0",
|
"rc-collapse": "~2.0.0",
|
||||||
"rc-dialog": "~8.3.0",
|
"rc-dialog": "~8.4.0",
|
||||||
"rc-drawer": "~4.1.0",
|
"rc-drawer": "~4.1.0",
|
||||||
"rc-dropdown": "~3.2.0",
|
"rc-dropdown": "~3.2.0",
|
||||||
"rc-field-form": "~1.12.0",
|
"rc-field-form": "~1.12.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user