From 71300d0c0055b6cfb35097b9290946e42fdc5ee4 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sun, 9 Dec 2018 11:43:27 +0800 Subject: [PATCH] feat: update input --- components/input/Input.jsx | 3 + components/input/__tests__/Search.test.js | 87 +++++++++++++++++++++++ components/input/__tests__/index.test.js | 4 ++ components/input/index.en-US.md | 1 + components/input/index.zh-CN.md | 1 + 5 files changed, 96 insertions(+) diff --git a/components/input/Input.jsx b/components/input/Input.jsx index e06fec3e2..5f050b285 100644 --- a/components/input/Input.jsx +++ b/components/input/Input.jsx @@ -71,6 +71,9 @@ export default { blur () { this.$refs.input.blur() }, + select () { + this.$refs.input.select() + }, getInputClassName () { const { prefixCls, size, disabled } = this.$props diff --git a/components/input/__tests__/Search.test.js b/components/input/__tests__/Search.test.js index e3e654145..c96e44eab 100644 --- a/components/input/__tests__/Search.test.js +++ b/components/input/__tests__/Search.test.js @@ -29,4 +29,91 @@ describe('Input.Search', () => { expect(wrapper.html()).toMatchSnapshot() }) }) + + it('should disable enter button when disabled prop is true', () => { + const wrapper = mount({ + render () { + return + }, + }) + expect(wrapper.findAll('.ant-btn-primary[disabled]')).toHaveLength(1) + }) + + // it('should trigger onSearch when click search icon', () => { + // const onSearch = jest.fn(); + // const wrapper = mount( + // + // ); + // wrapper.find('.anticon-search').simulate('click'); + // expect(onSearch).toHaveBeenCalledTimes(1); + // expect(onSearch).toBeCalledWith('search text', expect.objectContaining({ + // type: 'click', + // preventDefault: expect.any(Function), + // })); + // }); + + // it('should trigger onSearch when click search button', () => { + // const onSearch = jest.fn(); + // const wrapper = mount( + // + // ); + // wrapper.find('Button').simulate('click'); + // expect(onSearch).toHaveBeenCalledTimes(1); + // expect(onSearch).toBeCalledWith('search text', expect.objectContaining({ + // type: 'click', + // preventDefault: expect.any(Function), + // })); + // }); + + // it('should trigger onSearch when click search button with text', () => { + // const onSearch = jest.fn(); + // const wrapper = mount( + // + // ); + // wrapper.find('Button').simulate('click'); + // expect(onSearch).toHaveBeenCalledTimes(1); + // expect(onSearch).toBeCalledWith('search text', expect.objectContaining({ + // type: 'click', + // preventDefault: expect.any(Function), + // })); + // }); + + // it('should trigger onSearch when click search button with customize button', () => { + // const onSearch = jest.fn(); + // const wrapper = mount( + // antd button} onSearch={onSearch} /> + // ); + // wrapper.find('Button').simulate('click'); + // expect(onSearch).toHaveBeenCalledTimes(1); + // expect(onSearch).toBeCalledWith('search text', expect.objectContaining({ + // type: 'click', + // preventDefault: expect.any(Function), + // })); + // }); + + // it('should trigger onSearch when click search button of native', () => { + // const onSearch = jest.fn(); + // const wrapper = mount( + // antd button} onSearch={onSearch} /> + // ); + // wrapper.find('button').simulate('click'); + // expect(onSearch).toHaveBeenCalledTimes(1); + // expect(onSearch).toBeCalledWith('search text', expect.objectContaining({ + // type: 'click', + // preventDefault: expect.any(Function), + // })); + // }); + + // it('should trigger onSearch when press enter', () => { + // const onSearch = jest.fn(); + // const wrapper = mount( + // + // ); + // wrapper.find('input').simulate('keydown', { key: 'Enter', keyCode: 13 }); + // expect(onSearch).toHaveBeenCalledTimes(1); + // expect(onSearch).toBeCalledWith('search text', expect.objectContaining({ + // type: 'keydown', + // preventDefault: expect.any(Function), + // })); + // }); }) diff --git a/components/input/__tests__/index.test.js b/components/input/__tests__/index.test.js index 4f6609e93..5d403cdfb 100644 --- a/components/input/__tests__/index.test.js +++ b/components/input/__tests__/index.test.js @@ -15,6 +15,10 @@ describe('Input', () => { expect(wrapper.html()).toMatchSnapshot() }, 0) }) + it('select()', () => { + const wrapper = mount(Input) + wrapper.vm.select() + }) }) focusTest(TextArea) diff --git a/components/input/index.en-US.md b/components/input/index.en-US.md index d500cc2ef..a02a5a86e 100644 --- a/components/input/index.en-US.md +++ b/components/input/index.en-US.md @@ -19,6 +19,7 @@ ### Input Events | Events Name | Description | Arguments | | --- | --- | --- | +| change | callback when user input | function(e) | | | pressEnter | The callback function that is triggered when Enter key is pressed. | function(e) | > When `Input` is used in a `Form.Item` context, if the `Form.Item` has the `id` and `options` props defined diff --git a/components/input/index.zh-CN.md b/components/input/index.zh-CN.md index e96575837..39d464ac9 100644 --- a/components/input/index.zh-CN.md +++ b/components/input/index.zh-CN.md @@ -19,6 +19,7 @@ ### Input 事件 | 事件名称 | 说明 | 回调参数 | | --- | --- | --- | +| change | 输入框内容变化时的回调 | function(e) | | | pressEnter | 按下回车的回调 | function(e) | > 如果 `Input` 在 `Form.Item` 内,并且 `Form.Item` 设置了 `id` 和 `options` 属性,则 `value` `defaultValue` 和 `id` 属性会被自动设置。