From e086dc2fb73934a229a86116d8815280056c5f23 Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk Date: Fri, 1 Oct 2021 13:47:47 +0200 Subject: [PATCH] "Fix" typescript issues --- .../views/rooms/SendMessageComposer-test.tsx | 99 ++++++++++++++----- 1 file changed, 74 insertions(+), 25 deletions(-) diff --git a/test/components/views/rooms/SendMessageComposer-test.tsx b/test/components/views/rooms/SendMessageComposer-test.tsx index 1c287bd9cbb1..2d5e14beab8a 100644 --- a/test/components/views/rooms/SendMessageComposer-test.tsx +++ b/test/components/views/rooms/SendMessageComposer-test.tsx @@ -26,7 +26,7 @@ import SendMessageComposer, { isQuickReaction, } from "../../../../src/components/views/rooms/SendMessageComposer"; import MatrixClientContext from "../../../../src/contexts/MatrixClientContext"; -import RoomContext from "../../../../src/contexts/RoomContext"; +import RoomContext, { TimelineRenderingType } from "../../../../src/contexts/RoomContext"; import EditorModel from "../../../../src/editor/model"; import { createPartCreator, createRenderer } from "../../../editor/mock"; import { createTestClient, mkEvent, mkStubRoom } from "../../../test-utils"; @@ -34,18 +34,58 @@ import BasicMessageComposer from "../../../../src/components/views/rooms/BasicMe import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; import SpecPermalinkConstructor from "../../../../src/utils/permalinks/SpecPermalinkConstructor"; import defaultDispatcher from "../../../../src/dispatcher/dispatcher"; +import DocumentOffset from '../../../../src/editor/offset'; +import { Layout } from '../../../../src/settings/Layout'; jest.mock("../../../../src/stores/RoomViewStore"); configure({ adapter: new Adapter() }); describe('', () => { + const roomContext = { + roomLoading: true, + peekLoading: false, + shouldPeek: true, + membersLoaded: false, + numUnreadMessages: 0, + draggingFile: false, + searching: false, + guestsCanJoin: false, + canPeek: false, + showApps: false, + isPeeking: false, + showRightPanel: true, + joining: false, + atEndOfLiveTimeline: true, + atEndOfLiveTimelineInit: false, + showTopUnreadMessagesBar: false, + statusBarVisible: false, + canReact: false, + canReply: false, + layout: Layout.Group, + lowBandwidth: false, + alwaysShowTimestamps: false, + showTwelveHourTimestamps: false, + readMarkerInViewThresholdMs: 3000, + readMarkerOutOfViewThresholdMs: 30000, + showHiddenEventsInTimeline: false, + showReadReceipts: true, + showRedactions: true, + showJoinLeaves: true, + showAvatarChanges: true, + showDisplaynameChanges: true, + matrixClientIsReady: false, + dragCounter: 0, + timelineRenderingType: TimelineRenderingType.Room, + liveTimeline: undefined, + }; describe("createMessageContent", () => { - const permalinkCreator = jest.fn(); + const permalinkCreator = jest.fn() as any; it("sends plaintext messages correctly", () => { const model = new EditorModel([], createPartCreator(), createRenderer()); - model.update("hello world", "insertText", { offset: 11, atNodeEnd: true }); + const documentOffset = new DocumentOffset(11, true); + model.update("hello world", "insertText", documentOffset); const content = createMessageContent(model, null, false, permalinkCreator); @@ -57,7 +97,8 @@ describe('', () => { it("sends markdown messages correctly", () => { const model = new EditorModel([], createPartCreator(), createRenderer()); - model.update("hello *world*", "insertText", { offset: 13, atNodeEnd: true }); + const documentOffset = new DocumentOffset(13, true); + model.update("hello *world*", "insertText", documentOffset); const content = createMessageContent(model, null, false, permalinkCreator); @@ -71,7 +112,8 @@ describe('', () => { it("strips /me from messages and marks them as m.emote accordingly", () => { const model = new EditorModel([], createPartCreator(), createRenderer()); - model.update("/me blinks __quickly__", "insertText", { offset: 22, atNodeEnd: true }); + const documentOffset = new DocumentOffset(22, true); + model.update("/me blinks __quickly__", "insertText", documentOffset); const content = createMessageContent(model, null, false, permalinkCreator); @@ -85,7 +127,9 @@ describe('', () => { it("allows sending double-slash escaped slash commands correctly", () => { const model = new EditorModel([], createPartCreator(), createRenderer()); - model.update("//dev/null is my favourite place", "insertText", { offset: 32, atNodeEnd: true }); + const documentOffset = new DocumentOffset(32, true); + + model.update("//dev/null is my favourite place", "insertText", documentOffset); const content = createMessageContent(model, null, false, permalinkCreator); @@ -98,9 +142,11 @@ describe('', () => { describe("functions correctly mounted", () => { const mockClient = MatrixClientPeg.matrixClient = createTestClient(); - const mockRoom = mkStubRoom(); + const mockRoom = mkStubRoom() as any; const mockEvent = mkEvent({ type: "m.room.message", + room: 'myfakeroom', + user: 'myfakeuser', content: "Replying to this", event: true, }); @@ -117,11 +163,11 @@ describe('', () => { it("renders text and placeholder correctly", () => { const wrapper = mount( - + ); @@ -138,11 +184,12 @@ describe('', () => { it("correctly persists state to and from localStorage", () => { const wrapper = mount( - + + @@ -182,11 +229,12 @@ describe('', () => { it("persists state correctly without replyToEvent onbeforeunload", () => { const wrapper = mount( - + + ); @@ -210,11 +258,12 @@ describe('', () => { it("persists to session history upon sending", async () => { const wrapper = mount( - + + @@ -244,7 +293,7 @@ describe('', () => { describe("isQuickReaction", () => { it("correctly detects quick reaction", () => { const model = new EditorModel([], createPartCreator(), createRenderer()); - model.update("+😊", "insertText", { offset: 3, atNodeEnd: true }); + model.update("+😊", "insertText", new DocumentOffset(3, true)); const isReaction = isQuickReaction(model); @@ -253,7 +302,7 @@ describe('', () => { it("correctly detects quick reaction with space", () => { const model = new EditorModel([], createPartCreator(), createRenderer()); - model.update("+ 😊", "insertText", { offset: 4, atNodeEnd: true }); + model.update("+ 😊", "insertText", new DocumentOffset(4, true)); const isReaction = isQuickReaction(model); @@ -265,10 +314,10 @@ describe('', () => { const model2 = new EditorModel([], createPartCreator(), createRenderer()); const model3 = new EditorModel([], createPartCreator(), createRenderer()); const model4 = new EditorModel([], createPartCreator(), createRenderer()); - model.update("+😊hello", "insertText", { offset: 8, atNodeEnd: true }); - model2.update(" +😊", "insertText", { offset: 4, atNodeEnd: true }); - model3.update("+ 😊😊", "insertText", { offset: 6, atNodeEnd: true }); - model4.update("+smiley", "insertText", { offset: 7, atNodeEnd: true }); + model.update("+😊hello", "insertText", new DocumentOffset( 8, true)); + model2.update(" +😊", "insertText", new DocumentOffset( 4, true)); + model3.update("+ 😊😊", "insertText", new DocumentOffset( 6, true)); + model4.update("+smiley", "insertText", new DocumentOffset( 7, true)); expect(isQuickReaction(model)).toBeFalsy(); expect(isQuickReaction(model2)).toBeFalsy();