From 09b8f39d8cc5a4c5284bda24d2ce31e6d226541d Mon Sep 17 00:00:00 2001 From: Charly Nguyen Date: Sat, 9 Sep 2023 11:45:07 +0200 Subject: [PATCH] Avoid rendering view-message link in RoomKnocksBar unnecessarily Signed-off-by: Charly Nguyen --- src/components/views/rooms/RoomKnocksBar.tsx | 2 +- .../views/rooms/RoomKnocksBar-test.tsx | 29 ++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/components/views/rooms/RoomKnocksBar.tsx b/src/components/views/rooms/RoomKnocksBar.tsx index 4928e3cf30c..f24db6ed2e9 100644 --- a/src/components/views/rooms/RoomKnocksBar.tsx +++ b/src/components/views/rooms/RoomKnocksBar.tsx @@ -112,7 +112,7 @@ export const RoomKnocksBar: VFC<{ room: Room }> = ({ room }) => { ); names = `${knockMembers[0].name} (${knockMembers[0].userId})`; - link = ( + link = knockMembers[0].events.member?.getContent().reason && ( { expect(screen.getByRole("paragraph")).toHaveTextContent(`${bob.name} (${bob.userId})`); }); - it("renders a link to open the room settings people tab", () => { - getComponent(room); - fireEvent.click(getButton("View message")); - expect(dis.dispatch).toHaveBeenCalledWith({ - action: "open_room_settings", - initial_tab_id: RoomSettingsTab.People, - room_id: roomId, + describe("when a knock reason is not provided", () => { + it("does not render a link to open the room settings people tab", () => { + getComponent(room); + expect(screen.queryByRole("button", { name: "View message" })).not.toBeInTheDocument(); + }); + }); + + describe("when a knock reason is provided", () => { + it("renders a link to open the room settings people tab", () => { + bob.setMembershipEvent( + new MatrixEvent({ + content: { displayname: "Bob", membership: "knock", reason: "some reason" }, + type: EventType.RoomMember, + }), + ); + getComponent(room); + fireEvent.click(getButton("View message")); + expect(dis.dispatch).toHaveBeenCalledWith({ + action: "open_room_settings", + initial_tab_id: RoomSettingsTab.People, + room_id: roomId, + }); }); });