[MM-14777] Remove post for user after user deletes it (#2745)

* Remove post after delete

* Add unit test

* Fix check-style errors
This commit is contained in:
Miguel Alatzar 2019-04-29 17:07:30 -07:00 committed by GitHub
parent 412a009965
commit c87845dee8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View file

@ -363,7 +363,7 @@ export default class PostOptions extends PureComponent {
handlePostDelete = () => {
const {formatMessage} = this.context.intl;
const {actions, isMyPost, post} = this.props;
const {actions, post} = this.props;
Alert.alert(
formatMessage({id: 'mobile.post.delete_title', defaultMessage: 'Delete Post'}),
@ -379,9 +379,7 @@ export default class PostOptions extends PureComponent {
style: 'destructive',
onPress: () => {
actions.deletePost(post);
if (isMyPost) {
actions.removePost(post);
}
actions.removePost(post);
this.closeWithAnimation();
},
}]

View file

@ -2,6 +2,7 @@
// See LICENSE.txt for license information.
import React from 'react';
import {Alert} from 'react-native';
import {shallow} from 'enzyme';
import Preferences from 'mattermost-redux/constants/preferences';
@ -10,6 +11,12 @@ import PostOptions from './post_options';
jest.mock('react-intl');
jest.mock('Alert', () => {
return {
alert: jest.fn(),
};
});
describe('PostOptions', () => {
const navigator = {
showModal: jest.fn(),
@ -99,4 +106,17 @@ describe('PostOptions', () => {
expect(wrapper.findWhere((node) => node.key() === 'reply')).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
Alert.alert.mock.calls[0][2][1].onPress();
expect(actions.deletePost).toBeCalled();
expect(actions.removePost).toBeCalled();
});
});