aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/components/__tests__/MessageInput-test.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-04-08 02:21:01 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:54 +0300
commit844004f00aac6c4d8ad100fd0aced708447b67ac (patch)
tree4b7bec61ced8e8389547df54ecb8a73ef03aed52 /vnext/src/components/__tests__/MessageInput-test.js
parentee6944ac4bb5c0e673e23b87df1c0ef8cf29f05a (diff)
Drop enzyme
Some tests still failed
Diffstat (limited to 'vnext/src/components/__tests__/MessageInput-test.js')
-rw-r--r--vnext/src/components/__tests__/MessageInput-test.js72
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('');
});