mattermost-mobile/app/components/post_draft/typing/typing.test.js
Daniel Espino García 4c8594d330
Add linter rules for import order and type member delimiters (#5514)
* Add linter rules for import order and type member delimiters

* Remove unneeded group

* Group all app/* imports before the internal imports

* Move app/ imports before parent imports

* Separate @node_modules imports into a different group

* Substitute app paths by aliases

* Fix @node_modules import order and add test related modules

* Add aliases for types and test, and group import types
2021-07-23 11:06:04 +02:00

80 lines
2.4 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {Animated} from 'react-native';
import {TYPING_VISIBLE} from '@constants/post_draft';
import EventEmitter from '@mm-redux/utils/event_emitter';
import Typing from './typing';
describe('Typing', () => {
const baseProps = {
typing: ['user1', 'user2'],
theme: {
centerChannelColor: 'blue',
},
registerTypingAnimation: jest.fn(() => {
return jest.fn();
}),
};
EventEmitter.emit = jest.fn();
test('should render component without error', () => {
const wrapper = shallow(
<Typing {...baseProps}/>,
);
expect(wrapper.find(Animated.View).exists()).toBe(true);
});
test('should not emit TYPING_VISIBLE when typing props is not empty and previous is not empty', () => {
const props = {
...baseProps,
typing: ['user2'],
};
const wrapper = shallow(
<Typing {...props}/>,
);
wrapper.setProps({typing: ['user2 and user3']});
expect(EventEmitter.emit).not.toHaveBeenCalled();
});
test('should emit TYPING_VISIBLE with true when typing props is not empty and previous is empty', () => {
const props = {
...baseProps,
typing: [],
};
const wrapper = shallow(
<Typing {...props}/>,
);
wrapper.setProps({typing: ['user2']});
expect(EventEmitter.emit).toHaveBeenCalledWith(TYPING_VISIBLE, true);
});
test('should emit TYPING_VISIBLE with false when typing props is empty', () => {
const wrapper = shallow(
<Typing {...baseProps}/>,
);
wrapper.setProps({typing: []});
expect(EventEmitter.emit).toHaveBeenCalledWith(TYPING_VISIBLE, false);
});
test('should add/remove typing animation on mount/unmount', () => {
const wrapper = shallow(
<Typing {...baseProps}/>,
);
const instance = wrapper.instance();
expect(baseProps.registerTypingAnimation).toHaveBeenCalledTimes(1);
expect(instance.removeTypingAnimation).not.toHaveBeenCalled();
wrapper.unmount();
expect(instance.removeTypingAnimation).toHaveBeenCalledTimes(1);
});
});