aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/components/__tests__/MessageInput-test.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-06-21 00:27:02 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:53 +0300
commitb257e179862d0b895d6e7be30136018515de564c (patch)
tree1aed4d95954292eec0f72f93f8af3275afbf4f69 /vnext/src/components/__tests__/MessageInput-test.js
parent7a8f6604e77859455d8abab8c46af0a4619a9c60 (diff)
initial DOM tests
Diffstat (limited to 'vnext/src/components/__tests__/MessageInput-test.js')
-rw-r--r--vnext/src/components/__tests__/MessageInput-test.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/vnext/src/components/__tests__/MessageInput-test.js b/vnext/src/components/__tests__/MessageInput-test.js
new file mode 100644
index 00000000..f6a452d8
--- /dev/null
+++ b/vnext/src/components/__tests__/MessageInput-test.js
@@ -0,0 +1,47 @@
+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(<MessageInput data={testMessage} onSend={() => {}} />);
+ 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(<MessageInput data={testMessage} onSend={onSend} />);
+
+ 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);
+}); \ No newline at end of file