11/*
2- Copyright 2022 The Matrix.org Foundation C.I.C.
2+ Copyright 2022-2023 The Matrix.org Foundation C.I.C.
33
44Licensed under the Apache License, Version 2.0 (the "License");
55you may not use this file except in compliance with the License.
@@ -29,6 +29,8 @@ import ThreadView from "../../../src/components/structures/ThreadView";
2929import MatrixClientContext from "../../../src/contexts/MatrixClientContext" ;
3030import RoomContext from "../../../src/contexts/RoomContext" ;
3131import { SdkContextClass } from "../../../src/contexts/SDKContext" ;
32+ import { Action } from "../../../src/dispatcher/actions" ;
33+ import dispatcher from "../../../src/dispatcher/dispatcher" ;
3234import { MatrixClientPeg } from "../../../src/MatrixClientPeg" ;
3335import DMRoomMap from "../../../src/utils/DMRoomMap" ;
3436import ResizeNotifier from "../../../src/utils/ResizeNotifier" ;
@@ -47,7 +49,7 @@ describe("ThreadView", () => {
4749
4850 let changeEvent : ( event : MatrixEvent ) => void ;
4951
50- function TestThreadView ( ) {
52+ function TestThreadView ( { initialEvent } : { initialEvent ?: MatrixEvent } ) {
5153 const [ event , setEvent ] = useState ( rootEvent ) ;
5254 changeEvent = setEvent ;
5355
@@ -58,15 +60,21 @@ describe("ThreadView", () => {
5860 canSendMessages : true ,
5961 } ) }
6062 >
61- < ThreadView room = { room } onClose = { jest . fn ( ) } mxEvent = { event } resizeNotifier = { new ResizeNotifier ( ) } />
63+ < ThreadView
64+ room = { room }
65+ onClose = { jest . fn ( ) }
66+ mxEvent = { event }
67+ initialEvent = { initialEvent }
68+ resizeNotifier = { new ResizeNotifier ( ) }
69+ />
6270 </ RoomContext . Provider >
6371 ,
6472 </ MatrixClientContext . Provider >
6573 ) ;
6674 }
6775
68- async function getComponent ( ) : Promise < RenderResult > {
69- const renderResult = render ( < TestThreadView /> ) ;
76+ async function getComponent ( initialEvent ?: MatrixEvent ) : Promise < RenderResult > {
77+ const renderResult = render ( < TestThreadView initialEvent = { initialEvent } /> ) ;
7078
7179 await waitFor ( ( ) => {
7280 expect ( ( ) => getByTestId ( renderResult . container , "spinner" ) ) . toThrow ( ) ;
@@ -171,4 +179,17 @@ describe("ThreadView", () => {
171179 unmount ( ) ;
172180 await waitFor ( ( ) => expect ( SdkContextClass . instance . roomViewStore . getThreadId ( ) ) . toBeNull ( ) ) ;
173181 } ) ;
182+
183+ it ( "clears highlight message in the room view store" , async ( ) => {
184+ jest . spyOn ( SdkContextClass . instance . roomViewStore , "getRoomId" ) . mockReturnValue ( room . roomId ) ;
185+ const mock = jest . spyOn ( dispatcher , "dispatch" ) ;
186+ const { unmount } = await getComponent ( rootEvent ) ;
187+ mock . mockClear ( ) ;
188+ unmount ( ) ;
189+ expect ( mock ) . toHaveBeenCalledWith ( {
190+ action : Action . ViewRoom ,
191+ room_id : room . roomId ,
192+ metricsTrigger : undefined ,
193+ } ) ;
194+ } ) ;
174195} ) ;
0 commit comments