diff --git a/app/screens/flagged_posts/__snapshots__/flagged_posts.test.js.snap b/app/screens/flagged_posts/__snapshots__/flagged_posts.test.js.snap new file mode 100644 index 000000000..e6c7cbacd --- /dev/null +++ b/app/screens/flagged_posts/__snapshots__/flagged_posts.test.js.snap @@ -0,0 +1,46 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FlaggedPosts should match snapshot 1`] = ` + + + + +`; diff --git a/app/screens/flagged_posts/flagged_posts.js b/app/screens/flagged_posts/flagged_posts.js index b648ecb86..468bb5d3e 100644 --- a/app/screens/flagged_posts/flagged_posts.js +++ b/app/screens/flagged_posts/flagged_posts.js @@ -101,7 +101,7 @@ export default class FlaggedPosts extends PureComponent { }; handleHashtagPress = async (hashtag) => { - dismissModal(); + await dismissModal(); showSearchModal('#' + hashtag); }; diff --git a/app/screens/flagged_posts/flagged_posts.test.js b/app/screens/flagged_posts/flagged_posts.test.js new file mode 100644 index 000000000..586e73749 --- /dev/null +++ b/app/screens/flagged_posts/flagged_posts.test.js @@ -0,0 +1,66 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import React from 'react'; + +import Preferences from 'mattermost-redux/constants/preferences'; + +import * as NavigationActions from 'app/actions/navigation'; +import {shallowWithIntl} from 'test/intl-test-helper'; + +import FlaggedPosts from './flagged_posts'; + +jest.mock('rn-placeholder', () => ({ + ImageContent: () => {}, +})); + +describe('FlaggedPosts', () => { + const baseProps = { + actions: { + clearSearch: jest.fn(), + loadChannelsByTeamName: jest.fn(), + loadThreadIfNecessary: jest.fn(), + getFlaggedPosts: jest.fn(), + selectFocusedPostId: jest.fn(), + selectPost: jest.fn(), + }, + theme: Preferences.THEMES.default, + }; + + test('should match snapshot', () => { + const wrapper = shallowWithIntl( + + ); + + expect(wrapper.getElement()).toMatchSnapshot(); + }); + + test('should call showSearchModal after awaiting dismissModal on handleHashtagPress', async () => { + const error = new Error('foo'); + const dismissModal = jest.spyOn(NavigationActions, 'dismissModal'); + const showSearchModal = jest.spyOn(NavigationActions, 'showSearchModal'); + + const hashtag = 'test'; + const wrapper = shallowWithIntl( + + ); + + dismissModal.mockImplementation(async () => { + throw error; + }); + let caughtError; + try { + await wrapper.instance().handleHashtagPress(hashtag); + } catch (e) { + caughtError = e; + } + expect(caughtError).toBe(error); + expect(dismissModal).toHaveBeenCalled(); + expect(showSearchModal).not.toHaveBeenCalled(); + + dismissModal.mockImplementation(async () => (Promise.resolve())); + await wrapper.instance().handleHashtagPress(hashtag); + expect(dismissModal).toHaveBeenCalled(); + expect(showSearchModal).toHaveBeenCalledWith(`#${hashtag}`); + }); +}); diff --git a/app/screens/recent_mentions/__snapshots__/recent_mentions.test.js.snap b/app/screens/recent_mentions/__snapshots__/recent_mentions.test.js.snap new file mode 100644 index 000000000..33c35a8e9 --- /dev/null +++ b/app/screens/recent_mentions/__snapshots__/recent_mentions.test.js.snap @@ -0,0 +1,46 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`RecentMentions should match snapshot 1`] = ` + + + + +`; diff --git a/app/screens/recent_mentions/recent_mentions.js b/app/screens/recent_mentions/recent_mentions.js index b146861d2..7e43b89f9 100644 --- a/app/screens/recent_mentions/recent_mentions.js +++ b/app/screens/recent_mentions/recent_mentions.js @@ -95,7 +95,7 @@ export default class RecentMentions extends PureComponent { }; handleHashtagPress = async (hashtag) => { - dismissModal(); + await dismissModal(); showSearchModal('#' + hashtag); }; diff --git a/app/screens/recent_mentions/recent_mentions.test.js b/app/screens/recent_mentions/recent_mentions.test.js new file mode 100644 index 000000000..418f9f24a --- /dev/null +++ b/app/screens/recent_mentions/recent_mentions.test.js @@ -0,0 +1,66 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import React from 'react'; + +import Preferences from 'mattermost-redux/constants/preferences'; + +import * as NavigationActions from 'app/actions/navigation'; +import {shallowWithIntl} from 'test/intl-test-helper'; + +import RecentMentions from './recent_mentions'; + +jest.mock('rn-placeholder', () => ({ + ImageContent: () => {}, +})); + +describe('RecentMentions', () => { + const baseProps = { + actions: { + clearSearch: jest.fn(), + loadChannelsByTeamName: jest.fn(), + loadThreadIfNecessary: jest.fn(), + getRecentMentions: jest.fn(), + selectFocusedPostId: jest.fn(), + selectPost: jest.fn(), + }, + theme: Preferences.THEMES.default, + }; + + test('should match snapshot', () => { + const wrapper = shallowWithIntl( + + ); + + expect(wrapper.getElement()).toMatchSnapshot(); + }); + + test('should call showSearchModal after awaiting dismissModal on handleHashtagPress', async () => { + const error = new Error('foo'); + const dismissModal = jest.spyOn(NavigationActions, 'dismissModal'); + const showSearchModal = jest.spyOn(NavigationActions, 'showSearchModal'); + + const hashtag = 'test'; + const wrapper = shallowWithIntl( + + ); + + dismissModal.mockImplementation(async () => { + throw error; + }); + let caughtError; + try { + await wrapper.instance().handleHashtagPress(hashtag); + } catch (e) { + caughtError = e; + } + expect(caughtError).toBe(error); + expect(dismissModal).toHaveBeenCalled(); + expect(showSearchModal).not.toHaveBeenCalled(); + + dismissModal.mockImplementation(async () => (Promise.resolve())); + await wrapper.instance().handleHashtagPress(hashtag); + expect(dismissModal).toHaveBeenCalled(); + expect(showSearchModal).toHaveBeenCalledWith(`#${hashtag}`); + }); +});