Skip to content

Commit

Permalink
chore: fix ci (#39811)
Browse files Browse the repository at this point in the history
* chore: fix ci

* chore: code clean

* chore: update form test

* chore: test
  • Loading branch information
MadCcc committed Dec 26, 2022
1 parent b80a70f commit 663d145
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
6 changes: 4 additions & 2 deletions components/form/__tests__/index.test.tsx
Expand Up @@ -639,7 +639,7 @@ describe('Form', () => {
value = '',
id,
}) => {
shouldRender();
shouldRender(value);
return <input id={id} value={value} />;
};

Expand Down Expand Up @@ -667,8 +667,10 @@ describe('Form', () => {

expect(formRef.current!.getFieldsValue()).toEqual({ light: 'bamboo' });

expect(container.querySelector<HTMLInputElement>('#changed')!.value).toEqual('bamboo');
await waitFakeTimer();

expect(shouldNotRender).toHaveBeenCalledTimes(1);
expect(shouldRender).toHaveBeenLastCalledWith('bamboo');
expect(shouldRender).toHaveBeenCalledTimes(2);
});

Expand Down
28 changes: 12 additions & 16 deletions components/modal/__tests__/hook.test.tsx
Expand Up @@ -2,7 +2,7 @@ import CSSMotion from 'rc-motion';
import { genCSSMotion } from 'rc-motion/lib/CSSMotion';
import KeyCode from 'rc-util/lib/KeyCode';
import React from 'react';
import TestUtils, { act } from 'react-dom/test-utils';
import { act } from 'react-dom/test-utils';

import Modal from '..';
import { fireEvent, render, waitFakeTimer } from '../../../tests/utils';
Expand Down Expand Up @@ -199,10 +199,6 @@ describe('Modal.hook', () => {
it('the callback close should be a method when onCancel has a close parameter', async () => {
jest.useFakeTimers();

const clear = async function clear() {
await waitFakeTimer();
};

const mockFn = jest.fn();

const Demo = () => {
Expand All @@ -229,57 +225,57 @@ describe('Modal.hook', () => {

const { container } = render(<Demo />);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(0);
// First open
fireEvent.click(container.querySelectorAll('.open-hook-modal-btn')[0]);
await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(1);
// Click mask to close
fireEvent.click(document.body.querySelectorAll('.ant-modal-wrap')[0]);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(0);
// Second open
fireEvent.click(container.querySelectorAll('.open-hook-modal-btn')[0]);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(1);
// Press ESC to turn off
TestUtils.Simulate.keyDown(document.body.querySelectorAll('.ant-modal')[0], {
fireEvent.keyDown(document.body.querySelectorAll('.ant-modal')[0], {
keyCode: KeyCode.ESC,
});

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(0);
// Third open
fireEvent.click(container.querySelectorAll('.open-hook-modal-btn')[0]);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(1);
// Click the close icon to close
fireEvent.click(document.body.querySelectorAll('.ant-modal-close')[0]);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(0);
// Last open
fireEvent.click(container.querySelectorAll('.open-hook-modal-btn')[0]);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(1);

// Click the Cancel button to close (invalid)
fireEvent.click(document.body.querySelectorAll('.ant-modal-confirm-btns > .ant-btn')[0]);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(1);

Expand All @@ -288,7 +284,7 @@ describe('Modal.hook', () => {
// Click the Cancel button to close (valid)
fireEvent.click(document.body.querySelectorAll('.ant-modal-confirm-btns > .ant-btn')[0]);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(0);

Expand Down

0 comments on commit 663d145

Please sign in to comment.