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

Commit 652f2c1

Browse files
committed
test thread updates correctly updating timeline
1 parent a932664 commit 652f2c1

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

test/components/structures/TimelinePanel-test.tsx

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ import {
2828
} from 'matrix-js-sdk/src/matrix';
2929
import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
3030
import { render, RenderResult } from "@testing-library/react";
31+
import { FeatureSupport, THREAD_RELATION_TYPE, ThreadFilterType, Thread } from "matrix-js-sdk/src/models/thread";
3132

33+
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
3234
import { mkRoom, stubClient } from "../../test-utils";
3335
import TimelinePanel from '../../../src/components/structures/TimelinePanel';
3436
import { MatrixClientPeg } from '../../../src/MatrixClientPeg';
@@ -172,4 +174,95 @@ describe('TimelinePanel', () => {
172174
expect(client.setRoomReadMarkers).toHaveBeenCalledWith(room.roomId, "", undefined, events[0]);
173175
});
174176
});
177+
178+
it('updates thread previews', async () => {
179+
const client = MatrixClientPeg.get();
180+
181+
Thread.hasServerSideSupport = FeatureSupport.Stable;
182+
client.supportsExperimentalThreads = () => true;
183+
const getValueCopy = SettingsStore.getValue;
184+
SettingsStore.getValue = jest.fn().mockImplementation((name: string) => {
185+
if (name === "feature_thread") return true;
186+
return getValueCopy(name);
187+
});
188+
189+
const room = new Room("roomId", client, "userId");
190+
const allThreads = new EventTimelineSet(room, {
191+
pendingEvents: false,
192+
}, undefined, undefined, ThreadFilterType.All);
193+
const timeline = new EventTimeline(allThreads);
194+
allThreads.getLiveTimeline = () => timeline;
195+
allThreads.getTimelineForEvent = () => timeline;
196+
197+
const reply1 = new MatrixEvent({
198+
room_id: room.roomId,
199+
event_id: `event_reply_1`,
200+
type: EventType.RoomMessage,
201+
user_id: "userId",
202+
content: MessageEvent.from(`ReplyEvent1`).serialize().content,
203+
});
204+
205+
const rootEvent = new MatrixEvent({
206+
room_id: room.roomId,
207+
event_id: `event_root`,
208+
type: EventType.RoomMessage,
209+
user_id: "userId",
210+
content: MessageEvent.from(`RootEvent`).serialize().content,
211+
unsigned: {
212+
"m.relations": {
213+
[THREAD_RELATION_TYPE.name]: {
214+
"latest_event": reply1.event,
215+
"count": 1,
216+
"current_user_participated": true,
217+
},
218+
},
219+
},
220+
});
221+
222+
console.log("mocking thread");
223+
const thread = room.createThread(rootEvent.getId(), rootEvent, [], true);
224+
// So that we do not have to mock the thread loading
225+
thread.initialEventsFetched = true;
226+
// @ts-ignore
227+
thread.fetchEditsWhereNeeded = () => Promise.resolve();
228+
// @ts-ignore
229+
thread.fetchRootEvent = () => {
230+
thread.rootEvent = rootEvent;
231+
};
232+
await thread.addEvent(reply1, true);
233+
await timeline.addEvent(thread.rootEvent, { toStartOfTimeline: true });
234+
235+
const dom = render(
236+
<MatrixClientContext.Provider value={client}>
237+
<TimelinePanel
238+
timelineSet={allThreads}
239+
manageReadReceipts
240+
sendReadReceiptOnLoad
241+
/>
242+
</MatrixClientContext.Provider>,
243+
);
244+
await dom.findByText("RootEvent");
245+
await dom.findByText("ReplyEvent1");
246+
247+
const reply2 = new MatrixEvent({
248+
room_id: room.roomId,
249+
event_id: `event_reply_2`,
250+
type: EventType.RoomMessage,
251+
user_id: "userId",
252+
content: MessageEvent.from(`ReplyEvent2`).serialize().content,
253+
});
254+
255+
rootEvent.setUnsigned({
256+
"m.relations": {
257+
[THREAD_RELATION_TYPE.name]: {
258+
"latest_event": reply2.event,
259+
"count": 2,
260+
"current_user_participated": true,
261+
},
262+
},
263+
});
264+
265+
await thread.addEvent(reply2, false, true);
266+
await dom.findByText("ReplyEvent2");
267+
});
175268
});

0 commit comments

Comments
 (0)