@@ -15,6 +15,7 @@ limitations under the License.
1515*/
1616
1717import React from "react" ;
18+ import { mocked } from "jest-mock" ;
1819import { render } from "@testing-library/react" ;
1920import { MatrixClient } from "matrix-js-sdk/src/client" ;
2021import { Room } from "matrix-js-sdk/src/models/room" ;
@@ -28,6 +29,7 @@ import { HierarchyLevel, showRoom, toLocalRoom } from "../../../src/components/s
2829import { Action } from "../../../src/dispatcher/actions" ;
2930import MatrixClientContext from "../../../src/contexts/MatrixClientContext" ;
3031import DMRoomMap from "../../../src/utils/DMRoomMap" ;
32+ import SettingsStore from "../../../src/settings/SettingsStore" ;
3133
3234// Fake random strings to give a predictable snapshot for checkbox IDs
3335jest . mock ( "matrix-js-sdk/src/randomstring" , ( ) => {
@@ -128,6 +130,34 @@ describe("SpaceHierarchy", () => {
128130 const localRoomV3 = toLocalRoom ( client , { room_id : roomV3 . roomId } as IHierarchyRoom , hierarchy ) ;
129131 expect ( localRoomV3 . room_id ) . toEqual ( roomV3 . roomId ) ;
130132 } ) ;
133+
134+ describe ( "If the feature_dynamic_room_predecessors is not enabled" , ( ) => {
135+ beforeEach ( ( ) => {
136+ jest . spyOn ( SettingsStore , "getValue" ) . mockReturnValue ( false ) ;
137+ } ) ;
138+ it ( "Passes through the dynamic predecessor setting" , async ( ) => {
139+ mocked ( client . getRoomUpgradeHistory ) . mockClear ( ) ;
140+ const hierarchy = { roomMap : new Map ( [ ] ) } as RoomHierarchy ;
141+ toLocalRoom ( client , { room_id : roomV1 . roomId } as IHierarchyRoom , hierarchy ) ;
142+ expect ( client . getRoomUpgradeHistory ) . toHaveBeenCalledWith ( roomV1 . roomId , true , false ) ;
143+ } ) ;
144+ } ) ;
145+
146+ describe ( "If the feature_dynamic_room_predecessors is enabled" , ( ) => {
147+ beforeEach ( ( ) => {
148+ // Turn on feature_dynamic_room_predecessors setting
149+ jest . spyOn ( SettingsStore , "getValue" ) . mockImplementation (
150+ ( settingName ) => settingName === "feature_dynamic_room_predecessors" ,
151+ ) ;
152+ } ) ;
153+
154+ it ( "Passes through the dynamic predecessor setting" , async ( ) => {
155+ mocked ( client . getRoomUpgradeHistory ) . mockClear ( ) ;
156+ const hierarchy = { roomMap : new Map ( [ ] ) } as RoomHierarchy ;
157+ toLocalRoom ( client , { room_id : roomV1 . roomId } as IHierarchyRoom , hierarchy ) ;
158+ expect ( client . getRoomUpgradeHistory ) . toHaveBeenCalledWith ( roomV1 . roomId , true , true ) ;
159+ } ) ;
160+ } ) ;
131161 } ) ;
132162
133163 describe ( "<HierarchyLevel />" , ( ) => {
0 commit comments