1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-08-07 21:23:00 +03:00

Fix inability to join a knock room via space hierarchy view (#12404)

* Fix inability to join a `knock` room via space hierarchy view

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update src/components/structures/SpaceHierarchy.tsx

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>

* Add test

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update snapshot

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

---------

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
Michael Telatynski
2024-04-11 12:18:16 +01:00
committed by GitHub
parent c40fea008a
commit 77dfc1abee
3 changed files with 122 additions and 7 deletions

View File

@@ -17,7 +17,7 @@ limitations under the License.
import React from "react";
import { mocked } from "jest-mock";
import { fireEvent, render, screen, waitFor, waitForElementToBeRemoved } from "@testing-library/react";
import { MatrixClient, Room, HierarchyRoom } from "matrix-js-sdk/src/matrix";
import { HierarchyRoom, JoinRule, 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 { TooltipProvider } from "@vector-im/compound-web";
@@ -210,6 +210,13 @@ describe("SpaceHierarchy", () => {
type: "m.space.child",
sender: "@other:server",
},
{
state_key: "!knock1:server",
content: { order: "4" },
origin_server_ts: 111,
type: "m.space.child",
sender: "@other:server",
},
],
world_readable: true,
guest_can_join: true,
@@ -253,9 +260,25 @@ describe("SpaceHierarchy", () => {
world_readable: true,
guest_can_join: true,
};
const hierarchyKnockRoom1: HierarchyRoom = {
room_id: "!knock1:server",
name: "Knock room",
num_joined_members: 3,
children_state: [],
world_readable: true,
guest_can_join: true,
join_rule: JoinRule.Knock,
};
mocked(client.getRoomHierarchy).mockResolvedValue({
rooms: [hierarchyRoot, hierarchyRoom1, hierarchyRoom2, hierarchySpace1, hierarchyRoom3],
rooms: [
hierarchyRoot,
hierarchyRoom1,
hierarchyRoom2,
hierarchySpace1,
hierarchyRoom3,
hierarchyKnockRoom1,
],
});
const defaultProps = {
@@ -293,5 +316,24 @@ describe("SpaceHierarchy", () => {
expect(client.joinRoom).toHaveBeenCalledWith(space1.roomId, expect.any(Object));
expect(client.joinRoom).toHaveBeenCalledWith(room3.roomId, expect.any(Object));
});
it("should take user to view room for unjoined knockable rooms", async () => {
jest.spyOn(dispatcher, "dispatch");
const { getByText } = render(getComponent());
// Wait for spinners to go away
await waitForElementToBeRemoved(screen.getAllByRole("progressbar"));
const button = getByText("Knock room")!
.closest("li")!
.querySelector(".mx_AccessibleButton_kind_primary_outline")!;
fireEvent.click(button);
expect(defaultProps.showRoom).toHaveBeenCalledWith(
expect.anything(),
expect.anything(),
hierarchyKnockRoom1.room_id,
undefined,
);
});
});
});