@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- import { EventType , MatrixEvent } from "matrix-js-sdk/src/matrix" ;
17+ import { EventType , MatrixEvent , RoomMember } from "matrix-js-sdk/src/matrix" ;
1818import TestRenderer from 'react-test-renderer' ;
1919import { ReactElement } from "react" ;
2020
@@ -174,14 +174,17 @@ describe('TextForEvent', () => {
174174 const userA = {
175175 id : '@a' ,
176176 name : 'Alice' ,
177+ rawDisplayName : 'Alice' ,
177178 } ;
178179 const userB = {
179180 id : '@b' ,
180- name : 'Bob' ,
181+ name : 'Bob (@b)' ,
182+ rawDisplayName : 'Bob' ,
181183 } ;
182184 const userC = {
183185 id : '@c' ,
184- name : 'Carl' ,
186+ name : 'Bob (@c)' ,
187+ rawDisplayName : 'Bob' ,
185188 } ;
186189 interface PowerEventProps {
187190 usersDefault ?: number ;
@@ -191,19 +194,23 @@ describe('TextForEvent', () => {
191194 }
192195 const mockPowerEvent = ( {
193196 usersDefault, prevDefault, users, prevUsers,
194- } : PowerEventProps ) : MatrixEvent => new MatrixEvent ( {
195- type : EventType . RoomPowerLevels ,
196- sender : userA . id ,
197- state_key : "" ,
198- content : {
199- users_default : usersDefault ,
200- users,
201- } ,
202- prev_content : {
203- users : prevUsers ,
204- users_default : prevDefault ,
205- } ,
206- } ) ;
197+ } : PowerEventProps ) : MatrixEvent => {
198+ const mxEvent = new MatrixEvent ( {
199+ type : EventType . RoomPowerLevels ,
200+ sender : userA . id ,
201+ state_key : "" ,
202+ content : {
203+ users_default : usersDefault ,
204+ users,
205+ } ,
206+ prev_content : {
207+ users : prevUsers ,
208+ users_default : prevDefault ,
209+ } ,
210+ } ) ;
211+ mxEvent . sender = { name : userA . name } as RoomMember ;
212+ return mxEvent ;
213+ } ;
207214
208215 beforeAll ( ( ) => {
209216 mockClient = createTestClient ( ) ;
@@ -256,7 +263,7 @@ describe('TextForEvent', () => {
256263 [ userB . id ] : 50 ,
257264 } ,
258265 } ) ;
259- const expectedText = "@a changed the power level of @b from Moderator to Admin." ;
266+ const expectedText = "Alice changed the power level of Bob (@b) from Moderator to Admin." ;
260267 expect ( textForEvent ( event ) ) . toEqual ( expectedText ) ;
261268 } ) ;
262269
@@ -271,7 +278,7 @@ describe('TextForEvent', () => {
271278 [ userB . id ] : 50 ,
272279 } ,
273280 } ) ;
274- const expectedText = "@a changed the power level of @b from Moderator to Default." ;
281+ const expectedText = "Alice changed the power level of Bob (@b) from Moderator to Default." ;
275282 expect ( textForEvent ( event ) ) . toEqual ( expectedText ) ;
276283 } ) ;
277284
@@ -284,7 +291,7 @@ describe('TextForEvent', () => {
284291 [ userB . id ] : 50 ,
285292 } ,
286293 } ) ;
287- const expectedText = "@a changed the power level of @b from Moderator to Custom (-1)." ;
294+ const expectedText = "Alice changed the power level of Bob (@b) from Moderator to Custom (-1)." ;
288295 expect ( textForEvent ( event ) ) . toEqual ( expectedText ) ;
289296 } ) ;
290297
@@ -299,27 +306,9 @@ describe('TextForEvent', () => {
299306 [ userC . id ] : 101 ,
300307 } ,
301308 } ) ;
302- const expectedText =
303- "@a changed the power level of @b from Moderator to Admin, @c from Custom (101) to Moderator." ;
304- expect ( textForEvent ( event ) ) . toEqual ( expectedText ) ;
305- } ) ;
306-
307- it ( "uses userIdentifier customisation" , ( ) => {
308- ( UserIdentifierCustomisations . getDisplayUserIdentifier as jest . Mock )
309- . mockImplementation ( userId => 'customised ' + userId ) ;
310- const event = mockPowerEvent ( {
311- users : {
312- [ userB . id ] : 100 ,
313- } ,
314- prevUsers : {
315- [ userB . id ] : 50 ,
316- } ,
317- } ) ;
318- // uses customised user id
319- const expectedText = "@a changed the power level of customised @b from Moderator to Admin." ;
309+ const expectedText = "Alice changed the power level of Bob (@b) from Moderator to Admin,"
310+ + " Bob (@c) from Custom (101) to Moderator." ;
320311 expect ( textForEvent ( event ) ) . toEqual ( expectedText ) ;
321- expect ( UserIdentifierCustomisations . getDisplayUserIdentifier )
322- . toHaveBeenCalledWith ( userB . id , { roomId : event . getRoomId ( ) } ) ;
323312 } ) ;
324313 } ) ;
325314
0 commit comments