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

Commit

Permalink
Use room name as room intro (#9231)
Browse files Browse the repository at this point in the history
* Use roon name for room intro

* Fix types

* Revert caption var change

* Fix type issue
  • Loading branch information
weeman1337 authored Sep 6, 2022
1 parent 4524291 commit 9f7165e
Show file tree
Hide file tree
Showing 3 changed files with 3,558 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/components/views/rooms/NewRoomIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ const NewRoomIntro = () => {
? room.targets[0]?.userId
: DMRoomMap.shared().getUserIdForRoomId(roomId);

let body;
let body: JSX.Element;
if (dmPartner) {
let introMessage = _t("This is the beginning of your direct message history with <displayName/>.");
let caption;
let caption: string | undefined;

if (isLocalRoom) {
introMessage = _t("Send your first message to invite <displayName/> to chat");
Expand All @@ -67,7 +67,7 @@ const NewRoomIntro = () => {
}

const member = room?.getMember(dmPartner);
const displayName = member?.rawDisplayName || dmPartner;
const displayName = room?.name || member?.rawDisplayName || dmPartner;
body = <React.Fragment>
<RoomAvatar
room={room}
Expand Down
13 changes: 8 additions & 5 deletions test/components/views/rooms/NewRoomIntro-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,29 @@ describe("NewRoomIntro", () => {
describe("for a DM Room", () => {
beforeEach(() => {
jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(userId);
renderNewRoomIntro(client, new Room(roomId, client, client.getUserId()));
const room = new Room(roomId, client, client.getUserId());
room.name = "test_room";
renderNewRoomIntro(client, room);
});

it("should render the expected intro", () => {
const expected = `This is the beginning of your direct message history with ${userId}.`;
screen.getByText((id, element) => element.tagName === "SPAN" && element.textContent === expected);
const expected = `This is the beginning of your direct message history with test_room.`;
screen.getByText((id, element) => element?.tagName === "SPAN" && element?.textContent === expected);
});
});

describe("for a DM LocalRoom", () => {
beforeEach(() => {
jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(userId);
const localRoom = new LocalRoom(roomId, client, client.getUserId());
localRoom.name = "test_room";
localRoom.targets.push(new DirectoryMember({ user_id: userId }));
renderNewRoomIntro(client, localRoom);
});

it("should render the expected intro", () => {
const expected = `Send your first message to invite ${userId} to chat`;
screen.getByText((id, element) => element.tagName === "SPAN" && element.textContent === expected);
const expected = `Send your first message to invite test_room to chat`;
screen.getByText((id, element) => element?.tagName === "SPAN" && element?.textContent === expected);
});
});
});
Loading

0 comments on commit 9f7165e

Please sign in to comment.