From e0e149be3de8364127f3dce6844bc3bc3686dbeb Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Fri, 27 Jan 2023 14:58:38 +0100 Subject: [PATCH 01/10] Ensure room is actually in space hierarchy when resolving its latest version Relates to: vector-im/element-web#24329 --- src/components/structures/SpaceHierarchy.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/structures/SpaceHierarchy.tsx b/src/components/structures/SpaceHierarchy.tsx index af6f298382..f99cf73f5f 100644 --- a/src/components/structures/SpaceHierarchy.tsx +++ b/src/components/structures/SpaceHierarchy.tsx @@ -413,9 +413,18 @@ interface IHierarchyLevelProps { onToggleClick?(parentId: string, childId: string): void; } -const toLocalRoom = (cli: MatrixClient, room: IHierarchyRoom): IHierarchyRoom => { +const toLocalRoom = (cli: MatrixClient, room: IHierarchyRoom, hierarchy: RoomHierarchy): IHierarchyRoom => { const history = cli.getRoomUpgradeHistory(room.room_id, true); - const cliRoom = history[history.length - 1]; + + // Pick latest room that is actually part of the hierarchy + let cliRoom = null; + for (let idx = history.length - 1; idx >= 0; --idx) { + if (hierarchy.roomMap[history[idx].roomId]) { + cliRoom = history[idx]; + break; + } + } + if (cliRoom) { return { ...room, @@ -461,7 +470,7 @@ export const HierarchyLevel: React.FC = ({ (result, ev: IHierarchyRelation) => { const room = hierarchy.roomMap.get(ev.state_key); if (room && roomSet.has(room)) { - result[room.room_type === RoomType.Space ? 0 : 1].push(toLocalRoom(cli, room)); + result[room.room_type === RoomType.Space ? 0 : 1].push(toLocalRoom(cli, room, hierarchy)); } return result; }, From c557162592a38e99bf907a48f89d87eda4ca7d93 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Fri, 27 Jan 2023 15:14:20 +0100 Subject: [PATCH 02/10] Try to appease the linter --- src/components/structures/SpaceHierarchy.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/structures/SpaceHierarchy.tsx b/src/components/structures/SpaceHierarchy.tsx index f99cf73f5f..84ec987337 100644 --- a/src/components/structures/SpaceHierarchy.tsx +++ b/src/components/structures/SpaceHierarchy.tsx @@ -419,7 +419,7 @@ const toLocalRoom = (cli: MatrixClient, room: IHierarchyRoom, hierarchy: RoomHie // Pick latest room that is actually part of the hierarchy let cliRoom = null; for (let idx = history.length - 1; idx >= 0; --idx) { - if (hierarchy.roomMap[history[idx].roomId]) { + if (hierarchy.roomMap.get(history[idx].roomId)) { cliRoom = history[idx]; break; } @@ -432,7 +432,7 @@ const toLocalRoom = (cli: MatrixClient, room: IHierarchyRoom, hierarchy: RoomHie room_type: cliRoom.getType(), name: cliRoom.name, topic: cliRoom.currentState.getStateEvents(EventType.RoomTopic, "")?.getContent().topic, - avatar_url: cliRoom.getMxcAvatarUrl(), + avatar_url: cliRoom.getMxcAvatarUrl() ?? undefined, canonical_alias: cliRoom.getCanonicalAlias(), aliases: cliRoom.getAltAliases(), world_readable: From 0d0d7a3e2cfe5793c60bb3f3b4e110ea66eec758 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Fri, 27 Jan 2023 15:25:10 +0100 Subject: [PATCH 03/10] Try to appease the linter --- src/components/structures/SpaceHierarchy.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/structures/SpaceHierarchy.tsx b/src/components/structures/SpaceHierarchy.tsx index 84ec987337..f358e37889 100644 --- a/src/components/structures/SpaceHierarchy.tsx +++ b/src/components/structures/SpaceHierarchy.tsx @@ -432,8 +432,8 @@ const toLocalRoom = (cli: MatrixClient, room: IHierarchyRoom, hierarchy: RoomHie room_type: cliRoom.getType(), name: cliRoom.name, topic: cliRoom.currentState.getStateEvents(EventType.RoomTopic, "")?.getContent().topic, - avatar_url: cliRoom.getMxcAvatarUrl() ?? undefined, - canonical_alias: cliRoom.getCanonicalAlias(), + avatar_url: cliRoom.getMxcAvatarUrl(), + canonical_alias: cliRoom.getCanonicalAlias() ?? undefined, aliases: cliRoom.getAltAliases(), world_readable: cliRoom.currentState.getStateEvents(EventType.RoomHistoryVisibility, "")?.getContent() From 7788d50b02456d34d12d5f94aed4db7b18cf225a Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Fri, 27 Jan 2023 20:20:01 +0100 Subject: [PATCH 04/10] Add tests --- src/components/structures/SpaceHierarchy.tsx | 2 +- .../structures/SpaceHierarchy-test.tsx | 48 ++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/components/structures/SpaceHierarchy.tsx b/src/components/structures/SpaceHierarchy.tsx index f358e37889..7d6888a197 100644 --- a/src/components/structures/SpaceHierarchy.tsx +++ b/src/components/structures/SpaceHierarchy.tsx @@ -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 diff --git a/test/components/structures/SpaceHierarchy-test.tsx b/test/components/structures/SpaceHierarchy-test.tsx index 9181802814..a2a63ae0b8 100644 --- a/test/components/structures/SpaceHierarchy-test.tsx +++ b/test/components/structures/SpaceHierarchy-test.tsx @@ -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); + }); + }); }); From 6f4581943b003c533303e41d746b9f4112cbc40c Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Fri, 27 Jan 2023 20:29:50 +0100 Subject: [PATCH 05/10] Prettify it --- .../structures/SpaceHierarchy-test.tsx | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/test/components/structures/SpaceHierarchy-test.tsx b/test/components/structures/SpaceHierarchy-test.tsx index a2a63ae0b8..796e8848d4 100644 --- a/test/components/structures/SpaceHierarchy-test.tsx +++ b/test/components/structures/SpaceHierarchy-test.tsx @@ -85,11 +85,13 @@ describe("SpaceHierarchy", () => { }); 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 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); @@ -99,10 +101,12 @@ describe("SpaceHierarchy", () => { }); 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 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); From d0de2a6851ff21d383ed18f054f8a32f37b06619 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Mon, 30 Jan 2023 09:53:41 +0100 Subject: [PATCH 06/10] Add test case for no-version-in-hierarchy situation --- test/components/structures/SpaceHierarchy-test.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/components/structures/SpaceHierarchy-test.tsx b/test/components/structures/SpaceHierarchy-test.tsx index 796e8848d4..27e55e95c1 100644 --- a/test/components/structures/SpaceHierarchy-test.tsx +++ b/test/components/structures/SpaceHierarchy-test.tsx @@ -114,5 +114,15 @@ describe("SpaceHierarchy", () => { const localRoomV3 = toLocalRoom(client, { room_id: roomV3.roomId } as IHierarchyRoom, hierarchy); expect(localRoomV3.room_id).toEqual(roomV2.roomId); }); + + it("returns specified room when none of the versions is in hierarchy", () => { + const hierarchy = { roomMap: new Map([]) } as RoomHierarchy; + const localRoomV1 = toLocalRoom(client, { room_id: roomV1.roomId } as IHierarchyRoom, hierarchy); + expect(localRoomV1.room_id).toEqual(roomV1.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(roomV3.roomId); + }); }); }); From c63daf62ede3761290d7361299fa0dea370229d8 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Wed, 1 Feb 2023 19:51:37 +0100 Subject: [PATCH 07/10] Add snapshot test --- .../structures/SpaceHierarchy-test.tsx | 86 +++++++++- .../SpaceHierarchy-test.tsx.snap | 159 ++++++++++++++++++ 2 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 test/components/structures/__snapshots__/SpaceHierarchy-test.tsx.snap diff --git a/test/components/structures/SpaceHierarchy-test.tsx b/test/components/structures/SpaceHierarchy-test.tsx index 27e55e95c1..3d29b77646 100644 --- a/test/components/structures/SpaceHierarchy-test.tsx +++ b/test/components/structures/SpaceHierarchy-test.tsx @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +import React from "react"; +import { render } from "@testing-library/react"; 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"; @@ -22,8 +24,17 @@ import { IHierarchyRoom } from "matrix-js-sdk/src/@types/spaces"; import { MatrixClientPeg } from "../../../src/MatrixClientPeg"; import { mkStubRoom, stubClient } from "../../test-utils"; import dispatcher from "../../../src/dispatcher/dispatcher"; -import { showRoom, toLocalRoom } from "../../../src/components/structures/SpaceHierarchy"; +import { HierarchyLevel, showRoom, toLocalRoom } from "../../../src/components/structures/SpaceHierarchy"; import { Action } from "../../../src/dispatcher/actions"; +import MatrixClientContext from "../../../src/contexts/MatrixClientContext"; +import DMRoomMap from "../../../src/utils/DMRoomMap"; + +// Fake random strings to give a predictable snapshot for checkbox IDs +jest.mock("matrix-js-sdk/src/randomstring", () => { + return { + randomString: () => "abdefghi", + }; +}); describe("SpaceHierarchy", () => { describe("showRoom", () => { @@ -125,4 +136,77 @@ describe("SpaceHierarchy", () => { expect(localRoomV3.room_id).toEqual(roomV3.roomId); }); }); + + describe("", () => { + let client: MatrixClient; + let dmRoomMap: DMRoomMap; + + let root: Room; + let room1: Room; + let room2: Room; + + let hierarchyRoot: IHierarchyRoom + let hierarchyRoom1: IHierarchyRoom + let hierarchyRoom2: IHierarchyRoom + + let roomHierarchy: RoomHierarchy; + + beforeEach(() => { + stubClient(); + client = MatrixClientPeg.get(); + + dmRoomMap = { + getUserIdForRoomId: jest.fn() + } as unknown as DMRoomMap; + jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap); + + root = mkStubRoom("room-id-1", "Room 1", client); + room1 = mkStubRoom("room-id-2", "Room 2", client); + room2 = mkStubRoom("room-id-3", "Room 3", client); + + hierarchyRoot = { + room_id: root.roomId, + num_joined_members: 1, + children_state: [{ + state_key: room1.roomId, + content: { order: "1" } + }, { + state_key: room2.roomId, + content: { order: "2" } + }] + } as IHierarchyRoom + hierarchyRoom1 = { room_id: room1.roomId, num_joined_members: 2 } as IHierarchyRoom + hierarchyRoom2 = { room_id: root.roomId, num_joined_members: 3 } as IHierarchyRoom + + roomHierarchy = { + roomMap: new Map([ + [root.roomId, hierarchyRoot], + [room1.roomId, hierarchyRoom1], + [room2.roomId, hierarchyRoom2], + ]), + isSuggested: jest.fn() + } as unknown as RoomHierarchy; + }); + + it("renders", () => { + const defaultProps = { + root: hierarchyRoot, + roomSet: new Set([hierarchyRoom1, hierarchyRoom2]), + hierarchy: roomHierarchy, + parents: new Set(), + selectedMap: new Map>(), + onViewRoomClick: jest.fn(), + onJoinRoomClick: jest.fn(), + onToggleClick: jest.fn(), + }; + const getComponent = (props = {}): React.ReactElement => ( + + ; + + ); + + const { container } = render(getComponent()); + expect(container).toMatchSnapshot(); + }); + }); }); diff --git a/test/components/structures/__snapshots__/SpaceHierarchy-test.tsx.snap b/test/components/structures/__snapshots__/SpaceHierarchy-test.tsx.snap new file mode 100644 index 0000000000..25340face1 --- /dev/null +++ b/test/components/structures/__snapshots__/SpaceHierarchy-test.tsx.snap @@ -0,0 +1,159 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`SpaceHierarchy renders 1`] = ` +
+
  • +
    +
    +
    + +
    +
    + Unnamed Room +
    + Joined +
    +
    +
    + 2 members + · + +
    +
    +
    +
    + View +
    + + +
    +
  • +
  • +
    +
    +
    + +
    +
    + Unnamed Room +
    + Joined +
    +
    +
    + 3 members + · + +
    +
    +
    +
    + View +
    + + +
    +
  • + ; +
    +`; From bf94d50be2f99f20896a26334d5ab94c503f4887 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Wed, 1 Feb 2023 19:53:01 +0100 Subject: [PATCH 08/10] Prettyfy --- .../structures/SpaceHierarchy-test.tsx | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/test/components/structures/SpaceHierarchy-test.tsx b/test/components/structures/SpaceHierarchy-test.tsx index 3d29b77646..34746b2960 100644 --- a/test/components/structures/SpaceHierarchy-test.tsx +++ b/test/components/structures/SpaceHierarchy-test.tsx @@ -145,9 +145,9 @@ describe("SpaceHierarchy", () => { let room1: Room; let room2: Room; - let hierarchyRoot: IHierarchyRoom - let hierarchyRoom1: IHierarchyRoom - let hierarchyRoom2: IHierarchyRoom + let hierarchyRoot: IHierarchyRoom; + let hierarchyRoom1: IHierarchyRoom; + let hierarchyRoom2: IHierarchyRoom; let roomHierarchy: RoomHierarchy; @@ -156,7 +156,7 @@ describe("SpaceHierarchy", () => { client = MatrixClientPeg.get(); dmRoomMap = { - getUserIdForRoomId: jest.fn() + getUserIdForRoomId: jest.fn(), } as unknown as DMRoomMap; jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap); @@ -167,16 +167,19 @@ describe("SpaceHierarchy", () => { hierarchyRoot = { room_id: root.roomId, num_joined_members: 1, - children_state: [{ - state_key: room1.roomId, - content: { order: "1" } - }, { - state_key: room2.roomId, - content: { order: "2" } - }] - } as IHierarchyRoom - hierarchyRoom1 = { room_id: room1.roomId, num_joined_members: 2 } as IHierarchyRoom - hierarchyRoom2 = { room_id: root.roomId, num_joined_members: 3 } as IHierarchyRoom + children_state: [ + { + state_key: room1.roomId, + content: { order: "1" }, + }, + { + state_key: room2.roomId, + content: { order: "2" }, + }, + ], + } as IHierarchyRoom; + hierarchyRoom1 = { room_id: room1.roomId, num_joined_members: 2 } as IHierarchyRoom; + hierarchyRoom2 = { room_id: root.roomId, num_joined_members: 3 } as IHierarchyRoom; roomHierarchy = { roomMap: new Map([ @@ -184,7 +187,7 @@ describe("SpaceHierarchy", () => { [room1.roomId, hierarchyRoom1], [room2.roomId, hierarchyRoom2], ]), - isSuggested: jest.fn() + isSuggested: jest.fn(), } as unknown as RoomHierarchy; }); From 568042b9e7e62bd0031751c3e3ce2548bea773df Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Thu, 2 Feb 2023 20:20:57 +0100 Subject: [PATCH 09/10] Move test setup to describe scope --- .../structures/SpaceHierarchy-test.tsx | 100 +++++++----------- 1 file changed, 39 insertions(+), 61 deletions(-) diff --git a/test/components/structures/SpaceHierarchy-test.tsx b/test/components/structures/SpaceHierarchy-test.tsx index 34746b2960..99a11a92a7 100644 --- a/test/components/structures/SpaceHierarchy-test.tsx +++ b/test/components/structures/SpaceHierarchy-test.tsx @@ -81,19 +81,12 @@ 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]); - }); + stubClient(); + let client = MatrixClientPeg.get(); + let roomV1 = mkStubRoom("room-id-1", "Room V1", client); + let roomV2 = mkStubRoom("room-id-2", "Room V2", client); + let 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 = { @@ -138,58 +131,43 @@ describe("SpaceHierarchy", () => { }); describe("", () => { - let client: MatrixClient; - let dmRoomMap: DMRoomMap; + stubClient(); + let client = MatrixClientPeg.get(); - let root: Room; - let room1: Room; - let room2: Room; + let dmRoomMap = { + getUserIdForRoomId: jest.fn(), + } as unknown as DMRoomMap; + jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap); - let hierarchyRoot: IHierarchyRoom; - let hierarchyRoom1: IHierarchyRoom; - let hierarchyRoom2: IHierarchyRoom; + let root = mkStubRoom("room-id-1", "Room 1", client); + let room1 = mkStubRoom("room-id-2", "Room 2", client); + let room2 = mkStubRoom("room-id-3", "Room 3", client); - let roomHierarchy: RoomHierarchy; + let hierarchyRoot = { + room_id: root.roomId, + num_joined_members: 1, + children_state: [ + { + state_key: room1.roomId, + content: { order: "1" }, + }, + { + state_key: room2.roomId, + content: { order: "2" }, + }, + ], + } as IHierarchyRoom; + let hierarchyRoom1 = { room_id: room1.roomId, num_joined_members: 2 } as IHierarchyRoom; + let hierarchyRoom2 = { room_id: root.roomId, num_joined_members: 3 } as IHierarchyRoom; - beforeEach(() => { - stubClient(); - client = MatrixClientPeg.get(); - - dmRoomMap = { - getUserIdForRoomId: jest.fn(), - } as unknown as DMRoomMap; - jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap); - - root = mkStubRoom("room-id-1", "Room 1", client); - room1 = mkStubRoom("room-id-2", "Room 2", client); - room2 = mkStubRoom("room-id-3", "Room 3", client); - - hierarchyRoot = { - room_id: root.roomId, - num_joined_members: 1, - children_state: [ - { - state_key: room1.roomId, - content: { order: "1" }, - }, - { - state_key: room2.roomId, - content: { order: "2" }, - }, - ], - } as IHierarchyRoom; - hierarchyRoom1 = { room_id: room1.roomId, num_joined_members: 2 } as IHierarchyRoom; - hierarchyRoom2 = { room_id: root.roomId, num_joined_members: 3 } as IHierarchyRoom; - - roomHierarchy = { - roomMap: new Map([ - [root.roomId, hierarchyRoot], - [room1.roomId, hierarchyRoom1], - [room2.roomId, hierarchyRoom2], - ]), - isSuggested: jest.fn(), - } as unknown as RoomHierarchy; - }); + let roomHierarchy = { + roomMap: new Map([ + [root.roomId, hierarchyRoot], + [room1.roomId, hierarchyRoom1], + [room2.roomId, hierarchyRoom2], + ]), + isSuggested: jest.fn(), + } as unknown as RoomHierarchy; it("renders", () => { const defaultProps = { From d3f378240ed15ca95b1b55520e554ab6e8fef8b9 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Thu, 2 Feb 2023 20:38:42 +0100 Subject: [PATCH 10/10] Appease the linter --- .../structures/SpaceHierarchy-test.tsx | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/components/structures/SpaceHierarchy-test.tsx b/test/components/structures/SpaceHierarchy-test.tsx index 99a11a92a7..2c5cb0e85a 100644 --- a/test/components/structures/SpaceHierarchy-test.tsx +++ b/test/components/structures/SpaceHierarchy-test.tsx @@ -82,10 +82,10 @@ describe("SpaceHierarchy", () => { describe("toLocalRoom", () => { stubClient(); - let client = MatrixClientPeg.get(); - let roomV1 = mkStubRoom("room-id-1", "Room V1", client); - let roomV2 = mkStubRoom("room-id-2", "Room V2", client); - let roomV3 = mkStubRoom("room-id-3", "Room V3", client); + const client = MatrixClientPeg.get(); + const roomV1 = mkStubRoom("room-id-1", "Room V1", client); + const roomV2 = mkStubRoom("room-id-2", "Room V2", client); + const 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", () => { @@ -132,18 +132,18 @@ describe("SpaceHierarchy", () => { describe("", () => { stubClient(); - let client = MatrixClientPeg.get(); + const client = MatrixClientPeg.get(); - let dmRoomMap = { + const dmRoomMap = { getUserIdForRoomId: jest.fn(), } as unknown as DMRoomMap; jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap); - let root = mkStubRoom("room-id-1", "Room 1", client); - let room1 = mkStubRoom("room-id-2", "Room 2", client); - let room2 = mkStubRoom("room-id-3", "Room 3", client); + const root = mkStubRoom("room-id-1", "Room 1", client); + const room1 = mkStubRoom("room-id-2", "Room 2", client); + const room2 = mkStubRoom("room-id-3", "Room 3", client); - let hierarchyRoot = { + const hierarchyRoot = { room_id: root.roomId, num_joined_members: 1, children_state: [ @@ -157,10 +157,10 @@ describe("SpaceHierarchy", () => { }, ], } as IHierarchyRoom; - let hierarchyRoom1 = { room_id: room1.roomId, num_joined_members: 2 } as IHierarchyRoom; - let hierarchyRoom2 = { room_id: root.roomId, num_joined_members: 3 } as IHierarchyRoom; + const hierarchyRoom1 = { room_id: room1.roomId, num_joined_members: 2 } as IHierarchyRoom; + const hierarchyRoom2 = { room_id: root.roomId, num_joined_members: 3 } as IHierarchyRoom; - let roomHierarchy = { + const roomHierarchy = { roomMap: new Map([ [root.roomId, hierarchyRoot], [room1.roomId, hierarchyRoom1],