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

Commit ab1f6b6

Browse files
committed
Handle missing predecessor
1 parent 1b4c3f6 commit ab1f6b6

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-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: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,20 @@ describe("<RoomCreate />", () => {
4444
},
4545
event_id: "$create",
4646
});
47+
const createEventWithoutPredecessor = new MatrixEvent({
48+
type: EventType.RoomCreate,
49+
state_key: "",
50+
sender: userId,
51+
room_id: roomId,
52+
content: {},
53+
event_id: "$create",
54+
});
4755
stubClient();
4856
const client = mocked(MatrixClientPeg.get());
4957
const room = new Room(roomId, client, userId);
5058
upsertRoomStateEvents(room, [createEvent]);
59+
const roomNoPredecessors = new Room(roomId, client, userId);
60+
upsertRoomStateEvents(roomNoPredecessors, [createEventWithoutPredecessor]);
5161

5262
beforeEach(() => {
5363
jest.clearAllMocks();
@@ -62,7 +72,7 @@ describe("<RoomCreate />", () => {
6272
jest.spyOn(SettingsStore, "setValue").mockRestore();
6373
});
6474

65-
function renderRoomCreate() {
75+
function renderRoomCreate(room: Room) {
6676
return render(
6777
<RoomContext.Provider value={getRoomContext(room, {})}>
6878
<RoomCreate mxEvent={createEvent} />
@@ -71,20 +81,25 @@ describe("<RoomCreate />", () => {
7181
}
7282

7383
it("Renders as expected", () => {
74-
const roomCreate = renderRoomCreate();
84+
const roomCreate = renderRoomCreate(room);
7585
expect(roomCreate.asFragment()).toMatchSnapshot();
7686
});
7787

7888
it("Links to the old version of the room", () => {
79-
renderRoomCreate();
89+
renderRoomCreate(room);
8090
expect(screen.getByText("Click here to see older messages.")).toHaveAttribute(
8191
"href",
8292
"https://matrix.to/#/old_room_id/tombstone_event_id",
8393
);
8494
});
8595

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+
86101
it("Opens the old room on click", async () => {
87-
renderRoomCreate();
102+
renderRoomCreate(room);
88103
const link = screen.getByText("Click here to see older messages.");
89104

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

0 commit comments

Comments
 (0)