From 5b7a91ef18a2d65ee4d83cd921ae2e4559200060 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 9 Mar 2023 13:53:34 +0000 Subject: [PATCH] Support dynamic room predecessors in SpaceHierarchy --- src/components/structures/SpaceHierarchy.tsx | 7 ++++- .../structures/SpaceHierarchy-test.tsx | 30 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/components/structures/SpaceHierarchy.tsx b/src/components/structures/SpaceHierarchy.tsx index 45f20b5ae5a..a0558413dde 100644 --- a/src/components/structures/SpaceHierarchy.tsx +++ b/src/components/structures/SpaceHierarchy.tsx @@ -67,6 +67,7 @@ import { Alignment } from "../views/elements/Tooltip"; import { getTopic } from "../../hooks/room/useTopic"; import { SdkContextClass } from "../../contexts/SDKContext"; import { getDisplayAliasForAliasSet } from "../../Rooms"; +import SettingsStore from "../../settings/SettingsStore"; interface IProps { space: Room; @@ -425,7 +426,11 @@ interface IHierarchyLevelProps { } export const toLocalRoom = (cli: MatrixClient, room: IHierarchyRoom, hierarchy: RoomHierarchy): IHierarchyRoom => { - const history = cli.getRoomUpgradeHistory(room.room_id, true); + const history = cli.getRoomUpgradeHistory( + room.room_id, + true, + SettingsStore.getValue("feature_dynamic_room_predecessors"), + ); // Pick latest room that is actually part of the hierarchy let cliRoom = null; diff --git a/test/components/structures/SpaceHierarchy-test.tsx b/test/components/structures/SpaceHierarchy-test.tsx index 2c5cb0e85a1..5f248140c89 100644 --- a/test/components/structures/SpaceHierarchy-test.tsx +++ b/test/components/structures/SpaceHierarchy-test.tsx @@ -15,6 +15,7 @@ limitations under the License. */ import React from "react"; +import { mocked } from "jest-mock"; import { render } from "@testing-library/react"; import { MatrixClient } from "matrix-js-sdk/src/client"; import { Room } from "matrix-js-sdk/src/models/room"; @@ -28,6 +29,7 @@ import { HierarchyLevel, showRoom, toLocalRoom } from "../../../src/components/s import { Action } from "../../../src/dispatcher/actions"; import MatrixClientContext from "../../../src/contexts/MatrixClientContext"; import DMRoomMap from "../../../src/utils/DMRoomMap"; +import SettingsStore from "../../../src/settings/SettingsStore"; // Fake random strings to give a predictable snapshot for checkbox IDs jest.mock("matrix-js-sdk/src/randomstring", () => { @@ -128,6 +130,34 @@ describe("SpaceHierarchy", () => { const localRoomV3 = toLocalRoom(client, { room_id: roomV3.roomId } as IHierarchyRoom, hierarchy); expect(localRoomV3.room_id).toEqual(roomV3.roomId); }); + + describe("If the feature_dynamic_room_predecessors is not enabled", () => { + beforeEach(() => { + jest.spyOn(SettingsStore, "getValue").mockReturnValue(false); + }); + it("Passes through the dynamic predecessor setting", async () => { + mocked(client.getRoomUpgradeHistory).mockClear(); + const hierarchy = { roomMap: new Map([]) } as RoomHierarchy; + toLocalRoom(client, { room_id: roomV1.roomId } as IHierarchyRoom, hierarchy); + expect(client.getRoomUpgradeHistory).toHaveBeenCalledWith(roomV1.roomId, true, false); + }); + }); + + describe("If the feature_dynamic_room_predecessors is enabled", () => { + beforeEach(() => { + // Turn on feature_dynamic_room_predecessors setting + jest.spyOn(SettingsStore, "getValue").mockImplementation( + (settingName) => settingName === "feature_dynamic_room_predecessors", + ); + }); + + it("Passes through the dynamic predecessor setting", async () => { + mocked(client.getRoomUpgradeHistory).mockClear(); + const hierarchy = { roomMap: new Map([]) } as RoomHierarchy; + toLocalRoom(client, { room_id: roomV1.roomId } as IHierarchyRoom, hierarchy); + expect(client.getRoomUpgradeHistory).toHaveBeenCalledWith(roomV1.roomId, true, true); + }); + }); }); describe("", () => {