@@ -19,7 +19,7 @@ import { MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
19
19
import { MockedObject } from "jest-mock" ;
20
20
import { render } from "@testing-library/react" ;
21
21
22
- import { getMockClientWithEventEmitter , mkEvent , mkStubRoom } from "../../../test-utils" ;
22
+ import { getMockClientWithEventEmitter , mkEvent , mkMessage , mkStubRoom } from "../../../test-utils" ;
23
23
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg" ;
24
24
import * as languageHandler from "../../../../src/languageHandler" ;
25
25
import DMRoomMap from "../../../../src/utils/DMRoomMap" ;
@@ -28,6 +28,15 @@ import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
28
28
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks" ;
29
29
import { MediaEventHelper } from "../../../../src/utils/MediaEventHelper" ;
30
30
31
+ const mkRoomTextMessage = ( body : string ) : MatrixEvent => {
32
+ return mkMessage ( {
33
+ msg : body ,
34
+ room : "room_id" ,
35
+ user : "sender" ,
36
+ event : true ,
37
+ } ) ;
38
+ } ;
39
+
31
40
describe ( "<TextualBody />" , ( ) => {
32
41
afterEach ( ( ) => {
33
42
jest . spyOn ( MatrixClientPeg , "get" ) . mockRestore ( ) ;
@@ -38,9 +47,11 @@ describe("<TextualBody />", () => {
38
47
beforeEach ( ( ) => {
39
48
defaultMatrixClient = getMockClientWithEventEmitter ( {
40
49
getRoom : ( ) => defaultRoom ,
50
+ getRooms : ( ) => [ defaultRoom ] ,
41
51
getAccountData : ( ) : MatrixEvent | undefined => undefined ,
42
52
isGuest : ( ) => false ,
43
53
mxcUrlToHttp : ( s : string ) => s ,
54
+ getUserId : ( ) => "@user:example.com" ,
44
55
} ) ;
45
56
} ) ;
46
57
@@ -116,17 +127,7 @@ describe("<TextualBody />", () => {
116
127
} ) ;
117
128
118
129
it ( "simple message renders as expected" , ( ) => {
119
- const ev = mkEvent ( {
120
- type : "m.room.message" ,
121
- room : "room_id" ,
122
- user : "sender" ,
123
- content : {
124
- body : "this is a plaintext message" ,
125
- msgtype : "m.text" ,
126
- } ,
127
- event : true ,
128
- } ) ;
129
-
130
+ const ev = mkRoomTextMessage ( "this is a plaintext message" ) ;
130
131
const { container } = getComponent ( { mxEvent : ev } ) ;
131
132
expect ( container ) . toHaveTextContent ( ev . getContent ( ) . body ) ;
132
133
const content = container . querySelector ( ".mx_EventTile_body" ) ;
@@ -135,17 +136,7 @@ describe("<TextualBody />", () => {
135
136
136
137
// If pills were rendered within a Portal/same shadow DOM then it'd be easier to test
137
138
it ( "linkification get applied correctly into the DOM" , ( ) => {
138
- const ev = mkEvent ( {
139
- type : "m.room.message" ,
140
- room : "room_id" ,
141
- user : "sender" ,
142
- content : {
143
- body : "Visit https://matrix.org/" ,
144
- msgtype : "m.text" ,
145
- } ,
146
- event : true ,
147
- } ) ;
148
-
139
+ const ev = mkRoomTextMessage ( "Visit https://matrix.org/" ) ;
149
140
const { container } = getComponent ( { mxEvent : ev } ) ;
150
141
expect ( container ) . toHaveTextContent ( ev . getContent ( ) . body ) ;
151
142
const content = container . querySelector ( ".mx_EventTile_body" ) ;
@@ -155,6 +146,24 @@ describe("<TextualBody />", () => {
155
146
"https://matrix.org/</a></span>" ,
156
147
) ;
157
148
} ) ;
149
+
150
+ it ( "pillification of MXIDs get applied correctly into the DOM" , ( ) => {
151
+ const ev = mkRoomTextMessage ( "Chat with @user:example.com" ) ;
152
+ const { container } = getComponent ( { mxEvent : ev } ) ;
153
+ const content = container . querySelector ( ".mx_EventTile_body" ) ;
154
+ expect ( content . innerHTML ) . toMatchInlineSnapshot (
155
+ `"Chat with <span><bdi><a class="mx_Pill mx_UserPill"><img class="mx_BaseAvatar mx_BaseAvatar_image" src="mxc://avatar.url/image.png" style="width: 16px; height: 16px;" alt="" data-testid="avatar-img" aria-hidden="true"><span class="mx_Pill_linkText">Member</span></a></bdi></span>"` ,
156
+ ) ;
157
+ } ) ;
158
+
159
+ it ( "pillification of room aliases get applied correctly into the DOM" , ( ) => {
160
+ const ev = mkRoomTextMessage ( "Visit #room:example.com" ) ;
161
+ const { container } = getComponent ( { mxEvent : ev } ) ;
162
+ const content = container . querySelector ( ".mx_EventTile_body" ) ;
163
+ expect ( content . innerHTML ) . toMatchInlineSnapshot (
164
+ `"Visit <span><bdi><a class="mx_Pill mx_RoomPill" href="https://matrix.to/#/#room:example.com"><span class="mx_Pill_linkText">#room:example.com</span></a></bdi></span>"` ,
165
+ ) ;
166
+ } ) ;
158
167
} ) ;
159
168
160
169
describe ( "renders formatted m.text correctly" , ( ) => {
@@ -382,17 +391,7 @@ describe("<TextualBody />", () => {
382
391
} ) ;
383
392
DMRoomMap . makeShared ( ) ;
384
393
385
- const ev = mkEvent ( {
386
- type : "m.room.message" ,
387
- room : "room_id" ,
388
- user : "sender" ,
389
- content : {
390
- body : "Visit https://matrix.org/" ,
391
- msgtype : "m.text" ,
392
- } ,
393
- event : true ,
394
- } ) ;
395
-
394
+ const ev = mkRoomTextMessage ( "Visit https://matrix.org/" ) ;
396
395
const { container, rerender } = getComponent (
397
396
{ mxEvent : ev , showUrlPreview : true , onHeightChanged : jest . fn ( ) } ,
398
397
matrixClient ,
0 commit comments