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

Commit

Permalink
test thread updates correctly updating timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Nov 23, 2022
1 parent a932664 commit 652f2c1
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions test/components/structures/TimelinePanel-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import {
} from 'matrix-js-sdk/src/matrix';
import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
import { render, RenderResult } from "@testing-library/react";
import { FeatureSupport, THREAD_RELATION_TYPE, ThreadFilterType, Thread } from "matrix-js-sdk/src/models/thread";

import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
import { mkRoom, stubClient } from "../../test-utils";
import TimelinePanel from '../../../src/components/structures/TimelinePanel';
import { MatrixClientPeg } from '../../../src/MatrixClientPeg';
Expand Down Expand Up @@ -172,4 +174,95 @@ describe('TimelinePanel', () => {
expect(client.setRoomReadMarkers).toHaveBeenCalledWith(room.roomId, "", undefined, events[0]);
});
});

it('updates thread previews', async () => {
const client = MatrixClientPeg.get();

Thread.hasServerSideSupport = FeatureSupport.Stable;
client.supportsExperimentalThreads = () => true;
const getValueCopy = SettingsStore.getValue;
SettingsStore.getValue = jest.fn().mockImplementation((name: string) => {
if (name === "feature_thread") return true;
return getValueCopy(name);
});

const room = new Room("roomId", client, "userId");
const allThreads = new EventTimelineSet(room, {
pendingEvents: false,
}, undefined, undefined, ThreadFilterType.All);
const timeline = new EventTimeline(allThreads);
allThreads.getLiveTimeline = () => timeline;
allThreads.getTimelineForEvent = () => timeline;

const reply1 = new MatrixEvent({
room_id: room.roomId,
event_id: `event_reply_1`,
type: EventType.RoomMessage,
user_id: "userId",
content: MessageEvent.from(`ReplyEvent1`).serialize().content,
});

const rootEvent = new MatrixEvent({
room_id: room.roomId,
event_id: `event_root`,
type: EventType.RoomMessage,
user_id: "userId",
content: MessageEvent.from(`RootEvent`).serialize().content,
unsigned: {
"m.relations": {
[THREAD_RELATION_TYPE.name]: {
"latest_event": reply1.event,
"count": 1,
"current_user_participated": true,
},
},
},
});

console.log("mocking thread");
const thread = room.createThread(rootEvent.getId(), rootEvent, [], true);
// So that we do not have to mock the thread loading
thread.initialEventsFetched = true;
// @ts-ignore
thread.fetchEditsWhereNeeded = () => Promise.resolve();
// @ts-ignore
thread.fetchRootEvent = () => {
thread.rootEvent = rootEvent;
};
await thread.addEvent(reply1, true);
await timeline.addEvent(thread.rootEvent, { toStartOfTimeline: true });

const dom = render(
<MatrixClientContext.Provider value={client}>
<TimelinePanel
timelineSet={allThreads}
manageReadReceipts
sendReadReceiptOnLoad
/>
</MatrixClientContext.Provider>,
);
await dom.findByText("RootEvent");
await dom.findByText("ReplyEvent1");

const reply2 = new MatrixEvent({
room_id: room.roomId,
event_id: `event_reply_2`,
type: EventType.RoomMessage,
user_id: "userId",
content: MessageEvent.from(`ReplyEvent2`).serialize().content,
});

rootEvent.setUnsigned({
"m.relations": {
[THREAD_RELATION_TYPE.name]: {
"latest_event": reply2.event,
"count": 2,
"current_user_participated": true,
},
},
});

await thread.addEvent(reply2, false, true);
await dom.findByText("ReplyEvent2");
});
});

0 comments on commit 652f2c1

Please sign in to comment.