diff --git a/jest.config.js b/jest.config.js index 573194827..9641a57df 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,3 @@ module.exports = { - setupFiles: ['./tests/setup.js'], coveragePathIgnorePatterns: ['src/locale/', 'tests/'], }; diff --git a/package.json b/package.json index d51432a91..ca37514d0 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "build": "dumi build", "compile": "father build && lessc assets/index.less assets/index.css", "gh-pages": "npm run build && father doc deploy", - "prepublishOnly": "npm run compile && np --yolo --no-publish", + "prepublishOnly": "npm run compile && np --yolo --no-publish --any-branch", "lint": "eslint src/ --ext .ts,.tsx,.jsx,.js,.md", "lint:tsc": "tsc -p tsconfig.json --noEmit", "prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"", diff --git a/src/PickerInput/SinglePicker.tsx b/src/PickerInput/SinglePicker.tsx index 552c29e7d..a43c6b3a2 100644 --- a/src/PickerInput/SinglePicker.tsx +++ b/src/PickerInput/SinglePicker.tsx @@ -603,7 +603,6 @@ function Picker( // Submit with complex picker if (!mergedOpen && complexPicker && !needConfirm && lastOp === 'panel') { - triggerOpen(true); triggerConfirm(); } }, [mergedOpen]); diff --git a/tests/new-range.spec.tsx b/tests/new-range.spec.tsx index 3d92fee62..ee123b25f 100644 --- a/tests/new-range.spec.tsx +++ b/tests/new-range.spec.tsx @@ -785,6 +785,32 @@ describe('NewPicker.Range', () => { expect(container.querySelectorAll('input')[0]).toHaveValue('1990-09-05'); expect(container.querySelectorAll('input')[1]).toHaveValue('1990-09-05'); }); + + it('not trigger open when !needConfirm', () => { + const onChange = jest.fn(); + const onOpenChange = jest.fn(); + + const { container } = render( + , + ); + openPicker(container); + + fireEvent.click(findCell(5)); + + act(() => { + jest.runAllTimers(); + }); + expect(onOpenChange).toHaveBeenCalledWith(true); + + // Window click to close + fireEvent.mouseDown(document.body); + act(() => { + jest.runAllTimers(); + }); + + expect(onOpenChange).toHaveBeenCalledTimes(2); + expect(onOpenChange).toHaveBeenCalledWith(false); + }); }); describe('open', () => { diff --git a/tests/setup.js b/tests/setup.js deleted file mode 100644 index f2601cd4d..000000000 --- a/tests/setup.js +++ /dev/null @@ -1,85 +0,0 @@ -// global.requestAnimationFrame = callback => { -// global.setTimeout(callback, 0); -// }; - -// global.cancelAnimationFrame = id => { -// global.clearTimeout(id); -// }; - -// const Enzyme = require('enzyme'); -// const Adapter = require('@wojtekmaj/enzyme-adapter-react-17'); - -// Enzyme.configure({ adapter: new Adapter() }); - -// Object.assign(Enzyme.ReactWrapper.prototype, { -// openPicker(index = 0) { -// this.find('input') -// .at(index) -// .simulate('mousedown') -// .simulate('focus'); -// }, -// closePicker(index = 0) { -// this.find('input') -// .at(index) -// .simulate('blur'); -// }, -// confirmOK() { -// this.find('.rc-picker-ok > *').simulate('click'); -// }, -// isOpen() { -// const openDiv = this.find('.rc-picker-dropdown').hostNodes(); -// return openDiv && openDiv.length && !openDiv.hasClass('rc-picker-dropdown-hidden'); -// }, -// findCell(text, index = 0) { -// let matchCell; - -// const table = this.find('table').at(index); - -// table.find('td').forEach(td => { -// if (td.text() === String(text) && td.props().className.includes('-in-view')) { -// matchCell = td; -// } -// }); -// if (!matchCell) { -// throw new Error('Cell not match in picker panel.'); -// } - -// return matchCell; -// }, -// selectCell(text, index = 0) { -// const td = this.findCell(text, index); -// td.simulate('click'); - -// return td; -// }, -// clickButton(type) { -// let matchBtn; -// this.find('button').forEach(btn => { -// if (btn.props().className.includes(`-header-${type}-btn`)) { -// matchBtn = btn; -// } -// }); - -// matchBtn.simulate('click'); - -// return matchBtn; -// }, -// clearValue() { -// this.find('.rc-picker-clear-btn').simulate('mouseDown'); -// this.find('.rc-picker-clear-btn').simulate('mouseUp'); -// }, -// keyDown(which, info = {}, index = 0) { -// let component = this.find('input'); - -// if (component.length === 0) { -// component = this.find('.rc-picker-panel'); -// } - -// component.at(index).simulate('keydown', { ...info, which }); -// }, -// inputValue(text, index = 0) { -// this.find('input') -// .at(index) -// .simulate('change', { target: { value: text } }); -// }, -// });