11/*
2- Copyright 2024 New Vector Ltd.
2+ Copyright 2024, 2025 New Vector Ltd.
33Copyright 2022 The Matrix.org Foundation C.I.C.
44
55SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
@@ -17,6 +17,8 @@ import DMRoomMap from "../../../../../src/utils/DMRoomMap";
1717import { LocalRoom } from "../../../../../src/models/LocalRoom" ;
1818import * as AvatarModule from "../../../../../src/Avatar" ;
1919import { DirectoryMember } from "../../../../../src/utils/direct-messages" ;
20+ import SettingsStore from "../../../../../src/settings/SettingsStore" ;
21+ import { SettingLevel } from "../../../../../src/settings/SettingLevel" ;
2022
2123describe ( "RoomAvatar" , ( ) => {
2224 let client : MatrixClient ;
@@ -41,6 +43,12 @@ describe("RoomAvatar", () => {
4143 afterEach ( ( ) => {
4244 mocked ( DMRoomMap . shared ( ) . getUserIdForRoomId ) . mockReset ( ) ;
4345 mocked ( AvatarModule . defaultAvatarUrlForString ) . mockClear ( ) ;
46+ SettingsStore . setValue (
47+ "showAvatarsOnInvites" ,
48+ null ,
49+ SettingLevel . ACCOUNT ,
50+ SettingsStore . getDefaultValue ( "showAvatarsOnInvites" ) ,
51+ ) ;
4452 } ) ;
4553
4654 it ( "should render as expected for a Room" , ( ) => {
@@ -64,4 +72,19 @@ describe("RoomAvatar", () => {
6472 localRoom . targets . push ( new DirectoryMember ( { user_id : userId } ) ) ;
6573 expect ( render ( < RoomAvatar room = { localRoom } /> ) . container ) . toMatchSnapshot ( ) ;
6674 } ) ;
75+ it ( "should render an avatar for a room the user is invited to" , ( ) => {
76+ SettingsStore . setValue ( "showAvatarsOnInvites" , null , SettingLevel . ACCOUNT , true ) ;
77+ const room = new Room ( "!room:example.com" , client , client . getSafeUserId ( ) ) ;
78+ jest . spyOn ( room , "getMxcAvatarUrl" ) . mockImplementation ( ( ) => "mxc://example.com/foobar" ) ;
79+ room . name = "test room" ;
80+ room . updateMyMembership ( "invite" ) ;
81+ expect ( render ( < RoomAvatar room = { room } /> ) . container ) . toMatchSnapshot ( ) ;
82+ } ) ;
83+ it ( "should not render an invite avatar if the user has disabled it" , ( ) => {
84+ SettingsStore . setValue ( "showAvatarsOnInvites" , null , SettingLevel . ACCOUNT , false ) ;
85+ const room = new Room ( "!room:example.com" , client , client . getSafeUserId ( ) ) ;
86+ room . name = "test room" ;
87+ room . updateMyMembership ( "invite" ) ;
88+ expect ( render ( < RoomAvatar room = { room } /> ) . container ) . toMatchSnapshot ( ) ;
89+ } ) ;
6790} ) ;
0 commit comments