diff options
Diffstat (limited to 'vnext/src/components/__tests__/MessageInput-test.js')
-rw-r--r-- | vnext/src/components/__tests__/MessageInput-test.js | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/vnext/src/components/__tests__/MessageInput-test.js b/vnext/src/components/__tests__/MessageInput-test.js index ef7a81e6..143a2491 100644 --- a/vnext/src/components/__tests__/MessageInput-test.js +++ b/vnext/src/components/__tests__/MessageInput-test.js @@ -1,56 +1,51 @@ import React from 'react'; -import { mount } from 'enzyme'; -import { configure } from 'enzyme'; -import Adapter from 'enzyme-adapter-react-16'; +import { create, act } from 'react-test-renderer'; import MessageInput from '../MessageInput'; -// Remove when it will be fixed: https://github.com/airbnb/enzyme/issues/1875 -jest.mock('react', () => { - const r = jest.requireActual('react'); - return { ...r, memo: (x) => x }; -}); - -configure({ adapter: new Adapter() }); - const testMessage = { mid: 1, - user: { uid: 1, uname: 'ugnich' }, + rid: 0, body: 'test message', - timestamp: new Date().toISOString() + timestamp: new Date().toISOString(), + attach: '', + to: {} }; -window.matchMedia = window.matchMedia || function() { +window.matchMedia = window.matchMedia || function () { return { matches: true, - addListener: function() { }, - removeListener: function() { } + addListener: function () { }, + removeListener: function () { } }; }; it('Gives immediate focus on to textarea on load', () => { - const wrapper = mount(<MessageInput data={testMessage} onSend={() => { }} />); - const textareaRef = wrapper.instance().textarea; - - jest.spyOn(textareaRef.current, 'focus'); - - wrapper.instance().componentDidMount(); - expect(textareaRef.current.focus).toHaveBeenCalledTimes(1); + expect(document.activeElement.type).toEqual(undefined); + var wrapper = null; + act(() => { + wrapper = create(<MessageInput data={testMessage} onSend={() => { }} />); + }); + console.log(document.activeElement); + expect(document.activeElement.type).toEqual('textarea', 'textarea was not focused'); }); it('Submits on ctrl-enter', () => { const onSend = jest.fn(); - const messageInput = mount(<MessageInput data={testMessage} onSend={onSend} />); + var messageInput = null; + act(() => { + messageInput = create(<MessageInput data={testMessage} onSend={onSend} />); + }); - let textarea = messageInput.find('textarea'); - textarea.simulate('keypress', { + let textarea = messageInput.root.findByType('textarea'); + textarea.props.onKeyPress({ charCode: 13, which: 13, keyCode: 13, ctrlKey: false }); expect(onSend).toHaveBeenCalledTimes(0); - textarea.simulate('keypress', { + textarea.props.onKeyPress({ charCode: 13, which: 13, keyCode: 13, @@ -59,14 +54,19 @@ it('Submits on ctrl-enter', () => { expect(onSend).toHaveBeenCalledTimes(1); }); -it('Clears template on submit', () => { - const messageInput = mount(<MessageInput data={testMessage} onSend={() => { }} />); - messageInput.find('textarea').simulate('change', { - target: { - value: ' ' - } +it('Clears text on submit', () => { + var messageInput = null; + act(() => { + messageInput = create(<MessageInput data={testMessage} onSend={() => { }} />); + }); + let textarea = messageInput.root.findByType('textarea'); + act(() => { + textarea.value = ' '; + textarea.props.onChange({ target: { value: ' ', validity: {} } }); + }); + expect(textarea.value).toEqual(' '); + act(() => { + messageInput.root.findByType('form').props.onSubmit({ event: {} }); }); - expect(messageInput.state().body).toEqual(' '); - messageInput.find('Button').simulate('click'); - expect(messageInput.state().body).toEqual(''); + expect(textarea.value).toEqual(''); }); |