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

Avoid rendering view-message link in RoomKnocksBar unnecessarily #11598

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/views/rooms/RoomKnocksBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 && (
<AccessibleButton
className="mx_RoomKnocksBar_link"
element="a"
Expand Down
29 changes: 22 additions & 7 deletions test/components/views/rooms/RoomKnocksBar-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,28 @@ describe("RoomKnocksBar", () => {
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,
});
});
});

Expand Down