From 10c572bf3a4c3db56449baf595b82e80f2fd11db Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Wed, 1 Feb 2023 11:49:39 +0000 Subject: [PATCH] Handle missing predecessor --- src/components/views/messages/RoomCreate.tsx | 2 +- test/components/views/messages/RoomCreate-test.tsx | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/views/messages/RoomCreate.tsx b/src/components/views/messages/RoomCreate.tsx index cc453bf180fb..0b6ce03431f2 100644 --- a/src/components/views/messages/RoomCreate.tsx +++ b/src/components/views/messages/RoomCreate.tsx @@ -63,7 +63,7 @@ export const RoomCreate: React.FC = ({ mxEvent, timestamp }) => { metricsViaKeyboard: e.type !== "click", }); }, - [predecessor.eventId, predecessor.roomId], + [predecessor?.eventId, predecessor?.roomId], ); if (!roomContext.room || roomContext.room.roomId !== mxEvent.getRoomId()) { diff --git a/test/components/views/messages/RoomCreate-test.tsx b/test/components/views/messages/RoomCreate-test.tsx index df84972b56c7..c3fcf51c616c 100644 --- a/test/components/views/messages/RoomCreate-test.tsx +++ b/test/components/views/messages/RoomCreate-test.tsx @@ -72,7 +72,7 @@ describe("", () => { jest.spyOn(SettingsStore, "setValue").mockRestore(); }); - function renderRoomCreate() { + function renderRoomCreate(room: Room) { return render( @@ -81,20 +81,25 @@ describe("", () => { } it("Renders as expected", () => { - const roomCreate = renderRoomCreate(); + const roomCreate = renderRoomCreate(room); expect(roomCreate.asFragment()).toMatchSnapshot(); }); it("Links to the old version of the room", () => { - renderRoomCreate(); + renderRoomCreate(room); expect(screen.getByText("Click here to see older messages.")).toHaveAttribute( "href", "https://matrix.to/#/old_room_id/tombstone_event_id", ); }); + it("Shows an empty div if there is no predecessor", () => { + renderRoomCreate(roomNoPredecessors); + expect(screen.queryByText("Click here to see older messages.", { exact: false })).toBeNull(); + }); + it("Opens the old room on click", async () => { - renderRoomCreate(); + renderRoomCreate(room); const link = screen.getByText("Click here to see older messages."); await act(() => userEvent.click(link));