mattermost-mobile/share_extension/android/extension_post/extension_post.test.js
Elias Nahum d3a6e166ad
MM-15758 Update dependencies including Fastlane (#4272)
* Update dependencies including Fastlane and disable Flipper on iOS

* Remove EventEmitter for previous doc-viewer

* Fix android crash when setting more channels buttons

* Downgrade fuse.js

* Upgrade deps to latest

* Update Podfile.lock

* Downgrade RNN to 6.4.0

* QA Review #2

* Upgrade fuse.js to 6.0.0
2020-05-18 11:24:47 -07:00

68 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 = {
channelId: 'channel-id',
channels: {},
currentUserId: 'current-user-id',
getTeamChannels: jest.fn(),
maxFileSize: 1024,
navigation: {
setOptions: jest.fn(),
},
route: {
params: {},
},
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();
});
});