Support dynamic room predecessors in SpaceHierarchy (#10341)

This commit is contained in:
Andy Balaam 2023-03-10 09:41:14 +00:00 committed by GitHub
parent b646250c90
commit 42abfb1fac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View file

@ -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;

View file

@ -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("<HierarchyLevel />", () => {