@@ -22,9 +22,14 @@ import { createTestClient, mkEvent, mkStubRoom } from "../../../../test-utils";
22
22
import defaultDispatcher from "../../../../../src/dispatcher/dispatcher" ;
23
23
import SettingsStore from "../../../../../src/settings/SettingsStore" ;
24
24
import { SettingLevel } from "../../../../../src/settings/SettingLevel" ;
25
+ import { RoomPermalinkCreator } from "../../../../../src/utils/permalinks/Permalinks" ;
25
26
26
27
describe ( 'message' , ( ) => {
27
- const permalinkCreator = jest . fn ( ) as any ;
28
+ const permalinkCreator = {
29
+ forEvent ( eventId : string ) : string {
30
+ return "$$permalink$$" ;
31
+ } ,
32
+ } as RoomPermalinkCreator ;
28
33
const message = '<i><b>hello</b> world</i>' ;
29
34
const mockEvent = mkEvent ( {
30
35
type : "m.room.message" ,
@@ -45,10 +50,51 @@ describe('message', () => {
45
50
46
51
// Then
47
52
expect ( content ) . toEqual ( {
48
- body : message ,
49
- format : "org.matrix.custom.html" ,
50
- formatted_body : message ,
51
- msgtype : "m.text" ,
53
+ "body" : message ,
54
+ "format" : "org.matrix.custom.html" ,
55
+ "formatted_body" : message ,
56
+ "msgtype" : "m.text" ,
57
+ } ) ;
58
+ } ) ;
59
+
60
+ it ( 'Should add reply to message content' , ( ) => {
61
+ // When
62
+ const content = createMessageContent ( message , { permalinkCreator, replyToEvent : mockEvent } ) ;
63
+
64
+ // Then
65
+ expect ( content ) . toEqual ( {
66
+ "body" : "> <myfakeuser> Replying to this\n\n<i><b>hello</b> world</i>" ,
67
+ "format" : "org.matrix.custom.html" ,
68
+ "formatted_body" : "<mx-reply><blockquote><a href=\"$$permalink$$\">In reply to</a>" +
69
+ " <a href=\"https://matrix.to/#/myfakeuser\">myfakeuser</a>" +
70
+ "<br>Replying to this</blockquote></mx-reply><i><b>hello</b> world</i>" ,
71
+ "msgtype" : "m.text" ,
72
+ "m.relates_to" : {
73
+ "m.in_reply_to" : {
74
+ "event_id" : mockEvent . getId ( ) ,
75
+ } ,
76
+ } ,
77
+ } ) ;
78
+ } ) ;
79
+
80
+ it ( "Should add relation to message" , ( ) => {
81
+ // When
82
+ const relation = {
83
+ rel_type : "m.thread" ,
84
+ event_id : "myFakeThreadId" ,
85
+ } ;
86
+ const content = createMessageContent ( message , { permalinkCreator, relation } ) ;
87
+
88
+ // Then
89
+ expect ( content ) . toEqual ( {
90
+ "body" : message ,
91
+ "format" : "org.matrix.custom.html" ,
92
+ "formatted_body" : message ,
93
+ "msgtype" : "m.text" ,
94
+ "m.relates_to" : {
95
+ "event_id" : "myFakeThreadId" ,
96
+ "rel_type" : "m.thread" ,
97
+ } ,
52
98
} ) ;
53
99
} ) ;
54
100
} ) ;
@@ -102,6 +148,15 @@ describe('message', () => {
102
148
const spyDispatcher = jest . spyOn ( defaultDispatcher , "dispatch" ) ;
103
149
104
150
it ( 'Should not send empty html message' , async ( ) => {
151
+ // When
152
+ await sendMessage ( '' , { roomContext : defaultRoomContext , mxClient : mockClient , permalinkCreator } ) ;
153
+
154
+ // Then
155
+ expect ( mockClient . sendMessage ) . toBeCalledTimes ( 0 ) ;
156
+ expect ( spyDispatcher ) . toBeCalledTimes ( 0 ) ;
157
+ } ) ;
158
+
159
+ it ( 'Should send html message' , async ( ) => {
105
160
// When
106
161
await sendMessage ( message , { roomContext : defaultRoomContext , mxClient : mockClient , permalinkCreator } ) ;
107
162
@@ -116,13 +171,44 @@ describe('message', () => {
116
171
expect ( spyDispatcher ) . toBeCalledWith ( { action : 'message_sent' } ) ;
117
172
} ) ;
118
173
119
- it ( 'Should send html message' , async ( ) => {
174
+ it ( 'Should send reply to html message' , async ( ) => {
175
+ const mockReplyEvent = mkEvent ( {
176
+ type : "m.room.message" ,
177
+ room : 'myfakeroom' ,
178
+ user : 'myfakeuser2' ,
179
+ content : { "msgtype" : "m.text" , "body" : "My reply" } ,
180
+ event : true ,
181
+ } ) ;
182
+
120
183
// When
121
- await sendMessage ( '' , { roomContext : defaultRoomContext , mxClient : mockClient , permalinkCreator } ) ;
184
+ await sendMessage ( message , {
185
+ roomContext : defaultRoomContext ,
186
+ mxClient : mockClient ,
187
+ permalinkCreator,
188
+ replyToEvent : mockReplyEvent ,
189
+ } ) ;
122
190
123
191
// Then
124
- expect ( mockClient . sendMessage ) . toBeCalledTimes ( 0 ) ;
125
- expect ( spyDispatcher ) . toBeCalledTimes ( 0 ) ;
192
+ expect ( spyDispatcher ) . toBeCalledWith ( {
193
+ action : 'reply_to_event' ,
194
+ event : null ,
195
+ context : defaultRoomContext . timelineRenderingType ,
196
+ } ) ;
197
+
198
+ const expectedContent = {
199
+ "body" : "> <myfakeuser2> My reply\n\n<i><b>hello</b> world</i>" ,
200
+ "format" : "org.matrix.custom.html" ,
201
+ "formatted_body" : "<mx-reply><blockquote><a href=\"$$permalink$$\">In reply to</a>" +
202
+ " <a href=\"https://matrix.to/#/myfakeuser2\">myfakeuser2</a>" +
203
+ "<br>My reply</blockquote></mx-reply><i><b>hello</b> world</i>" ,
204
+ "msgtype" : "m.text" ,
205
+ "m.relates_to" : {
206
+ "m.in_reply_to" : {
207
+ "event_id" : mockReplyEvent . getId ( ) ,
208
+ } ,
209
+ } ,
210
+ } ;
211
+ expect ( mockClient . sendMessage ) . toBeCalledWith ( 'myfakeroom' , null , expectedContent ) ;
126
212
} ) ;
127
213
128
214
it ( 'Should scroll to bottom after sending a html message' , async ( ) => {
0 commit comments