Use context provided RoomViewStore within the RoomView component hierarchy (#31077)

* Update ContentMessages.ts

Update ContentMessages.ts

* update PlaybackQueue.ts

* Update SpaceHierarchy.tsx

* Update ThreadView.tsx

* Update RoomCallBanner.tsx

* Update useRoomCall.tsx

* Update DateSeparator.tsx

* Update TimelineCard.tsx

* Update UserInfoBasicOptions

* Update slask-commands/utils.ts

* lint

* Update PlaybackQueue, MVoiceMessageBody and UserInfoBasicOptionsView tests.

* Update RoomHeader-test.tsx

* lint

* Add ts docs

* Update utils-test.tsx

* Update message-test.ts

* coverage

* lint

* Improve naming

---------

Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
David Langley
2025-10-29 09:40:21 +00:00
committed by GitHub
parent 209dfece21
commit ae2acdf311
38 changed files with 520 additions and 104 deletions

View File

@@ -9,18 +9,19 @@ Please see LICENSE files in the repository root for full details.
import React from "react";
import { mocked } from "jest-mock";
import { fireEvent, render, screen, waitFor, waitForElementToBeRemoved } from "jest-matrix-react";
import { type HierarchyRoom, JoinRule, type MatrixClient, Room } from "matrix-js-sdk/src/matrix";
import { type HierarchyRoom, JoinRule, MatrixError, type MatrixClient, Room } from "matrix-js-sdk/src/matrix";
import { KnownMembership } from "matrix-js-sdk/src/types";
import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
import { mkStubRoom, stubClient } from "../../../test-utils";
import dispatcher from "../../../../src/dispatcher/dispatcher";
import SpaceHierarchy, { showRoom, toLocalRoom } from "../../../../src/components/structures/SpaceHierarchy";
import SpaceHierarchy, { showRoom, toLocalRoom, joinRoom } from "../../../../src/components/structures/SpaceHierarchy";
import { Action } from "../../../../src/dispatcher/actions";
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
import DMRoomMap from "../../../../src/utils/DMRoomMap";
import SettingsStore from "../../../../src/settings/SettingsStore";
import { type RoomViewStore } from "../../../../src/stores/RoomViewStore";
describe("SpaceHierarchy", () => {
describe("showRoom", () => {
@@ -66,6 +67,59 @@ describe("SpaceHierarchy", () => {
});
});
describe("joinRoom", () => {
let client: MatrixClient;
let hierarchy: RoomHierarchy;
let roomViewStore: RoomViewStore;
let room: Room;
const roomId = "!room:server";
beforeEach(() => {
stubClient();
client = MatrixClientPeg.safeGet();
room = new Room("space-id", client, "@alice:example.com");
hierarchy = new RoomHierarchy(room);
roomViewStore = {
showJoinRoomError: jest.fn(),
} as unknown as RoomViewStore;
jest.spyOn(client, "isGuest").mockReturnValue(false);
jest.spyOn(dispatcher, "dispatch");
});
it("should handle MatrixError exceptions when joining room", async () => {
// Mock joinRoom to throw a MatrixError
const matrixError = new MatrixError({ errcode: "M_FORBIDDEN", error: "Access denied" });
mocked(client.joinRoom).mockRejectedValue(matrixError);
// Attempt to join the room
await expect(joinRoom(client, roomViewStore, hierarchy, roomId)).rejects.toThrow(matrixError);
// Verify that showJoinRoomError was called with the MatrixError
expect(roomViewStore.showJoinRoomError).toHaveBeenCalledWith(matrixError, roomId);
});
it("should handle non-MatrixError exceptions when joining room", async () => {
// Mock joinRoom to throw a non-MatrixError
const customError = new Error("Custom error");
mocked(client.joinRoom).mockRejectedValue(customError);
// Attempt to join the room
await expect(joinRoom(client, roomViewStore, hierarchy, roomId)).rejects.toThrow("Custom error");
// Verify that showJoinRoomError was called with a MatrixError wrapper
expect(roomViewStore.showJoinRoomError).toHaveBeenCalledWith(
expect.objectContaining({
errcode: undefined,
data: expect.objectContaining({
error: "Unknown error",
}),
}),
roomId,
);
});
});
describe("toLocalRoom", () => {
stubClient();
const client = MatrixClientPeg.safeGet();