Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 77dfc1a

Browse files
t3chguyrichvdh
andauthored
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 <[email protected]> * Update src/components/structures/SpaceHierarchy.tsx Co-authored-by: Richard van der Hoff <[email protected]> * Add test Signed-off-by: Michael Telatynski <[email protected]> * Update snapshot Signed-off-by: Michael Telatynski <[email protected]> --------- Signed-off-by: Michael Telatynski <[email protected]> Co-authored-by: Richard van der Hoff <[email protected]>
1 parent c40fea0 commit 77dfc1a

File tree

3 files changed

+122
-7
lines changed

3 files changed

+122
-7
lines changed

src/components/structures/SpaceHierarchy.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
HistoryVisibility,
4242
HierarchyRelation,
4343
HierarchyRoom,
44+
JoinRule,
4445
} from "matrix-js-sdk/src/matrix";
4546
import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy";
4647
import classNames from "classnames";
@@ -158,7 +159,9 @@ const Tile: React.FC<ITileProps> = ({
158159
<Spinner w={24} h={24} />
159160
</AccessibleTooltipButton>
160161
);
161-
} else if (joinedRoom) {
162+
} else if (joinedRoom || room.join_rule === JoinRule.Knock) {
163+
// If the room is knockable, show the "View" button even if we are not a member; that
164+
// allows us to reuse the "request to join" UX in RoomView.
162165
button = (
163166
<AccessibleButton
164167
onClick={onPreviewClick}

test/components/structures/SpaceHierarchy-test.tsx

+44-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
import React from "react";
1818
import { mocked } from "jest-mock";
1919
import { fireEvent, render, screen, waitFor, waitForElementToBeRemoved } from "@testing-library/react";
20-
import { MatrixClient, Room, HierarchyRoom } from "matrix-js-sdk/src/matrix";
20+
import { HierarchyRoom, JoinRule, MatrixClient, Room } from "matrix-js-sdk/src/matrix";
2121
import { KnownMembership } from "matrix-js-sdk/src/types";
2222
import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy";
2323
import { TooltipProvider } from "@vector-im/compound-web";
@@ -210,6 +210,13 @@ describe("SpaceHierarchy", () => {
210210
type: "m.space.child",
211211
sender: "@other:server",
212212
},
213+
{
214+
state_key: "!knock1:server",
215+
content: { order: "4" },
216+
origin_server_ts: 111,
217+
type: "m.space.child",
218+
sender: "@other:server",
219+
},
213220
],
214221
world_readable: true,
215222
guest_can_join: true,
@@ -253,9 +260,25 @@ describe("SpaceHierarchy", () => {
253260
world_readable: true,
254261
guest_can_join: true,
255262
};
263+
const hierarchyKnockRoom1: HierarchyRoom = {
264+
room_id: "!knock1:server",
265+
name: "Knock room",
266+
num_joined_members: 3,
267+
children_state: [],
268+
world_readable: true,
269+
guest_can_join: true,
270+
join_rule: JoinRule.Knock,
271+
};
256272

257273
mocked(client.getRoomHierarchy).mockResolvedValue({
258-
rooms: [hierarchyRoot, hierarchyRoom1, hierarchyRoom2, hierarchySpace1, hierarchyRoom3],
274+
rooms: [
275+
hierarchyRoot,
276+
hierarchyRoom1,
277+
hierarchyRoom2,
278+
hierarchySpace1,
279+
hierarchyRoom3,
280+
hierarchyKnockRoom1,
281+
],
259282
});
260283

261284
const defaultProps = {
@@ -293,5 +316,24 @@ describe("SpaceHierarchy", () => {
293316
expect(client.joinRoom).toHaveBeenCalledWith(space1.roomId, expect.any(Object));
294317
expect(client.joinRoom).toHaveBeenCalledWith(room3.roomId, expect.any(Object));
295318
});
319+
320+
it("should take user to view room for unjoined knockable rooms", async () => {
321+
jest.spyOn(dispatcher, "dispatch");
322+
323+
const { getByText } = render(getComponent());
324+
// Wait for spinners to go away
325+
await waitForElementToBeRemoved(screen.getAllByRole("progressbar"));
326+
const button = getByText("Knock room")!
327+
.closest("li")!
328+
.querySelector(".mx_AccessibleButton_kind_primary_outline")!;
329+
fireEvent.click(button);
330+
331+
expect(defaultProps.showRoom).toHaveBeenCalledWith(
332+
expect.anything(),
333+
expect.anything(),
334+
hierarchyKnockRoom1.room_id,
335+
undefined,
336+
);
337+
});
296338
});
297339
});

test/components/structures/__snapshots__/SpaceHierarchy-test.tsx.snap

+74-4
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,76 @@ exports[`SpaceHierarchy <SpaceHierarchy /> renders 1`] = `
195195
</div>
196196
</div>
197197
</li>
198+
<li
199+
class="mx_SpaceHierarchy_roomTileWrapper"
200+
role="treeitem"
201+
>
202+
<div
203+
class="mx_AccessibleButton mx_SpaceHierarchy_roomTile"
204+
role="button"
205+
tabindex="-1"
206+
>
207+
<div
208+
class="mx_SpaceHierarchy_roomTile_item"
209+
>
210+
<div
211+
class="mx_SpaceHierarchy_roomTile_avatar"
212+
>
213+
<span
214+
class="_avatar_mcap2_17 mx_BaseAvatar _avatar-imageless_mcap2_61"
215+
data-color="6"
216+
data-testid="avatar-img"
217+
data-type="round"
218+
role="presentation"
219+
style="--cpd-avatar-size: 20px;"
220+
>
221+
K
222+
</span>
223+
</div>
224+
<div
225+
class="mx_SpaceHierarchy_roomTile_name"
226+
>
227+
Knock room
228+
</div>
229+
<div
230+
class="mx_SpaceHierarchy_roomTile_info"
231+
>
232+
3 members
233+
</div>
234+
</div>
235+
<div
236+
class="mx_SpaceHierarchy_actions"
237+
>
238+
<div
239+
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_primary_outline"
240+
role="button"
241+
tabindex="-1"
242+
>
243+
View
244+
</div>
245+
<span
246+
class="mx_Checkbox mx_Checkbox_hasKind mx_Checkbox_kind_solid"
247+
>
248+
<input
249+
id="checkbox_wKpa6hpi3Y"
250+
tabindex="-1"
251+
type="checkbox"
252+
/>
253+
<label
254+
for="checkbox_wKpa6hpi3Y"
255+
>
256+
<div
257+
class="mx_Checkbox_background"
258+
>
259+
<div
260+
class="mx_Checkbox_checkmark"
261+
/>
262+
</div>
263+
</label>
264+
</span>
265+
</div>
266+
</div>
267+
</li>
198268
<li
199269
aria-expanded="true"
200270
class="mx_SpaceHierarchy_roomTileWrapper"
@@ -247,12 +317,12 @@ exports[`SpaceHierarchy <SpaceHierarchy /> renders 1`] = `
247317
class="mx_Checkbox mx_Checkbox_hasKind mx_Checkbox_kind_solid"
248318
>
249319
<input
250-
id="checkbox_wKpa6hpi3Y"
320+
id="checkbox_EetmBG4yVC"
251321
tabindex="-1"
252322
type="checkbox"
253323
/>
254324
<label
255-
for="checkbox_wKpa6hpi3Y"
325+
for="checkbox_EetmBG4yVC"
256326
>
257327
<div
258328
class="mx_Checkbox_background"
@@ -330,12 +400,12 @@ exports[`SpaceHierarchy <SpaceHierarchy /> renders 1`] = `
330400
>
331401
<input
332402
disabled=""
333-
id="checkbox_EetmBG4yVC"
403+
id="checkbox_eEefiPqpMR"
334404
tabindex="-1"
335405
type="checkbox"
336406
/>
337407
<label
338-
for="checkbox_EetmBG4yVC"
408+
for="checkbox_eEefiPqpMR"
339409
>
340410
<div
341411
class="mx_Checkbox_background"

0 commit comments

Comments
 (0)