From c2a3ef6b3db3582d3ae9f13a571109d91feb3536 Mon Sep 17 00:00:00 2001 From: Sudhanva-Nadiger <93595710+Sudhanva-Nadiger@users.noreply.github.com> Date: Tue, 24 Oct 2023 22:34:45 +0530 Subject: [PATCH] [MM-47055] Migrate "components/advanced_create_post/advanced_create_post.test.jsx" to Typescript (#24955) --- ...nap => advanced_create_post.test.tsx.snap} | 228 ++++++++- ...test.jsx => advanced_create_post.test.tsx} | 471 ++++++++++-------- .../advanced_create_post.tsx | 2 +- 3 files changed, 470 insertions(+), 231 deletions(-) rename webapp/channels/src/components/advanced_create_post/__snapshots__/{advanced_create_post.test.jsx.snap => advanced_create_post.test.tsx.snap} (80%) rename webapp/channels/src/components/advanced_create_post/{advanced_create_post.test.jsx => advanced_create_post.test.tsx} (77%) diff --git a/webapp/channels/src/components/advanced_create_post/__snapshots__/advanced_create_post.test.jsx.snap b/webapp/channels/src/components/advanced_create_post/__snapshots__/advanced_create_post.test.tsx.snap similarity index 80% rename from webapp/channels/src/components/advanced_create_post/__snapshots__/advanced_create_post.test.jsx.snap rename to webapp/channels/src/components/advanced_create_post/__snapshots__/advanced_create_post.test.tsx.snap index 5a25d4bcd3..4510585f33 100644 --- a/webapp/channels/src/components/advanced_create_post/__snapshots__/advanced_create_post.test.jsx.snap +++ b/webapp/channels/src/components/advanced_create_post/__snapshots__/advanced_create_post.test.tsx.snap @@ -12,20 +12,37 @@ exports[`components/advanced_create_post Show tutorial 1`] = ` applyMarkdown={[Function]} badConnection={false} canPost={true} - canUploadFiles={true} + canUploadFiles={false} channelId="owsyt8n43jfxjpzh9np93mx1wa" currentChannel={ Object { + "create_at": 0, + "creator_id": "id", + "delete_at": 0, + "display_name": "name", + "group_constrained": false, + "header": "header", "id": "owsyt8n43jfxjpzh9np93mx1wa", + "last_post_at": 0, + "last_root_post_at": 0, + "name": "DN", + "purpose": "purpose", + "scheme_id": "id", + "team_id": "team_id", "type": "O", + "update_at": 0, } } currentUserId="zaktnt8bpbgu8mb6ez9k64r7sa" disableSend={false} draft={ Object { + "channelId": "", + "createAt": 0, "fileInfos": Array [], "message": "", + "rootId": "", + "updateAt": 0, "uploadsInProgress": Array [], } } @@ -65,7 +82,7 @@ exports[`components/advanced_create_post Show tutorial 1`] = ` setShowPreview={[Function]} shouldShowPreview={false} showEmojiPicker={false} - showSendTutorialTip={false} + showSendTutorialTip={true} textboxRef={ Object { "current": null, @@ -91,20 +108,37 @@ exports[`components/advanced_create_post should match snapshot for center textbo applyMarkdown={[Function]} badConnection={false} canPost={true} - canUploadFiles={true} + canUploadFiles={false} channelId="owsyt8n43jfxjpzh9np93mx1wa" currentChannel={ Object { + "create_at": 0, + "creator_id": "id", + "delete_at": 0, + "display_name": "name", + "group_constrained": false, + "header": "header", "id": "owsyt8n43jfxjpzh9np93mx1wa", + "last_post_at": 0, + "last_root_post_at": 0, + "name": "DN", + "purpose": "purpose", + "scheme_id": "id", + "team_id": "team_id", "type": "O", + "update_at": 0, } } currentUserId="zaktnt8bpbgu8mb6ez9k64r7sa" disableSend={false} draft={ Object { + "channelId": "", + "createAt": 0, "fileInfos": Array [], "message": "", + "rootId": "", + "updateAt": 0, "uploadsInProgress": Array [], } } @@ -170,20 +204,37 @@ exports[`components/advanced_create_post should match snapshot when cannot post applyMarkdown={[Function]} badConnection={false} canPost={false} - canUploadFiles={true} + canUploadFiles={false} channelId="owsyt8n43jfxjpzh9np93mx1wa" currentChannel={ Object { + "create_at": 0, + "creator_id": "id", + "delete_at": 0, + "display_name": "name", + "group_constrained": false, + "header": "header", "id": "owsyt8n43jfxjpzh9np93mx1wa", + "last_post_at": 0, + "last_root_post_at": 0, + "name": "DN", + "purpose": "purpose", + "scheme_id": "id", + "team_id": "team_id", "type": "O", + "update_at": 0, } } currentUserId="zaktnt8bpbgu8mb6ez9k64r7sa" disableSend={false} draft={ Object { + "channelId": "", + "createAt": 0, "fileInfos": Array [], "message": "", + "rootId": "", + "updateAt": 0, "uploadsInProgress": Array [], } } @@ -253,16 +304,33 @@ exports[`components/advanced_create_post should match snapshot when file upload channelId="owsyt8n43jfxjpzh9np93mx1wa" currentChannel={ Object { + "create_at": 0, + "creator_id": "id", + "delete_at": 0, + "display_name": "name", + "group_constrained": false, + "header": "header", "id": "owsyt8n43jfxjpzh9np93mx1wa", + "last_post_at": 0, + "last_root_post_at": 0, + "name": "DN", + "purpose": "purpose", + "scheme_id": "id", + "team_id": "team_id", "type": "O", + "update_at": 0, } } currentUserId="zaktnt8bpbgu8mb6ez9k64r7sa" disableSend={false} draft={ Object { + "channelId": "", + "createAt": 0, "fileInfos": Array [], "message": "", + "rootId": "", + "updateAt": 0, "uploadsInProgress": Array [], } } @@ -328,20 +396,37 @@ exports[`components/advanced_create_post should match snapshot, can post; previe applyMarkdown={[Function]} badConnection={false} canPost={true} - canUploadFiles={true} + canUploadFiles={false} channelId="owsyt8n43jfxjpzh9np93mx1wa" currentChannel={ Object { + "create_at": 0, + "creator_id": "id", + "delete_at": 0, + "display_name": "name", + "group_constrained": false, + "header": "header", "id": "owsyt8n43jfxjpzh9np93mx1wa", + "last_post_at": 0, + "last_root_post_at": 0, + "name": "DN", + "purpose": "purpose", + "scheme_id": "id", + "team_id": "team_id", "type": "O", + "update_at": 0, } } currentUserId="zaktnt8bpbgu8mb6ez9k64r7sa" disableSend={false} draft={ Object { + "channelId": "", + "createAt": 0, "fileInfos": Array [], "message": "", + "rootId": "", + "updateAt": 0, "uploadsInProgress": Array [], } } @@ -407,20 +492,37 @@ exports[`components/advanced_create_post should match snapshot, can post; previe applyMarkdown={[Function]} badConnection={false} canPost={true} - canUploadFiles={true} + canUploadFiles={false} channelId="owsyt8n43jfxjpzh9np93mx1wa" currentChannel={ Object { + "create_at": 0, + "creator_id": "id", + "delete_at": 0, + "display_name": "name", + "group_constrained": false, + "header": "header", "id": "owsyt8n43jfxjpzh9np93mx1wa", + "last_post_at": 0, + "last_root_post_at": 0, + "name": "DN", + "purpose": "purpose", + "scheme_id": "id", + "team_id": "team_id", "type": "O", + "update_at": 0, } } currentUserId="zaktnt8bpbgu8mb6ez9k64r7sa" disableSend={false} draft={ Object { + "channelId": "", + "createAt": 0, "fileInfos": Array [], "message": "", + "rootId": "", + "updateAt": 0, "uploadsInProgress": Array [], } } @@ -486,20 +588,37 @@ exports[`components/advanced_create_post should match snapshot, cannot post; pre applyMarkdown={[Function]} badConnection={false} canPost={false} - canUploadFiles={true} + canUploadFiles={false} channelId="owsyt8n43jfxjpzh9np93mx1wa" currentChannel={ Object { + "create_at": 0, + "creator_id": "id", + "delete_at": 0, + "display_name": "name", + "group_constrained": false, + "header": "header", "id": "owsyt8n43jfxjpzh9np93mx1wa", + "last_post_at": 0, + "last_root_post_at": 0, + "name": "DN", + "purpose": "purpose", + "scheme_id": "id", + "team_id": "team_id", "type": "O", + "update_at": 0, } } currentUserId="zaktnt8bpbgu8mb6ez9k64r7sa" disableSend={false} draft={ Object { + "channelId": "", + "createAt": 0, "fileInfos": Array [], "message": "", + "rootId": "", + "updateAt": 0, "uploadsInProgress": Array [], } } @@ -565,20 +684,37 @@ exports[`components/advanced_create_post should match snapshot, cannot post; pre applyMarkdown={[Function]} badConnection={false} canPost={false} - canUploadFiles={true} + canUploadFiles={false} channelId="owsyt8n43jfxjpzh9np93mx1wa" currentChannel={ Object { + "create_at": 0, + "creator_id": "id", + "delete_at": 0, + "display_name": "name", + "group_constrained": false, + "header": "header", "id": "owsyt8n43jfxjpzh9np93mx1wa", + "last_post_at": 0, + "last_root_post_at": 0, + "name": "DN", + "purpose": "purpose", + "scheme_id": "id", + "team_id": "team_id", "type": "O", + "update_at": 0, } } currentUserId="zaktnt8bpbgu8mb6ez9k64r7sa" disableSend={false} draft={ Object { + "channelId": "", + "createAt": 0, "fileInfos": Array [], "message": "", + "rootId": "", + "updateAt": 0, "uploadsInProgress": Array [], } } @@ -644,20 +780,37 @@ exports[`components/advanced_create_post should match snapshot, init 1`] = ` applyMarkdown={[Function]} badConnection={false} canPost={true} - canUploadFiles={true} + canUploadFiles={false} channelId="owsyt8n43jfxjpzh9np93mx1wa" currentChannel={ Object { + "create_at": 0, + "creator_id": "id", + "delete_at": 0, + "display_name": "name", + "group_constrained": false, + "header": "header", "id": "owsyt8n43jfxjpzh9np93mx1wa", + "last_post_at": 0, + "last_root_post_at": 0, + "name": "DN", + "purpose": "purpose", + "scheme_id": "id", + "team_id": "team_id", "type": "O", + "update_at": 0, } } currentUserId="zaktnt8bpbgu8mb6ez9k64r7sa" disableSend={false} draft={ Object { + "channelId": "", + "createAt": 0, "fileInfos": Array [], "message": "", + "rootId": "", + "updateAt": 0, "uploadsInProgress": Array [], } } @@ -723,18 +876,33 @@ exports[`components/advanced_create_post should match snapshot, post priority di applyMarkdown={[Function]} badConnection={false} canPost={true} - canUploadFiles={true} + canUploadFiles={false} channelId="owsyt8n43jfxjpzh9np93mx1wa" currentChannel={ Object { + "create_at": 0, + "creator_id": "id", + "delete_at": 0, + "display_name": "name", + "group_constrained": false, + "header": "header", "id": "owsyt8n43jfxjpzh9np93mx1wa", + "last_post_at": 0, + "last_root_post_at": 0, + "name": "DN", + "purpose": "purpose", + "scheme_id": "id", + "team_id": "team_id", "type": "O", + "update_at": 0, } } currentUserId="zaktnt8bpbgu8mb6ez9k64r7sa" disableSend={false} draft={ Object { + "channelId": "", + "createAt": 0, "fileInfos": Array [], "message": "", "metadata": Object { @@ -742,6 +910,8 @@ exports[`components/advanced_create_post should match snapshot, post priority di "priority": "important", }, }, + "rootId": "", + "updateAt": 0, "uploadsInProgress": Array [], } } @@ -815,20 +985,37 @@ exports[`components/advanced_create_post should match snapshot, post priority en applyMarkdown={[Function]} badConnection={false} canPost={true} - canUploadFiles={true} + canUploadFiles={false} channelId="owsyt8n43jfxjpzh9np93mx1wa" currentChannel={ Object { + "create_at": 0, + "creator_id": "id", + "delete_at": 0, + "display_name": "name", + "group_constrained": false, + "header": "header", "id": "owsyt8n43jfxjpzh9np93mx1wa", + "last_post_at": 0, + "last_root_post_at": 0, + "name": "DN", + "purpose": "purpose", + "scheme_id": "id", + "team_id": "team_id", "type": "O", + "update_at": 0, } } currentUserId="zaktnt8bpbgu8mb6ez9k64r7sa" disableSend={false} draft={ Object { + "channelId": "", + "createAt": 0, "fileInfos": Array [], "message": "", + "rootId": "", + "updateAt": 0, "uploadsInProgress": Array [], } } @@ -907,18 +1094,33 @@ exports[`components/advanced_create_post should match snapshot, post priority en applyMarkdown={[Function]} badConnection={false} canPost={true} - canUploadFiles={true} + canUploadFiles={false} channelId="owsyt8n43jfxjpzh9np93mx1wa" currentChannel={ Object { + "create_at": 0, + "creator_id": "id", + "delete_at": 0, + "display_name": "name", + "group_constrained": false, + "header": "header", "id": "owsyt8n43jfxjpzh9np93mx1wa", + "last_post_at": 0, + "last_root_post_at": 0, + "name": "DN", + "purpose": "purpose", + "scheme_id": "id", + "team_id": "team_id", "type": "O", + "update_at": 0, } } currentUserId="zaktnt8bpbgu8mb6ez9k64r7sa" disableSend={false} draft={ Object { + "channelId": "", + "createAt": 0, "fileInfos": Array [], "message": "", "metadata": Object { @@ -926,6 +1128,8 @@ exports[`components/advanced_create_post should match snapshot, post priority en "priority": "important", }, }, + "rootId": "", + "updateAt": 0, "uploadsInProgress": Array [], } } diff --git a/webapp/channels/src/components/advanced_create_post/advanced_create_post.test.jsx b/webapp/channels/src/components/advanced_create_post/advanced_create_post.test.tsx similarity index 77% rename from webapp/channels/src/components/advanced_create_post/advanced_create_post.test.jsx rename to webapp/channels/src/components/advanced_create_post/advanced_create_post.test.tsx index 9840c546ae..6250c02491 100644 --- a/webapp/channels/src/components/advanced_create_post/advanced_create_post.test.jsx +++ b/webapp/channels/src/components/advanced_create_post/advanced_create_post.test.tsx @@ -4,18 +4,27 @@ import {shallow} from 'enzyme'; import React from 'react'; +import type {ChannelMemberCountsByGroup} from '@mattermost/types/channels'; +import type {CommandArgs} from '@mattermost/types/integrations'; +import type {Post} from '@mattermost/types/posts'; +import {PostPriority} from '@mattermost/types/posts'; + import {Posts} from 'mattermost-redux/constants'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import * as GlobalActions from 'actions/global_actions'; +import type {Props} from 'components/advanced_create_post/advanced_create_post'; import AdvancedCreatePost from 'components/advanced_create_post/advanced_create_post'; import AdvanceTextEditor from 'components/advanced_text_editor/advanced_text_editor'; +import type {TextboxElement} from 'components/textbox'; import {testComponentForLineBreak} from 'tests/helpers/line_break_helpers'; import {testComponentForMarkdownHotkeys} from 'tests/helpers/markdown_hotkey_helpers.js'; import Constants, {StoragePrefixes, ModalIdentifiers} from 'utils/constants'; import EmojiMap from 'utils/emoji_map'; import {execCommandInsertText} from 'utils/exec_commands'; +import {TestHelper} from 'utils/test_helper'; import * as Utils from 'utils/utils'; jest.mock('actions/global_actions', () => ({ @@ -25,7 +34,7 @@ jest.mock('actions/global_actions', () => ({ jest.mock('actions/post_actions', () => ({ createPost: jest.fn(() => { - return new Promise((resolve) => { + return new Promise((resolve) => { process.nextTick(() => resolve()); }); }), @@ -37,129 +46,115 @@ jest.mock('utils/exec_commands', () => ({ const currentTeamIdProp = 'r7rws4y7ppgszym3pdd5kaibfa'; const currentUserIdProp = 'zaktnt8bpbgu8mb6ez9k64r7sa'; -const showTutorialTipProp = false; +const showSendTutorialTipProp = false; const fullWidthTextBoxProp = true; -const recentPostIdInChannelProp = 'a'; const latestReplyablePostIdProp = 'a'; const localeProp = 'en'; -const currentChannelProp = { +const currentChannelProp = TestHelper.getChannelMock({ id: 'owsyt8n43jfxjpzh9np93mx1wa', type: 'O', -}; +}); + const currentChannelMembersCountProp = 9; -const draftProp = { + +const draftProp = TestHelper.getPostDraftMock({ + fileInfos: [], message: '', uploadsInProgress: [], - fileInfos: [], -}; +}); const ctrlSendProp = false; -const currentUsersLatestPostProp = {id: 'b', root_id: 'a', channel_id: currentChannelProp.id}; +const currentUsersLatestPostProp = TestHelper.getPostMock({id: 'b', root_id: 'a', channel_id: currentChannelProp.id}); -const actionsProp = { - addMessageIntoHistory: jest.fn(), - moveHistoryIndexBack: jest.fn(), - moveHistoryIndexForward: jest.fn(), - addReaction: jest.fn(), - removeReaction: jest.fn(), - clearDraftUploads: jest.fn(), - onSubmitPost: jest.fn(), - selectPostFromRightHandSideSearchByPostId: jest.fn(), - setDraft: jest.fn(), - setEditingPost: jest.fn(), - openModal: jest.fn(), - setShowPreview: jest.fn(), - savePreferences: jest.fn(), - executeCommand: async () => { - return {data: true}; +const baseProp: Props = { + currentTeamId: currentTeamIdProp, + currentChannelMembersCount: currentChannelMembersCountProp, + currentChannel: currentChannelProp, + currentUserId: currentUserIdProp, + showSendTutorialTip: showSendTutorialTipProp, + fullWidthTextBox: fullWidthTextBoxProp, + draft: draftProp, + isRemoteDraft: false, + latestReplyablePostId: latestReplyablePostIdProp, + locale: localeProp, + actions: { + addMessageIntoHistory: jest.fn(), + moveHistoryIndexBack: jest.fn(), + moveHistoryIndexForward: jest.fn(), + addReaction: jest.fn(), + removeReaction: jest.fn(), + clearDraftUploads: jest.fn(), + onSubmitPost: jest.fn(), + selectPostFromRightHandSideSearchByPostId: jest.fn(), + setDraft: jest.fn(), + setEditingPost: jest.fn(), + openModal: jest.fn(), + setShowPreview: jest.fn(), + savePreferences: jest.fn(), + executeCommand: () => { + return {data: true}; + }, + getChannelTimezones: jest.fn(), + runMessageWillBePostedHooks: (post: Post) => { + return {data: post}; + }, + runSlashCommandWillBePostedHooks: (message: string, args: CommandArgs) => { + return {data: {message, args}}; + }, + scrollPostListToBottom: jest.fn(), + getChannelMemberCountsByGroup: jest.fn(), + emitShortcutReactToLastPostFrom: jest.fn(), + searchAssociatedGroupsForReference: jest.fn(), }, - getChannelTimezones: jest.fn(), - runMessageWillBePostedHooks: async (post) => { - return {data: post}; - }, - runSlashCommandWillBePostedHooks: async (message, args) => { - return {data: {message, args}}; - }, - scrollPostListToBottom: jest.fn(), - getChannelMemberCountsByGroup: jest.fn(), - emitShortcutReactToLastPostFrom: jest.fn(), - searchAssociatedGroupsForReference: jest.fn(), + ctrlSend: ctrlSendProp, + currentUsersLatestPost: currentUsersLatestPostProp, + canUploadFiles: false, + emojiMap: new EmojiMap(new Map()), + enableEmojiPicker: true, + enableGifPicker: true, + isTimezoneEnabled: false, + useLDAPGroupMentions: true, + useCustomGroupMentions: true, + canPost: true, + isPostPriorityEnabled: false, + enableConfirmNotificationsToChannel: true, + maxPostSize: Constants.DEFAULT_CHARACTER_LIMIT, + userIsOutOfOffice: false, + rhsExpanded: false, + rhsOpen: false, + badConnection: false, + shouldShowPreview: false, + useChannelMentions: true, + isFormattingBarHidden: false, + groupsWithAllowReference: null, + channelMemberCountsByGroup: [] as unknown as ChannelMemberCountsByGroup, + postEditorActions: [], }; -function advancedCreatePost({ - currentChannel = currentChannelProp, - currentTeamId = currentTeamIdProp, - currentUserId = currentUserIdProp, - showSendTutorialTip = showTutorialTipProp, - currentChannelMembersCount = currentChannelMembersCountProp, - fullWidthTextBox = fullWidthTextBoxProp, - draft = draftProp, - recentPostIdInChannel = recentPostIdInChannelProp, - latestReplyablePostId = latestReplyablePostIdProp, - locale = localeProp, - actions = actionsProp, - ctrlSend = ctrlSendProp, - currentUsersLatestPost = currentUsersLatestPostProp, - canUploadFiles = true, - emojiMap = new EmojiMap(new Map()), - isTimezoneEnabled = false, - useLDAPGroupMentions = true, - useCustomGroupMentions = true, - canPost = true, - isMarkdownPreviewEnabled = false, - isPostPriorityEnabled = false, -} = {}) { +const submitEvent = { + preventDefault: jest.fn(), +} as unknown as React.FormEvent; + +function advancedCreatePost(props?: Partial) { + const allProps: Props = {...baseProp, ...props}; + return ( - + ); } describe('components/advanced_create_post', () => { jest.useFakeTimers('legacy'); + let spy: jest.SpyInstance; beforeEach(() => { - jest.spyOn(window, 'requestAnimationFrame').mockImplementation((cb) => setTimeout(cb, 16)); + spy = jest.spyOn(window, 'requestAnimationFrame').mockImplementation((cb) => setTimeout(cb, 16)); }); afterEach(() => { - window.requestAnimationFrame.mockRestore(); + spy.mockRestore(); }); it('should match snapshot, init', () => { @@ -178,7 +173,7 @@ describe('components/advanced_create_post', () => { it('should call clearDraftUploads on mount', () => { const clearDraftUploads = jest.fn(); const actions = { - ...actionsProp, + ...baseProp.actions, clearDraftUploads, }; @@ -215,7 +210,7 @@ describe('components/advanced_create_post', () => { message: 'hello', }; const actions = { - ...actionsProp, + ...baseProp.actions, searchAssociatedGroupsForReference, }; const wrapper = shallow(advancedCreatePost({draft, actions})); @@ -236,7 +231,7 @@ describe('components/advanced_create_post', () => { message: '@group1 hello', }; const actions = { - ...actionsProp, + ...baseProp.actions, searchAssociatedGroupsForReference, }; const wrapper = shallow(advancedCreatePost({draft, actions})); @@ -257,7 +252,7 @@ describe('components/advanced_create_post', () => { message: '@group1 @group2 hello', }; const actions = { - ...actionsProp, + ...baseProp.actions, getChannelMemberCountsByGroup, }; const wrapper = shallow(advancedCreatePost({draft, actions})); @@ -275,7 +270,7 @@ describe('components/advanced_create_post', () => { const getChannelMemberCountsByGroup = jest.fn(); const useLDAPGroupMentions = false; const actions = { - ...actionsProp, + ...baseProp.actions, getChannelMemberCountsByGroup, }; const wrapper = shallow(advancedCreatePost({actions, useLDAPGroupMentions})); @@ -362,7 +357,7 @@ describe('components/advanced_create_post', () => { // const wrapper = shallow( // advancedCreatePost({ // actions: { - // ...actionsProp, + // ...baseProp.actions, // setDraft, // }, // }), @@ -398,16 +393,18 @@ describe('components/advanced_create_post', () => { message: 'test @here', }); + const instance = wrapper.instance() as AdvancedCreatePost; + const form = wrapper.find('#create_post'); form.simulate('Submit', {preventDefault: jest.fn()}); - expect(wrapper.instance().props.actions.openModal).toHaveBeenCalledTimes(1); + expect(instance.props.actions.openModal).toHaveBeenCalledTimes(1); wrapper.setProps({ currentChannelMembersCount: 2, }); form.simulate('Submit', {preventDefault: jest.fn()}); - expect(wrapper.instance().props.actions.openModal).toHaveBeenCalledTimes(1); + expect(instance.props.actions.openModal).toHaveBeenCalledTimes(1); }); it('onSubmit test for @all', () => { @@ -417,16 +414,18 @@ describe('components/advanced_create_post', () => { message: 'test @all', }); + const instance = wrapper.instance() as AdvancedCreatePost; + const form = wrapper.find('#create_post'); form.simulate('Submit', {preventDefault: jest.fn()}); - expect(wrapper.instance().props.actions.openModal).toHaveBeenCalledTimes(1); + expect(instance.props.actions.openModal).toHaveBeenCalledTimes(1); wrapper.setProps({ currentChannelMembersCount: 2, }); form.simulate('Submit', {preventDefault: jest.fn()}); - expect(wrapper.instance().props.actions.openModal).toHaveBeenCalledTimes(1); + expect(instance.props.actions.openModal).toHaveBeenCalledTimes(1); }); it('onSubmit test for @groups', () => { @@ -450,13 +449,15 @@ describe('components/advanced_create_post', () => { message: '@developers', }); - const showNotifyAllModal = wrapper.instance().showNotifyAllModal; - wrapper.instance().showNotifyAllModal = jest.fn((mentions, channelTimezoneCount, memberNotifyCount) => showNotifyAllModal(mentions, channelTimezoneCount, memberNotifyCount)); + const instance = wrapper.instance() as AdvancedCreatePost; + + const showNotifyAllModal = (instance).showNotifyAllModal; + instance.showNotifyAllModal = jest.fn((mentions, channelTimezoneCount, memberNotifyCount) => showNotifyAllModal(mentions, channelTimezoneCount, memberNotifyCount)); const form = wrapper.find('#create_post'); form.simulate('Submit', {preventDefault: jest.fn()}); - expect(wrapper.instance().props.actions.openModal).toHaveBeenCalled(); - expect(wrapper.instance().showNotifyAllModal).toHaveBeenCalledWith(['@developers'], 0, 10); + expect(instance.props.actions.openModal).toHaveBeenCalled(); + expect(instance.showNotifyAllModal).toHaveBeenCalledWith(['@developers'], 0, 10); }); it('onSubmit test for several @groups', () => { @@ -512,13 +513,15 @@ describe('components/advanced_create_post', () => { message: '@developers @boss @love @you @software-developers', }); - const showNotifyAllModal = wrapper.instance().showNotifyAllModal; - wrapper.instance().showNotifyAllModal = jest.fn((mentions, channelTimezoneCount, memberNotifyCount) => showNotifyAllModal(mentions, channelTimezoneCount, memberNotifyCount)); + const instance = wrapper.instance() as AdvancedCreatePost; + + const showNotifyAllModal = instance.showNotifyAllModal; + instance.showNotifyAllModal = jest.fn((mentions, channelTimezoneCount, memberNotifyCount) => showNotifyAllModal(mentions, channelTimezoneCount, memberNotifyCount)); const form = wrapper.find('#create_post'); form.simulate('Submit', {preventDefault: jest.fn()}); - expect(wrapper.instance().props.actions.openModal).toHaveBeenCalled(); - expect(wrapper.instance().showNotifyAllModal).toHaveBeenCalledWith(['@developers', '@boss', '@love', '@you', '@software-developers'], 0, 40); + expect(instance.props.actions.openModal).toHaveBeenCalled(); + expect(instance.showNotifyAllModal).toHaveBeenCalledWith(['@developers', '@boss', '@love', '@you', '@software-developers'], 0, 40); }); it('onSubmit test for several @groups with timezone', () => { @@ -566,20 +569,22 @@ describe('components/advanced_create_post', () => { message: '@developers @boss @love @you', }); - const showNotifyAllModal = wrapper.instance().showNotifyAllModal; - wrapper.instance().showNotifyAllModal = jest.fn((mentions, channelTimezoneCount, memberNotifyCount) => showNotifyAllModal(mentions, channelTimezoneCount, memberNotifyCount)); + const instance = wrapper.instance() as AdvancedCreatePost; + + const showNotifyAllModal = instance.showNotifyAllModal; + instance.showNotifyAllModal = jest.fn((mentions, channelTimezoneCount, memberNotifyCount) => showNotifyAllModal(mentions, channelTimezoneCount, memberNotifyCount)); const form = wrapper.find('#create_post'); form.simulate('Submit', {preventDefault: jest.fn()}); - expect(wrapper.instance().props.actions.openModal).toHaveBeenCalled(); - expect(wrapper.instance().showNotifyAllModal).toHaveBeenCalledWith(['@developers', '@boss', '@love', '@you'], 5, 40); + expect(instance.props.actions.openModal).toHaveBeenCalled(); + expect(instance.showNotifyAllModal).toHaveBeenCalledWith(['@developers', '@boss', '@love', '@you'], 5, 40); }); it('Should set mentionHighlightDisabled prop when useChannelMentions disabled before calling actions.onSubmitPost', async () => { const onSubmitPost = jest.fn(); const wrapper = shallow(advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, onSubmitPost, }, })); @@ -588,8 +593,8 @@ describe('components/advanced_create_post', () => { useChannelMentions: false, }); - const post = {message: 'message with @here mention'}; - await wrapper.instance().sendMessage(post); + const post = TestHelper.getPostMock({message: 'message with @here mention'}); + await (wrapper.instance() as AdvancedCreatePost).sendMessage(post); expect(onSubmitPost).toHaveBeenCalledTimes(1); expect(onSubmitPost.mock.calls[0][0]).toEqual({...post, props: {mentionHighlightDisabled: true}}); @@ -599,7 +604,7 @@ describe('components/advanced_create_post', () => { const onSubmitPost = jest.fn(); const wrapper = shallow(advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, onSubmitPost, }, })); @@ -608,8 +613,8 @@ describe('components/advanced_create_post', () => { useChannelMentions: true, }); - const post = {message: 'message with @here mention'}; - await wrapper.instance().sendMessage(post); + const post = TestHelper.getPostMock({message: 'message with @here mention'}); + await (wrapper.instance() as AdvancedCreatePost).sendMessage(post); expect(onSubmitPost).toHaveBeenCalledTimes(1); expect(onSubmitPost.mock.calls[0][0]).toEqual(post); @@ -619,7 +624,7 @@ describe('components/advanced_create_post', () => { const onSubmitPost = jest.fn(); const wrapper = shallow(advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, onSubmitPost, }, })); @@ -628,19 +633,22 @@ describe('components/advanced_create_post', () => { useChannelMentions: false, }); - const post = {message: 'message without mention'}; - await wrapper.instance().sendMessage(post); + const post = TestHelper.getPostMock({message: 'message with @here mention'}); + await (wrapper.instance() as AdvancedCreatePost).sendMessage(post); expect(onSubmitPost).toHaveBeenCalledTimes(1); expect(onSubmitPost.mock.calls[0][0]).toEqual(post); }); it('onSubmit test for @all with timezones', async () => { + const result: ActionResult = { + data: [1, 2, 3, 4], + }; const wrapper = shallow( advancedCreatePost({ actions: { - ...actionsProp, - getChannelTimezones: jest.fn(() => Promise.resolve({data: [1, 2, 3, 4]})), + ...baseProp.actions, + getChannelTimezones: jest.fn(() => result), }, isTimezoneEnabled: true, currentChannelMembersCount: 9, @@ -651,27 +659,35 @@ describe('components/advanced_create_post', () => { message: 'test @all', }); - const showNotifyAllModal = wrapper.instance().showNotifyAllModal; - wrapper.instance().showNotifyAllModal = jest.fn((mentions, channelTimezoneCount, memberNotifyCount) => showNotifyAllModal(mentions, channelTimezoneCount, memberNotifyCount)); + const instance = wrapper.instance() as AdvancedCreatePost; + + const showNotifyAllModal = instance.showNotifyAllModal; + instance.showNotifyAllModal = jest.fn((mentions, channelTimezoneCount, memberNotifyCount) => showNotifyAllModal(mentions, channelTimezoneCount, memberNotifyCount)); const form = wrapper.find('#create_post'); await form.simulate('Submit', {preventDefault: jest.fn()}); - expect(wrapper.instance().props.actions.openModal).toHaveBeenCalledTimes(1); - expect(wrapper.instance().showNotifyAllModal).toHaveBeenCalledWith(['@all'], 4, 8); + expect(instance.props.actions.openModal).toHaveBeenCalledTimes(1); + expect(instance.showNotifyAllModal).toHaveBeenCalledWith(['@all'], 4, 8); wrapper.setProps({ currentChannelMembersCount: 2, }); form.simulate('Submit', {preventDefault: jest.fn()}); - expect(wrapper.instance().props.actions.openModal).toHaveBeenCalledTimes(1); + expect(instance.props.actions.openModal).toHaveBeenCalledTimes(1); }); it('onSubmit test for @all with timezones disabled', () => { + const result: ActionResult = { + data: [], + }; const wrapper = shallow( advancedCreatePost({ - getChannelTimezones: jest.fn(() => Promise.resolve([])), + actions: { + ...baseProp.actions, + getChannelTimezones: jest.fn(() => result), + }, isTimezoneEnabled: false, }), ); @@ -680,16 +696,18 @@ describe('components/advanced_create_post', () => { message: 'test @all', }); + const instance = wrapper.instance() as AdvancedCreatePost; + const form = wrapper.find('#create_post'); form.simulate('Submit', {preventDefault: jest.fn()}); - expect(wrapper.instance().props.actions.openModal).toHaveBeenCalledTimes(1); + expect(instance.props.actions.openModal).toHaveBeenCalledTimes(1); wrapper.setProps({ currentChannelMembersCount: 2, }); form.simulate('Submit', {preventDefault: jest.fn()}); - expect(wrapper.instance().props.actions.openModal).toHaveBeenCalledTimes(1); + expect(instance.props.actions.openModal).toHaveBeenCalledTimes(1); }); it('onSubmit test for "/header" message', () => { @@ -698,7 +716,7 @@ describe('components/advanced_create_post', () => { const wrapper = shallow( advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, openModal, }, }), @@ -721,7 +739,7 @@ describe('components/advanced_create_post', () => { const wrapper = shallow( advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, openModal, }, }), @@ -749,7 +767,7 @@ describe('components/advanced_create_post', () => { message: '/unknown', }); - await wrapper.instance().handleSubmit({preventDefault: jest.fn()}); + await (wrapper.instance() as AdvancedCreatePost).handleSubmit(submitEvent); expect(wrapper.state('submitting')).toBe(false); }); @@ -759,7 +777,7 @@ describe('components/advanced_create_post', () => { const wrapper = shallow( advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, addReaction, }, }), @@ -769,7 +787,7 @@ describe('components/advanced_create_post', () => { message: '+:smile:', }); - await wrapper.instance().handleSubmit({preventDefault: jest.fn()}); + await (wrapper.instance() as AdvancedCreatePost).handleSubmit(submitEvent); expect(addReaction).toHaveBeenCalledWith('a', 'smile'); }); @@ -779,7 +797,7 @@ describe('components/advanced_create_post', () => { const wrapper = shallow( advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, removeReaction, }, }), @@ -814,7 +832,14 @@ describe('components/advanced_create_post', () => { it('check for handleFileUploadChange callback for focus', () => { const wrapper = shallow(advancedCreatePost()); - const instance = wrapper.instance(); + const instance: any = wrapper.instance(); + const mockImpl = () => { + return { + setSelectionRange: jest.fn(), + focus: jest.fn(), + }; + }; + instance.textboxRef.current = {getInputBox: jest.fn(mockImpl), focus: jest.fn(), blur: jest.fn()}; instance.focusTextbox = jest.fn(); instance.handleFileUploadChange(); @@ -827,13 +852,13 @@ describe('components/advanced_create_post', () => { const wrapper = shallow( advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, setDraft, }, }), ); - const instance = wrapper.instance(); + const instance = wrapper.instance() as AdvancedCreatePost; const clientIds = ['a']; const draft = { ...draftProp, @@ -853,13 +878,13 @@ describe('components/advanced_create_post', () => { const wrapper = shallow( advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, setDraft, }, }), ); - const instance = wrapper.instance(); + const instance: any = wrapper.instance(); const clientIds = ['a']; const uploadsInProgressDraft = { ...draftProp, @@ -872,14 +897,12 @@ describe('components/advanced_create_post', () => { instance.draftsForChannel[currentChannelProp.id] = uploadsInProgressDraft; wrapper.setProps({draft: uploadsInProgressDraft}); - const fileInfos = { - id: 'a', - }; + const fileInfos = [TestHelper.getFileInfoMock({id: 'a'})]; const expectedDraft = { ...draftProp, fileInfos: [ ...draftProp.fileInfos, - fileInfos, + ...fileInfos, ], }; @@ -895,13 +918,13 @@ describe('components/advanced_create_post', () => { const wrapper = shallow( advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, setDraft, }, }), ); - const instance = wrapper.instance(); + const instance: any = wrapper.instance(); const uploadsInProgressDraft = { ...draftProp, uploadsInProgress: [ @@ -934,11 +957,11 @@ describe('components/advanced_create_post', () => { it('Remove preview from fileInfos', () => { const setDraft = jest.fn(); - const fileInfos = { + const fileInfos = TestHelper.getFileInfoMock({ id: 'a', extension: 'jpg', name: 'trimmedFilename', - }; + }); const uploadsInProgressDraft = { ...draftProp, fileInfos: [ @@ -950,7 +973,7 @@ describe('components/advanced_create_post', () => { const wrapper = shallow( advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, setDraft, }, draft: { @@ -960,7 +983,7 @@ describe('components/advanced_create_post', () => { }), ); - const instance = wrapper.instance(); + const instance = wrapper.instance() as AdvancedCreatePost; instance.handleFileUploadChange = jest.fn(); instance.removePreview('a'); @@ -975,7 +998,7 @@ describe('components/advanced_create_post', () => { ctrlSend: true, })); - const instance = wrapper.instance(); + const instance: any = wrapper.instance(); instance.textboxRef.current = {blur: jest.fn()}; const target = { @@ -992,7 +1015,7 @@ describe('components/advanced_create_post', () => { stopPropagation: jest.fn(), persist: jest.fn(), target, - }; + } as unknown as React.KeyboardEvent; instance.handleKeyDown(event); setTimeout(() => { @@ -1004,11 +1027,11 @@ describe('components/advanced_create_post', () => { const setEditingPost = jest.fn(); const wrapper = shallow(advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, setEditingPost, }, })); - const instance = wrapper.instance(); + const instance = wrapper.instance() as AdvancedCreatePost; const type = Utils.localizeMessage('create_post.comment', Posts.MESSAGE_TYPES.COMMENT); const target = { @@ -1023,7 +1046,7 @@ describe('components/advanced_create_post', () => { preventDefault: jest.fn(), persist: jest.fn(), target, - }; + } as unknown as React.KeyboardEvent; instance.handleKeyDown(event); expect(setEditingPost).toHaveBeenCalledWith(currentUsersLatestPostProp.id, 'post_textbox', type); @@ -1033,11 +1056,11 @@ describe('components/advanced_create_post', () => { const setEditingPost = jest.fn(); const wrapper = shallow(advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, setEditingPost, }, })); - const instance = wrapper.instance(); + const instance = wrapper.instance() as AdvancedCreatePost; wrapper.setProps({ currentUsersLatestPost: {id: 'b', channel_id: currentChannelProp.id}, @@ -1057,7 +1080,7 @@ describe('components/advanced_create_post', () => { preventDefault: jest.fn(), persist: jest.fn(), target, - }; + } as unknown as React.KeyboardEvent; instance.handleKeyDown(event); expect(setEditingPost).toHaveBeenCalledWith(currentUsersLatestPostProp.id, 'post_textbox', type); @@ -1066,18 +1089,18 @@ describe('components/advanced_create_post', () => { it('Should call moveHistoryIndexForward as ctrlKey and down arrow', () => { const moveHistoryIndexForward = jest.fn( () => { - return new Promise((resolve) => { + return new Promise((resolve) => { process.nextTick(() => resolve()); }); }, ); const wrapper = shallow(advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, moveHistoryIndexForward, }, })); - const instance = wrapper.instance(); + const instance = wrapper.instance() as AdvancedCreatePost; const target = { selectionStart: 0, @@ -1093,7 +1116,7 @@ describe('components/advanced_create_post', () => { stopPropagation: jest.fn(), persist: jest.fn(), target, - }; + } as unknown as React.KeyboardEvent; instance.handleKeyDown(event); expect(moveHistoryIndexForward).toHaveBeenCalled(); @@ -1102,18 +1125,18 @@ describe('components/advanced_create_post', () => { it('Should call moveHistoryIndexBack as ctrlKey and up arrow', () => { const moveHistoryIndexBack = jest.fn( () => { - return new Promise((resolve) => { + return new Promise((resolve) => { process.nextTick(() => resolve()); }); }, ); const wrapper = shallow(advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, moveHistoryIndexBack, }, })); - const instance = wrapper.instance(); + const instance = wrapper.instance() as AdvancedCreatePost; const target = { selectionStart: 0, @@ -1129,7 +1152,7 @@ describe('components/advanced_create_post', () => { stopPropagation: jest.fn(), persist: jest.fn(), target, - }; + } as unknown as React.KeyboardEvent; instance.handleKeyDown(event); expect(moveHistoryIndexBack).toHaveBeenCalled(); @@ -1137,7 +1160,7 @@ describe('components/advanced_create_post', () => { it('Show tutorial', () => { const wrapper = shallow(advancedCreatePost({ - showTutorialTip: true, + showSendTutorialTip: true, })); expect(wrapper).toMatchSnapshot(); }); @@ -1146,12 +1169,12 @@ describe('components/advanced_create_post', () => { const onSubmitPost = jest.fn(); const wrapper = shallow(advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, onSubmitPost, }, })); - const post = {message: 'message', file_ids: []}; - await wrapper.instance().sendMessage(post); + const post = TestHelper.getPostMock({message: 'message', file_ids: []}); + await (wrapper.instance() as AdvancedCreatePost).sendMessage(post); expect(onSubmitPost).toHaveBeenCalledTimes(1); expect(onSubmitPost.mock.calls[0][0]).toEqual(post); @@ -1163,18 +1186,20 @@ describe('components/advanced_create_post', () => { let latestReplyablePostId = ''; const wrapper = shallow(advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, selectPostFromRightHandSideSearchByPostId, }, latestReplyablePostId, })); - wrapper.instance().replyToLastPost({preventDefault: jest.fn()}); + const event = {preventDefault: jest.fn()} as unknown as React.KeyboardEvent; + + (wrapper.instance() as AdvancedCreatePost).replyToLastPost(event); expect(selectPostFromRightHandSideSearchByPostId).not.toBeCalled(); latestReplyablePostId = 'latest_replyablePost_id'; wrapper.setProps({latestReplyablePostId}); - wrapper.instance().replyToLastPost({preventDefault: jest.fn()}); + (wrapper.instance() as AdvancedCreatePost).replyToLastPost(event); expect(selectPostFromRightHandSideSearchByPostId).toHaveBeenCalledTimes(1); expect(selectPostFromRightHandSideSearchByPostId.mock.calls[0][0]).toEqual(latestReplyablePostId); }); @@ -1194,13 +1219,16 @@ describe('components/advanced_create_post', () => { message: 'No command found', server_error_id: 'api.command.execute_command.not_found.app_error', }; - const executeCommand = jest.fn(() => Promise.resolve({error})); + const result: ActionResult = { + error, + }; + const executeCommand = jest.fn(() => result); const onSubmitPost = jest.fn(); const wrapper = shallow( advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, executeCommand, onSubmitPost, }, @@ -1211,11 +1239,11 @@ describe('components/advanced_create_post', () => { message: '/fakecommand some text', }); - await wrapper.instance().handleSubmit({preventDefault: jest.fn()}); + await (wrapper.instance() as AdvancedCreatePost).handleSubmit(submitEvent); expect(executeCommand).toHaveBeenCalled(); expect(onSubmitPost).not.toHaveBeenCalled(); - await wrapper.instance().handleSubmit({preventDefault: jest.fn()}); + await (wrapper.instance() as AdvancedCreatePost).handleSubmit(submitEvent); expect(onSubmitPost).toHaveBeenCalledWith( expect.objectContaining({ @@ -1230,13 +1258,14 @@ describe('components/advanced_create_post', () => { message: 'No command found', server_error_id: 'api.command.execute_command.not_found.app_error', }; - const executeCommand = jest.fn(() => Promise.resolve({error})); + + const executeCommand = jest.fn().mockResolvedValue({error}); const onSubmitPost = jest.fn(); const wrapper = shallow( advancedCreatePost({ actions: { - ...actionsProp, + ...baseProp.actions, executeCommand, onSubmitPost, }, @@ -1247,15 +1276,21 @@ describe('components/advanced_create_post', () => { message: '/fakecommand some text', }); - await wrapper.instance().handleSubmit({preventDefault: jest.fn()}); + const instance = wrapper.instance() as AdvancedCreatePost; + + await instance.handleSubmit(submitEvent); expect(executeCommand).toHaveBeenCalled(); expect(onSubmitPost).not.toHaveBeenCalled(); - wrapper.instance().handleChange({ - target: {value: 'some valid text'}, - }); + const event = { + target: { + value: 'some valid text', + }, + } as unknown as React.ChangeEvent; - await wrapper.instance().handleSubmit({preventDefault: jest.fn()}); + instance.handleChange(event); + + await instance.handleSubmit(submitEvent); expect(onSubmitPost).toHaveBeenCalledWith( expect.objectContaining({ @@ -1273,7 +1308,7 @@ describe('components/advanced_create_post', () => { focus: jest.fn(), }; }; - wrapper.instance().textboxRef.current = {getInputBox: jest.fn(mockImpl), focus: jest.fn(), blur: jest.fn()}; + (wrapper.instance() as any).textboxRef.current = {getInputBox: jest.fn(mockImpl), focus: jest.fn(), blur: jest.fn()}; const event = { target: { @@ -1287,11 +1322,11 @@ describe('components/advanced_create_post', () => { return '
testtest
testtest
'; }, }, - }; + } as unknown as ClipboardEvent; const markdownTable = '| test | test |\n| --- | --- |\n| test | test |'; - wrapper.instance().pasteHandler(event); + (wrapper.instance() as AdvancedCreatePost).pasteHandler(event); expect(execCommandInsertText).toHaveBeenCalledWith(markdownTable); }); @@ -1303,7 +1338,7 @@ describe('components/advanced_create_post', () => { focus: jest.fn(), }; }; - wrapper.instance().textboxRef.current = {getInputBox: jest.fn(mockImpl), focus: jest.fn(), blur: jest.fn()}; + (wrapper.instance() as any).textboxRef.current = {getInputBox: jest.fn(mockImpl), focus: jest.fn(), blur: jest.fn()}; const event = { target: { @@ -1317,11 +1352,11 @@ describe('components/advanced_create_post', () => { return '
testtest
testtest
'; }, }, - }; + } as unknown as ClipboardEvent; const markdownTable = '| test | test |\n| --- | --- |\n| test | test |\n'; - wrapper.instance().pasteHandler(event); + (wrapper.instance() as AdvancedCreatePost).pasteHandler(event); expect(execCommandInsertText).toHaveBeenCalledWith(markdownTable); }); @@ -1333,7 +1368,7 @@ describe('components/advanced_create_post', () => { focus: jest.fn(), }; }; - wrapper.instance().textboxRef.current = {getInputBox: jest.fn(mockImpl), focus: jest.fn(), blur: jest.fn()}; + (wrapper.instance() as any).textboxRef.current = {getInputBox: jest.fn(mockImpl), focus: jest.fn(), blur: jest.fn()}; const event = { target: { @@ -1347,11 +1382,11 @@ describe('components/advanced_create_post', () => { return 'link text'; }, }, - }; + } as unknown as ClipboardEvent; const markdownLink = '[link text](https://test.domain)'; - wrapper.instance().pasteHandler(event); + (wrapper.instance() as AdvancedCreatePost).pasteHandler(event); expect(execCommandInsertText).toHaveBeenCalledWith(markdownLink); }); @@ -1363,7 +1398,7 @@ describe('components/advanced_create_post', () => { focus: jest.fn(), }; }; - wrapper.instance().textboxRef.current = {getInputBox: jest.fn(mockImpl), focus: jest.fn(), blur: jest.fn()}; + (wrapper.instance() as any).textboxRef.current = {getInputBox: jest.fn(mockImpl), focus: jest.fn(), blur: jest.fn()}; const event = { target: { @@ -1373,18 +1408,18 @@ describe('components/advanced_create_post', () => { clipboardData: { items: [1], types: ['text/plain', 'text/html'], - getData: (type) => { + getData: (type: string) => { if (type === 'text/plain') { return '// a javascript codeblock example\nif (1 > 0) {\n return \'condition is true\';\n}'; } return '
// a javascript codeblock example
 if (1 > 0) {
 console.log(\'condition is true\');
 }
'; }, }, - }; + } as unknown as ClipboardEvent; const codeBlockMarkdown = "```\n// a javascript codeblock example\nif (1 > 0) {\n return 'condition is true';\n}\n```"; - wrapper.instance().pasteHandler(event); + (wrapper.instance() as AdvancedCreatePost).pasteHandler(event); expect(execCommandInsertText).toHaveBeenCalledWith(codeBlockMarkdown); }); @@ -1431,14 +1466,14 @@ describe('components/advanced_create_post', () => { // }); testComponentForLineBreak( - (value) => advancedCreatePost({draft: {...draftProp, message: value}}), - (instance) => instance.state().message, + (value: string) => advancedCreatePost({draft: {...draftProp, message: value}}), + (instance: any) => instance.state.message, false, ); testComponentForMarkdownHotkeys( - (value) => advancedCreatePost({draft: {...draftProp, message: value}}), - (wrapper, setSelectionRangeFn) => { + (value: string) => advancedCreatePost({draft: {...draftProp, message: value}}), + (wrapper: any, setSelectionRangeFn: any) => { wrapper.instance().textboxRef = { current: { getInputBox: jest.fn(() => { @@ -1450,32 +1485,32 @@ describe('components/advanced_create_post', () => { }, }; }, - (instance) => instance.find(AdvanceTextEditor), - (instance) => instance.state().message, + (instance: any) => instance.find(AdvanceTextEditor), + (instance: any) => instance.state().message, false, 'post_textbox', ); it('should match snapshot, can post; preview enabled', () => { - const wrapper = shallow(advancedCreatePost({canPost: true, isMarkdownPreviewEnabled: true})); + const wrapper = shallow(advancedCreatePost({canPost: true})); expect(wrapper).toMatchSnapshot(); }); it('should match snapshot, can post; preview disabled', () => { - const wrapper = shallow(advancedCreatePost({canPost: true, isMarkdownPreviewEnabled: false})); + const wrapper = shallow(advancedCreatePost({canPost: true})); expect(wrapper).toMatchSnapshot(); }); it('should match snapshot, cannot post; preview enabled', () => { - const wrapper = shallow(advancedCreatePost({canPost: false, isMarkdownPreviewEnabled: true})); + const wrapper = shallow(advancedCreatePost({canPost: false})); expect(wrapper).toMatchSnapshot(); }); it('should match snapshot, cannot post; preview disabled', () => { - const wrapper = shallow(advancedCreatePost({canPost: false, isMarkdownPreviewEnabled: false})); + const wrapper = shallow(advancedCreatePost({canPost: false})); expect(wrapper).toMatchSnapshot(); }); @@ -1487,13 +1522,13 @@ describe('components/advanced_create_post', () => { }); it('should match snapshot, post priority enabled, with priority important', () => { - const wrapper = shallow(advancedCreatePost({isPostPriorityEnabled: true, draft: {...draftProp, metadata: {priority: {priority: 'important'}}}})); + const wrapper = shallow(advancedCreatePost({isPostPriorityEnabled: true, draft: {...draftProp, metadata: {priority: {priority: PostPriority.IMPORTANT}}}})); expect(wrapper).toMatchSnapshot(); }); it('should match snapshot, post priority disabled, with priority important', () => { - const wrapper = shallow(advancedCreatePost({isPostPriorityEnabled: false, draft: {...draftProp, metadata: {priority: {priority: 'important'}}}})); + const wrapper = shallow(advancedCreatePost({isPostPriorityEnabled: false, draft: {...draftProp, metadata: {priority: {priority: PostPriority.IMPORTANT}}}})); expect(wrapper).toMatchSnapshot(); }); diff --git a/webapp/channels/src/components/advanced_create_post/advanced_create_post.tsx b/webapp/channels/src/components/advanced_create_post/advanced_create_post.tsx index 6ad01812ab..23bba031da 100644 --- a/webapp/channels/src/components/advanced_create_post/advanced_create_post.tsx +++ b/webapp/channels/src/components/advanced_create_post/advanced_create_post.tsx @@ -86,7 +86,7 @@ function isDraftEmpty(draft: PostDraft): boolean { type TextboxElement = HTMLInputElement | HTMLTextAreaElement; -type Props = { +export type Props = { // ref passed from channelView for EmojiPickerOverlay getChannelView?: () => void;