From 90dba40a928cd6a09a0142de5ffb2c98b17cc03e Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Wed, 14 Aug 2019 18:34:18 +0200 Subject: [PATCH] Automated cherry pick of #3116 (#3120) * Fix delete the root post on a thread to properly close the thread screen * Fix unit test --- app/screens/post_options/post_options.js | 7 ++++--- app/screens/post_options/post_options.test.js | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/screens/post_options/post_options.js b/app/screens/post_options/post_options.js index ff4032bb5..20d8ffddd 100644 --- a/app/screens/post_options/post_options.js +++ b/app/screens/post_options/post_options.js @@ -349,9 +349,10 @@ export default class PostOptions extends PureComponent { text: formatMessage({id: 'post_info.del', defaultMessage: 'Delete'}), style: 'destructive', onPress: () => { - actions.deletePost(post); - actions.removePost(post); - this.closeWithAnimation(); + this.closeWithAnimation(() => { + actions.deletePost(post); + actions.removePost(post); + }); }, }] ); diff --git a/app/screens/post_options/post_options.test.js b/app/screens/post_options/post_options.test.js index cd742c97f..5d46c84db 100644 --- a/app/screens/post_options/post_options.test.js +++ b/app/screens/post_options/post_options.test.js @@ -110,8 +110,14 @@ describe('PostOptions', () => { 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(); });