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

Commit

Permalink
Handle missing predecessor
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalaam committed Feb 1, 2023
1 parent 92ce225 commit 10c572b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/views/messages/RoomCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const RoomCreate: React.FC<IProps> = ({ mxEvent, timestamp }) => {
metricsViaKeyboard: e.type !== "click",
});
},
[predecessor.eventId, predecessor.roomId],
[predecessor?.eventId, predecessor?.roomId],
);

if (!roomContext.room || roomContext.room.roomId !== mxEvent.getRoomId()) {
Expand Down
13 changes: 9 additions & 4 deletions test/components/views/messages/RoomCreate-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe("<RoomCreate />", () => {
jest.spyOn(SettingsStore, "setValue").mockRestore();
});

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

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));
Expand Down

0 comments on commit 10c572b

Please sign in to comment.