import React from 'react'; import { mount } from 'enzyme'; import { configure } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; import MessageInput from '../MessageInput'; configure({ adapter: new Adapter() }); const testMessage = { mid: 1, user: { uid: 1, uname: 'ugnich' }, body: 'test message', timestamp: new Date().toISOString() }; it('Gives immediate focus on to textarea on load', () => { const wrapper = mount( {}} />); const textareaRef = wrapper.instance().textarea; jest.spyOn(textareaRef.current, 'focus'); wrapper.instance().componentDidMount(); expect(textareaRef.current.focus).toHaveBeenCalledTimes(1); }); it('Submits on ctrl-enter', () => { const onSend = jest.fn(); const messageInput = mount(); let textarea = messageInput.find('textarea'); textarea.simulate('keypress', { charCode: 32, which: 32, keyCode: 32, ctrlKey: false }); expect(onSend).toHaveBeenCalledTimes(0); // TODO: test for body change textarea.simulate('keypress', { charCode: 13, which: 13, keyCode: 13, ctrlKey: true }); expect(onSend).toHaveBeenCalledTimes(1); }); it('Clears template on submit', () => { const messageInput = mount( {}} />); messageInput.setState({'body': 'yoyo'}); messageInput.find('.msg-comment .badge').simulate('click'); expect(messageInput.state().body).toEqual(''); })