Add tests
This commit is contained in:
parent
0d0d7a3e2c
commit
7788d50b02
2 changed files with 47 additions and 3 deletions
|
@ -413,7 +413,7 @@ interface IHierarchyLevelProps {
|
|||
onToggleClick?(parentId: string, childId: string): void;
|
||||
}
|
||||
|
||||
const toLocalRoom = (cli: MatrixClient, room: IHierarchyRoom, hierarchy: RoomHierarchy): IHierarchyRoom => {
|
||||
export const toLocalRoom = (cli: MatrixClient, room: IHierarchyRoom, hierarchy: RoomHierarchy): IHierarchyRoom => {
|
||||
const history = cli.getRoomUpgradeHistory(room.room_id, true);
|
||||
|
||||
// Pick latest room that is actually part of the hierarchy
|
||||
|
|
|
@ -17,11 +17,12 @@ limitations under the License.
|
|||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy";
|
||||
import { IHierarchyRoom } from "matrix-js-sdk/src/@types/spaces";
|
||||
|
||||
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
|
||||
import { stubClient } from "../../test-utils";
|
||||
import { mkStubRoom, stubClient } from "../../test-utils";
|
||||
import dispatcher from "../../../src/dispatcher/dispatcher";
|
||||
import { showRoom } from "../../../src/components/structures/SpaceHierarchy";
|
||||
import { showRoom, toLocalRoom } from "../../../src/components/structures/SpaceHierarchy";
|
||||
import { Action } from "../../../src/dispatcher/actions";
|
||||
|
||||
describe("SpaceHierarchy", () => {
|
||||
|
@ -67,4 +68,47 @@ describe("SpaceHierarchy", () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("toLocalRoom", () => {
|
||||
let client: MatrixClient;
|
||||
let roomV1: Room;
|
||||
let roomV2: Room;
|
||||
let roomV3: Room;
|
||||
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
client = MatrixClientPeg.get();
|
||||
roomV1 = mkStubRoom("room-id-1", "Room V1", client);
|
||||
roomV2 = mkStubRoom("room-id-2", "Room V2", client);
|
||||
roomV3 = mkStubRoom("room-id-3", "Room V3", client);
|
||||
jest.spyOn(client, "getRoomUpgradeHistory").mockReturnValue([roomV1, roomV2, roomV3]);
|
||||
});
|
||||
|
||||
it("grabs last room that is in hierarchy when latest version is in hierarchy", () => {
|
||||
const hierarchy = { roomMap: new Map([
|
||||
[roomV1.roomId, { room_id: roomV1.roomId } as IHierarchyRoom],
|
||||
[roomV2.roomId, { room_id: roomV2.roomId } as IHierarchyRoom],
|
||||
[roomV3.roomId, { room_id: roomV3.roomId } as IHierarchyRoom],
|
||||
]) } as RoomHierarchy;
|
||||
const localRoomV1 = toLocalRoom(client, { room_id: roomV1.roomId } as IHierarchyRoom, hierarchy);
|
||||
expect(localRoomV1.room_id).toEqual(roomV3.roomId);
|
||||
const localRoomV2 = toLocalRoom(client, { room_id: roomV2.roomId } as IHierarchyRoom, hierarchy);
|
||||
expect(localRoomV2.room_id).toEqual(roomV3.roomId);
|
||||
const localRoomV3 = toLocalRoom(client, { room_id: roomV3.roomId } as IHierarchyRoom, hierarchy);
|
||||
expect(localRoomV3.room_id).toEqual(roomV3.roomId);
|
||||
});
|
||||
|
||||
it("grabs last room that is in hierarchy when latest version is *not* in hierarchy", () => {
|
||||
const hierarchy = { roomMap: new Map([
|
||||
[roomV1.roomId, { room_id: roomV1.roomId } as IHierarchyRoom],
|
||||
[roomV2.roomId, { room_id: roomV2.roomId } as IHierarchyRoom]
|
||||
]) } as RoomHierarchy;
|
||||
const localRoomV1 = toLocalRoom(client, { room_id: roomV1.roomId } as IHierarchyRoom, hierarchy);
|
||||
expect(localRoomV1.room_id).toEqual(roomV2.roomId);
|
||||
const localRoomV2 = toLocalRoom(client, { room_id: roomV2.roomId } as IHierarchyRoom, hierarchy);
|
||||
expect(localRoomV2.room_id).toEqual(roomV2.roomId);
|
||||
const localRoomV3 = toLocalRoom(client, { room_id: roomV3.roomId } as IHierarchyRoom, hierarchy);
|
||||
expect(localRoomV3.room_id).toEqual(roomV2.roomId);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue