mattermost-mobile/app/screens/post_options/post_options.test.js
Michael Kochell 985070ee71
[MM-33766] Handle channel header call error (#5233)
* Apps bindings support (#5012)

* Add redux related information

* Add binding loading on channel refresh

* Add channel header and post option bindings

* Fix test

* Minor fixes

* Fix snapshots

* Handle errors and show bindings only on main channel

* Update Expand Levels keys and values to match latest changes

* Add NAVIGATE call response handling.

* Add more isolation to apps related code

* Add defaults to send ephemeral

* Update variable naming

* Rename shouldProcessApps by a more meaningful appsEnabled

* Embedded forms (#5169)

* Add redux related information

* Add binding loading on channel refresh

* Add channel header and post option bindings

* Fix test

* Minor fixes

* Fix snapshots

* Handle errors and show bindings only on main channel

* Update Expand Levels keys and values to match latest changes

* Add NAVIGATE call response handling.

* Add more isolation to apps related code

* Add Embedded Forms

* Fix snapshots

* Add Embedded Forms

* Improve naming, change the root element to be a binding and improve binding handling

* Get post down on the buttons, remove unneeded variables and minor fixes from the review

* Allow undefined bindings to fillBindingsInformation and add logging for error.

* Address review feedback

* Add App Forms (#5177)

* Add App Forms

* Address feedback and self review

* Add dynamic select

* Fixes and improvements

* Add the ability to refresh on submit.

* Use AppFormValue instead of redoing the type

* Address feedback

* [MM-31508] Rename URL to Path in Call (#5186)

* Add user agent to call context (#5193)

* Remove unneeded state reference (#5196)

* Change user agent query on fetch bindings (#5201)

* Add refresh websocket event to refetch bindings (#5194)

* Add refresh websocket event to refetch bindings

* Add missing changes

* Declare socket event constant and separate the handler to a different function

* Add binding validation on binding fetch (#5200)

* Apps commands (#5107)

* Add redux related information

* Add binding loading on channel refresh

* Add channel header and post option bindings

* Fix test

* Minor fixes

* Fix snapshots

* apps modals draft

* Handle errors and show bindings only on main channel

* Update Expand Levels keys and values to match latest changes

* Add NAVIGATE call response handling.

* Add more isolation to apps related code

* reuse command parser throughout slash_suggestion component's lifecycle

* fix prop and lint

* using alert to show error message. need another way

* duplicate import

* types

* types

* types

* rename file

* copy webapp parser and test

* dependencies moved. tests pass

* move app command parser into its own folder

* converted to typescript, all tests are passing

* automated and manual tests work

* lint

* lint

* remove fall throughs with blocks

* types

* doAppCall type

* extract displayError to deps file

* test types

* lint

* fix tests

* unused import

* PR feedback

* fix imports and show errors

* types

* remove execute suggestion for mobile

* watch feature flag

* fix tests

* change form text arugment behavior to show user input and not hint

* return call response error in doAppCall

* update tests to remove hint from text field suggestions

* lint

* use new base command structure

* fix tests

* wrap appsEnabled

* typescript actions/command.ts

* update app constants

* PR feedback

* fix error handling from doAppCall action

* Use App CallRequest structure (#5212)

* error handling

* move test files

* remove unused import

Co-authored-by: Daniel Espino García <larkox@gmail.com>

* Add feature flag (#5207)

* Add feature flag

* Simplify return

* Add localization, call validation and use call type on subpath (#5221)

* Add localization, call validation and use call type on subpath

* Add more localization to the parser and bring fixes from webapp

* Fix ephemerals and channel header / post options crashes

* fix app command parser deps and alert messages

* Improve suggestion handling

* Fix test

* Fix lint

* Return errors as error

* Address PR feedback

* return error property

* fix error string wordings

Co-authored-by: Michael Kochell <6913320+mickmister@users.noreply.github.com>

* leave the channel info screen when the call is successful. stay if there is an error

* fix intl in tests

Co-authored-by: Daniel Espino García <larkox@gmail.com>
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-03-24 13:39:42 -04:00

128 lines
3.9 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {Alert} from 'react-native';
import {shallowWithIntl} from 'test/intl-test-helper';
import Preferences from '@mm-redux/constants/preferences';
import PostOptions from './post_options';
describe('PostOptions', () => {
const actions = {
addReaction: jest.fn(),
deletePost: jest.fn(),
flagPost: jest.fn(),
pinPost: jest.fn(),
removePost: jest.fn(),
unflagPost: jest.fn(),
unpinPost: jest.fn(),
setUnreadPost: jest.fn(),
};
const post = {
root_id: 'root_id',
id: 'post_id',
message: 'message',
is_pinned: false,
channel_id: 'channel_id',
};
const baseProps = {
actions,
canAddReaction: true,
canReply: true,
canDelete: true,
canPin: true,
canEdit: true,
canMarkAsUnread: true,
canEditUntil: -1,
channelIsReadOnly: false,
currentTeamUrl: 'http://localhost:8065/team-name',
currentUserId: 'user1',
deviceHeight: 600,
hasBeenDeleted: false,
isFlagged: true,
isSystemMessage: false,
managedConfig: {},
post,
showAddReaction: true,
showAppOptions: true,
theme: Preferences.THEMES.default,
};
function getWrapper(props = {}) {
return shallowWithIntl(
<PostOptions
{...baseProps}
{...props}
/>,
);
}
test('should match snapshot, showing all possible options', () => {
const wrapper = getWrapper();
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should match snapshot, showing Delete option only for system message to user who has permission to delete', () => {
const wrapper = getWrapper({isSystemMessage: true});
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should match snapshot, no option for system message to user who doesn\'t have the permission to delete', () => {
const wrapper = getWrapper({isSystemMessage: true, canDelete: false});
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should load thread', () => {
const wrapper = getWrapper();
const instance = wrapper.instance();
instance.closeWithAnimation = jest.fn();
wrapper.findWhere((node) => node.key() === 'reply').simulate('press');
expect(instance.closeWithAnimation).toBeCalled();
});
test('should not show reply option', () => {
const wrapper = getWrapper({canReply: false});
expect(wrapper.findWhere((node) => node.key() === 'reply')).toMatchObject({});
});
test('should not show mark as unread option', () => {
const wrapper = getWrapper({canMarkAsUnread: false});
expect(wrapper.findWhere((node) => node.key() === 'markUnread')).toMatchObject({});
});
test('should remove post after delete', () => {
const wrapper = getWrapper();
wrapper.findWhere((node) => node.key() === 'delete').simulate('press');
expect(Alert.alert).toBeCalled();
// Trigger on press of Delete in the Alert
const closeWithAnimation = jest.spyOn(wrapper.instance(), 'closeWithAnimation');
Alert.alert.mock.calls[0][2][1].onPress();
expect(closeWithAnimation).toBeCalled();
// get the callback that gets called by closeWithAnimation
const callback = closeWithAnimation.mock.calls[0][0];
callback();
expect(actions.deletePost).toBeCalled();
expect(actions.removePost).toBeCalled();
});
test('should not show reply option without create_post permission', () => {
const wrapper = getWrapper({canPost: false});
expect(wrapper.findWhere((node) => node.key() === 'reply')).toMatchObject({});
});
});