aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/ui/__tests__/MessageInput-test.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-10-28 15:52:57 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:58 +0300
commit58f504e34fe5c37056c4e74ed8204bd0d10cb994 (patch)
tree59c9daf1be270793c294c78a079d3bc73b4d45e7 /vnext/src/ui/__tests__/MessageInput-test.js
parentd1ae7c0766c1e3319b4a75164123ffd364fd2389 (diff)
Merge Jest configuration from Next version
Diffstat (limited to 'vnext/src/ui/__tests__/MessageInput-test.js')
-rw-r--r--vnext/src/ui/__tests__/MessageInput-test.js101
1 files changed, 0 insertions, 101 deletions
diff --git a/vnext/src/ui/__tests__/MessageInput-test.js b/vnext/src/ui/__tests__/MessageInput-test.js
deleted file mode 100644
index 12b85bca..00000000
--- a/vnext/src/ui/__tests__/MessageInput-test.js
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * @jest-environment jsdom
- */
-
-import { create, act } from 'react-test-renderer';
-
-import MessageInput from '../MessageInput';
-
-const testMessage = {
- mid: 1,
- rid: 0,
- body: 'test message',
- timestamp: new Date().toISOString(),
- attach: '',
- to: {}
-};
-
-window.matchMedia = window.matchMedia || function() {
- return {
- matches: true,
- addListener: function() { },
- removeListener: function() { }
- };
-};
-
-function createMessageInput(data, onFocus, onSend, draft) {
- return create(<MessageInput data={data} onSend={onSend} text={draft} />, {
- createNodeMock: (element) => {
- if (element.type === 'textarea') {
- // mock a focus function
- return {
- focus: onFocus,
- style: {}
- };
- }
- return null;
- }
- });
-}
-
-it('Gives immediate focus on to textarea on load', () => {
- let focused = false;
- act(() => {
- createMessageInput(testMessage, () => {
- focused = true;
- }, () => { });
- });
- expect(focused).toEqual(true, 'textarea was not focused');
-});
-
-
-it('Submits on ctrl-enter', () => {
- const onSend = jest.fn();
- var messageInput = null;
- act(() => {
- messageInput = createMessageInput(testMessage, () => {}, onSend);
- });
- let textarea = messageInput.root.findByType('textarea');
- act(() => {
-
- textarea.props.onKeyPress({
- charCode: 13,
- which: 13,
- keyCode: 13,
- ctrlKey: false
- });
- });
- expect(onSend).toHaveBeenCalledTimes(0);
- act(() => {
- textarea.props.onKeyPress({
- charCode: 13,
- which: 13,
- keyCode: 13,
- ctrlKey: true
- });
- });
- expect(onSend).toHaveBeenCalledTimes(1);
- expect(textarea.props.value).toEqual('');
- act(() => {
- textarea.props.onChange({
- target: {
- value: ' ',
- validity: {}
- }
- });
- });
- expect(textarea.props.value).toEqual(' ');
- act(() => {
- messageInput.root.findByType('form').props.onSubmit({ event: {} });
- });
- expect(textarea.props.value).toEqual('', 'Value should be cleared after submit');
-});
-
-it('Show draft text', () => {
- var messageInput;
- act(() => {
- messageInput = createMessageInput(testMessage, () => {}, () => {}, 'yo');
- });
- let textarea = messageInput.root.findByType('textarea');
- expect(textarea.props.value).toEqual('yo', 'Value should match draft');
-});