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

Commit 10c572b

Browse files
committed
Handle missing predecessor
1 parent 92ce225 commit 10c572b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/components/views/messages/RoomCreate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const RoomCreate: React.FC<IProps> = ({ mxEvent, timestamp }) => {
6363
metricsViaKeyboard: e.type !== "click",
6464
});
6565
},
66-
[predecessor.eventId, predecessor.roomId],
66+
[predecessor?.eventId, predecessor?.roomId],
6767
);
6868

6969
if (!roomContext.room || roomContext.room.roomId !== mxEvent.getRoomId()) {

test/components/views/messages/RoomCreate-test.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe("<RoomCreate />", () => {
7272
jest.spyOn(SettingsStore, "setValue").mockRestore();
7373
});
7474

75-
function renderRoomCreate() {
75+
function renderRoomCreate(room: Room) {
7676
return render(
7777
<RoomContext.Provider value={getRoomContext(room, {})}>
7878
<RoomCreate mxEvent={createEvent} />
@@ -81,20 +81,25 @@ describe("<RoomCreate />", () => {
8181
}
8282

8383
it("Renders as expected", () => {
84-
const roomCreate = renderRoomCreate();
84+
const roomCreate = renderRoomCreate(room);
8585
expect(roomCreate.asFragment()).toMatchSnapshot();
8686
});
8787

8888
it("Links to the old version of the room", () => {
89-
renderRoomCreate();
89+
renderRoomCreate(room);
9090
expect(screen.getByText("Click here to see older messages.")).toHaveAttribute(
9191
"href",
9292
"https://matrix.to/#/old_room_id/tombstone_event_id",
9393
);
9494
});
9595

96+
it("Shows an empty div if there is no predecessor", () => {
97+
renderRoomCreate(roomNoPredecessors);
98+
expect(screen.queryByText("Click here to see older messages.", { exact: false })).toBeNull();
99+
});
100+
96101
it("Opens the old room on click", async () => {
97-
renderRoomCreate();
102+
renderRoomCreate(room);
98103
const link = screen.getByText("Click here to see older messages.");
99104

100105
await act(() => userEvent.click(link));

0 commit comments

Comments
 (0)