mattermost-mobile/share_extension/android/extension_post/extension_post.test.js
Elias Nahum 03d406021f Port WebSocket from mm-redux and batch actions (#4060)
* Port WebSocket from mm-redux and batch actions

* Update mm-redux and fix tests

* Change action name

* Naming batch actions

* Fix unit tests

* Dispatch connection change only if its different

* Remove comment

* Add Lint to TypeScript and fix linting errors

* Add WebSocket Unit Tests

* Revert from unwanted RN 0.62
2020-04-17 20:44:25 -07:00

67 lines
2 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {Alert, PermissionsAndroid} from 'react-native';
import {shallowWithIntl} from 'test/intl-test-helper';
import ExtensionPost from './extension_post';
jest.spyOn(Alert, 'alert').mockReturnValue(true);
jest.spyOn(PermissionsAndroid, 'check').mockReturnValue(PermissionsAndroid.RESULTS.GRANTED);
jest.mock('react-navigation-stack/lib/module/views/TouchableItem', () => null);
jest.mock('app/mattermost_managed', () => ({
getConfig: jest.fn().mockReturnValue(false),
}));
const MAX_MESSAGE_LENGTH = 4000;
describe('ExtensionPost', () => {
const baseProps = {
actions: {
getTeamChannels: jest.fn(),
},
channelId: 'channel-id',
channels: {},
currentUserId: 'current-user-id',
maxFileSize: 1024,
navigation: {
setParams: jest.fn(),
},
teamId: 'team-id',
};
const wrapper = shallowWithIntl(
<ExtensionPost {...baseProps}/>,
);
const instance = wrapper.instance();
const postMessage = (message) => {
wrapper.setState({value: message});
instance.onPost();
};
test('should show Alert dialog if shared message is longer than maximum length permitted', () => {
const longMessage = 'a'.repeat(MAX_MESSAGE_LENGTH + 1);
postMessage(longMessage);
expect(Alert.alert).toHaveBeenCalledTimes(1);
});
test('should not show Alert dialog if shared message is within maximum length permitted', () => {
const message = 'a'.repeat(MAX_MESSAGE_LENGTH - 1);
postMessage(message);
expect(Alert.alert).not.toHaveBeenCalled();
});
test('should not show Alert dialog if shared message is at maximum length permitted', () => {
const exactLengthMessage = 'a'.repeat(MAX_MESSAGE_LENGTH);
postMessage(exactLengthMessage);
expect(Alert.alert).not.toHaveBeenCalled();
});
});