@@ -34,6 +34,10 @@ import { getRoomContext } from "../../../test-utils/room";
3434import { mkMessage , stubClient } from "../../../test-utils/test-utils" ;
3535import { mkThread } from "../../../test-utils/threads" ;
3636import { ScopedRoomContextProvider } from "../../../../src/contexts/ScopedRoomContext.tsx" ;
37+ import defaultDispatcher from "../../../../src/dispatcher/dispatcher" ;
38+ import { untilDispatch } from "../../../test-utils/utilities.ts" ;
39+ import { TimelineRenderingType } from "../../../../src/contexts/RoomContext.ts" ;
40+ import { ComposerInsertPayload , ComposerType } from "../../../../src/dispatcher/payloads/ComposerInsertPayload.ts" ;
3741
3842describe ( "ThreadView" , ( ) => {
3943 const ROOM_ID = "!roomId:example.org" ;
@@ -209,4 +213,87 @@ describe("ThreadView", () => {
209213 metricsTrigger : undefined ,
210214 } ) ;
211215 } ) ;
216+
217+ describe ( "handles Action.ComposerInsert" , ( ) => {
218+ it ( "redispatches a payload of timelineRenderingType=Thread" , async ( ) => {
219+ await getComponent ( ) ;
220+ const promise = untilDispatch ( ( payload ) => {
221+ try {
222+ expect ( payload ) . toEqual ( {
223+ action : Action . ComposerInsert ,
224+ text : "Hello world" ,
225+ timelineRenderingType : TimelineRenderingType . Thread ,
226+ composerType : ComposerType . Send ,
227+ } ) ;
228+ } catch {
229+ return false ;
230+ }
231+ return true ;
232+ } , defaultDispatcher ) ;
233+ defaultDispatcher . dispatch ( {
234+ action : Action . ComposerInsert ,
235+ text : "Hello world" ,
236+ timelineRenderingType : TimelineRenderingType . Thread ,
237+ } satisfies ComposerInsertPayload ) ;
238+ await promise ;
239+ } ) ;
240+ it ( "ignores payloads with a composerType" , async ( ) => {
241+ await getComponent ( ) ;
242+ const promise = untilDispatch (
243+ ( payload ) => {
244+ try {
245+ expect ( payload ) . toStrictEqual ( {
246+ action : Action . ComposerInsert ,
247+ text : "Hello world" ,
248+ timelineRenderingType : TimelineRenderingType . Thread ,
249+ composerType : ComposerType . Send ,
250+ } ) ;
251+ } catch {
252+ return false ;
253+ }
254+ return true ;
255+ } ,
256+ defaultDispatcher ,
257+ 500 ,
258+ ) ;
259+ defaultDispatcher . dispatch ( {
260+ action : Action . ComposerInsert ,
261+ text : "Hello world" ,
262+ composerType : ComposerType . Send ,
263+ timelineRenderingType : TimelineRenderingType . Thread ,
264+ // Ensure we don't accidentally pick up this emit by strictly checking above.
265+ viaTest : true ,
266+ } satisfies ComposerInsertPayload ) ;
267+ await expect ( promise ) . rejects . toThrow ( ) ;
268+ } ) ;
269+ it ( "ignores payloads with a timelineRenderingType != TimelineRenderingType.Thread" , async ( ) => {
270+ await getComponent ( ) ;
271+ const promise = untilDispatch (
272+ ( payload ) => {
273+ try {
274+ expect ( payload ) . toStrictEqual ( {
275+ action : Action . ComposerInsert ,
276+ text : "Hello world" ,
277+ timelineRenderingType : TimelineRenderingType . Thread ,
278+ composerType : ComposerType . Send ,
279+ } ) ;
280+ } catch {
281+ return false ;
282+ }
283+ return true ;
284+ } ,
285+ defaultDispatcher ,
286+ 500 ,
287+ ) ;
288+ defaultDispatcher . dispatch ( {
289+ action : Action . ComposerInsert ,
290+ text : "Hello world" ,
291+ composerType : ComposerType . Send ,
292+ timelineRenderingType : TimelineRenderingType . Room ,
293+ // Ensure we don't accidentally pick up this emit by strictly checking above.
294+ viaTest : true ,
295+ } satisfies ComposerInsertPayload ) ;
296+ await expect ( promise ) . rejects . toThrow ( ) ;
297+ } ) ;
298+ } ) ;
212299} ) ;
0 commit comments