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

Commit bb91df1

Browse files
authored
Avoid rendering view-message link in RoomKnocksBar unnecessarily (#11598)
Signed-off-by: Charly Nguyen <[email protected]>
1 parent 3c6d8a2 commit bb91df1

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/components/views/rooms/RoomKnocksBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const RoomKnocksBar: VFC<{ room: Room }> = ({ room }) => {
112112
</>
113113
);
114114
names = `${knockMembers[0].name} (${knockMembers[0].userId})`;
115-
link = (
115+
link = knockMembers[0].events.member?.getContent().reason && (
116116
<AccessibleButton
117117
className="mx_RoomKnocksBar_link"
118118
element="a"

test/components/views/rooms/RoomKnocksBar-test.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,28 @@ describe("RoomKnocksBar", () => {
165165
expect(screen.getByRole("paragraph")).toHaveTextContent(`${bob.name} (${bob.userId})`);
166166
});
167167

168-
it("renders a link to open the room settings people tab", () => {
169-
getComponent(room);
170-
fireEvent.click(getButton("View message"));
171-
expect(dis.dispatch).toHaveBeenCalledWith({
172-
action: "open_room_settings",
173-
initial_tab_id: RoomSettingsTab.People,
174-
room_id: roomId,
168+
describe("when a knock reason is not provided", () => {
169+
it("does not render a link to open the room settings people tab", () => {
170+
getComponent(room);
171+
expect(screen.queryByRole("button", { name: "View message" })).not.toBeInTheDocument();
172+
});
173+
});
174+
175+
describe("when a knock reason is provided", () => {
176+
it("renders a link to open the room settings people tab", () => {
177+
bob.setMembershipEvent(
178+
new MatrixEvent({
179+
content: { displayname: "Bob", membership: "knock", reason: "some reason" },
180+
type: EventType.RoomMember,
181+
}),
182+
);
183+
getComponent(room);
184+
fireEvent.click(getButton("View message"));
185+
expect(dis.dispatch).toHaveBeenCalledWith({
186+
action: "open_room_settings",
187+
initial_tab_id: RoomSettingsTab.People,
188+
room_id: roomId,
189+
});
175190
});
176191
});
177192

0 commit comments

Comments
 (0)