Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit ff7d358

Browse files
committed
Support dynamic room predecessors in SpaceHierarchy
1 parent edd8865 commit ff7d358

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/components/structures/SpaceHierarchy.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import { Alignment } from "../views/elements/Tooltip";
6767
import { getTopic } from "../../hooks/room/useTopic";
6868
import { SdkContextClass } from "../../contexts/SDKContext";
6969
import { getDisplayAliasForAliasSet } from "../../Rooms";
70+
import SettingsStore from "../../settings/SettingsStore";
7071

7172
interface IProps {
7273
space: Room;
@@ -425,7 +426,11 @@ interface IHierarchyLevelProps {
425426
}
426427

427428
export const toLocalRoom = (cli: MatrixClient, room: IHierarchyRoom, hierarchy: RoomHierarchy): IHierarchyRoom => {
428-
const history = cli.getRoomUpgradeHistory(room.room_id, true);
429+
const history = cli.getRoomUpgradeHistory(
430+
room.room_id,
431+
true,
432+
SettingsStore.getValue("feature_dynamic_room_predecessors"),
433+
);
429434

430435
// Pick latest room that is actually part of the hierarchy
431436
let cliRoom = null;

test/components/structures/SpaceHierarchy-test.tsx

+30
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import { HierarchyLevel, showRoom, toLocalRoom } from "../../../src/components/s
2828
import { Action } from "../../../src/dispatcher/actions";
2929
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
3030
import DMRoomMap from "../../../src/utils/DMRoomMap";
31+
import { mocked } from "jest-mock";
32+
import SettingsStore from "../../../src/settings/SettingsStore";
3133

3234
// Fake random strings to give a predictable snapshot for checkbox IDs
3335
jest.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

Comments
 (0)