@@ -33,7 +33,7 @@ import { ReceiptType } from "../../src/@types/read_receipts";
3333import * as testUtils from "../test-utils/test-utils" ;
3434import { makeBeaconInfoContent } from "../../src/content-helpers" ;
3535import { M_BEACON_INFO } from "../../src/@types/beacon" ;
36- import { Room } from "../../src" ;
36+ import { ContentHelpers , Room } from "../../src" ;
3737import { makeBeaconEvent } from "../test-utils/beacon" ;
3838
3939jest . useFakeTimers ( ) ;
@@ -1104,6 +1104,41 @@ describe("MatrixClient", function() {
11041104 } ) ;
11051105 } ) ;
11061106
1107+ describe ( "setRoomTopic" , ( ) => {
1108+ const roomId = "!foofoofoofoofoofoo:matrix.org" ;
1109+ const createSendStateEventMock = ( topic : string , htmlTopic ?: string ) => {
1110+ return jest . fn ( )
1111+ . mockImplementation ( ( roomId : string , eventType : string , content : any , stateKey : string ) => {
1112+ expect ( roomId ) . toEqual ( roomId ) ;
1113+ expect ( eventType ) . toEqual ( EventType . RoomTopic ) ;
1114+ expect ( content ) . toMatchObject ( ContentHelpers . makeTopicContent ( topic , htmlTopic ) ) ;
1115+ expect ( stateKey ) . toBeUndefined ( ) ;
1116+ return Promise . resolve ( ) ;
1117+ } ) ;
1118+ } ;
1119+
1120+ it ( "is called with plain text topic and sends state event" , async ( ) => {
1121+ const sendStateEvent = createSendStateEventMock ( "pizza" ) ;
1122+ client . sendStateEvent = sendStateEvent ;
1123+ await client . setRoomTopic ( roomId , "pizza" ) ;
1124+ expect ( sendStateEvent ) . toHaveBeenCalledTimes ( 1 ) ;
1125+ } ) ;
1126+
1127+ it ( "is called with plain text topic and callback and sends state event" , async ( ) => {
1128+ const sendStateEvent = createSendStateEventMock ( "pizza" ) ;
1129+ client . sendStateEvent = sendStateEvent ;
1130+ await client . setRoomTopic ( roomId , "pizza" , ( ) => { } ) ;
1131+ expect ( sendStateEvent ) . toHaveBeenCalledTimes ( 1 ) ;
1132+ } ) ;
1133+
1134+ it ( "is called with plain text and HTML topic and sends state event" , async ( ) => {
1135+ const sendStateEvent = createSendStateEventMock ( "pizza" , "<b>pizza</b>" ) ;
1136+ client . sendStateEvent = sendStateEvent ;
1137+ await client . setRoomTopic ( roomId , "pizza" , "<b>pizza</b>" ) ;
1138+ expect ( sendStateEvent ) . toHaveBeenCalledTimes ( 1 ) ;
1139+ } ) ;
1140+ } ) ;
1141+
11071142 describe ( "setPassword" , ( ) => {
11081143 const auth = { session : 'abcdef' , type : 'foo' } ;
11091144 const newPassword = 'newpassword' ;
0 commit comments