Skip to content

Commit

Permalink
write test for thread list pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Sep 23, 2022
1 parent 94390da commit ba48a6f
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions spec/integ/matrix-client-event-timeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
import * as utils from "../test-utils/test-utils";
import { ClientEvent, EventTimeline, Filter, IEvent, MatrixClient, MatrixEvent, Room } from "../../src/matrix";
import { logger } from "../../src/logger";
import { encodeUri } from "../../src/utils";
import { TestClient } from "../TestClient";
import { FeatureSupport, Thread, THREAD_RELATION_TYPE } from "../../src/models/thread";

Expand Down Expand Up @@ -925,6 +926,96 @@ describe("MatrixClient event timelines", function() {
});
});

describe("paginateEventTimeline for thread list timeline", function() {
async function flushHttp<T>(promise: Promise<T>): Promise<T> {
return Promise.all([promise, httpBackend.flushAllExpected()]).then(([result]) => result);
}

it("should allow you to paginate backwards", async function() {
// @ts-ignore
client.clientOpts.experimentalThreadSupport = true;
Thread.setServerSideSupport(FeatureSupport.Experimental);
Thread.setServerSideListSupport(FeatureSupport.Stable);

const room = client.getRoom(roomId);
const [allThreads] = await room.createThreadsTimelineSets();

httpBackend.when("GET", encodeUri("/_matrix/client/r0/rooms/$roomId/context/$eventId", {
$roomId: roomId,
$eventId: THREAD_ROOT.event_id,
})).respond(200, {
end: "",
start: "",
state: [],
events_before: [],
events_after: [],
event: THREAD_ROOT,
});

await flushHttp(client.getEventTimeline(allThreads, THREAD_ROOT.event_id));
httpBackend.when("GET", encodeUri("/_matrix/client/r0/rooms/$roomId/threads", {
$roomId: roomId,
})).respond(200, {
chunk: [THREAD_ROOT],
});
const timeline = await flushHttp(client.getLatestTimeline(allThreads));
httpBackend.when("GET", encodeUri("/_matrix/client/r0/rooms/$roomId/threads", {
$roomId: roomId,
})).respond(200, {
chunk: [THREAD_ROOT],
next_batch: "end_token0",
});
const success = await flushHttp(client.paginateEventTimeline(timeline, { backwards: true }));
expect(success).toBeTruthy();
expect(timeline.getEvents().length).toEqual(1);
expect(timeline.getEvents()[0].event).toEqual(THREAD_ROOT);
expect(timeline.getPaginationToken(EventTimeline.BACKWARDS))
.toEqual("end_token0");
});

it("should allow you to paginate forwards", async function() {
// @ts-ignore
client.clientOpts.experimentalThreadSupport = true;
Thread.setServerSideSupport(FeatureSupport.Experimental);
Thread.setServerSideListSupport(FeatureSupport.Stable);

const room = client.getRoom(roomId);
const [allThreads] = await room.createThreadsTimelineSets();

httpBackend.when("GET", encodeUri("/_matrix/client/r0/rooms/$roomId/context/$eventId", {
$roomId: roomId,
$eventId: THREAD_ROOT.event_id,
})).respond(200, {
end: "",
start: "",
state: [],
events_before: [],
events_after: [],
event: THREAD_ROOT,
});

await flushHttp(client.getEventTimeline(allThreads, THREAD_ROOT.event_id));
httpBackend.when("GET", encodeUri("/_matrix/client/r0/rooms/$roomId/threads", {
$roomId: roomId,
})).respond(200, {
chunk: [THREAD_ROOT],
});
const timeline = await flushHttp(client.getLatestTimeline(allThreads));
httpBackend.when("GET", encodeUri("/_matrix/client/r0/rooms/$roomId/threads", {
$roomId: roomId,
})).respond(200, {
chunk: [THREAD_ROOT],
next_batch: "start_token1",
});
const success = await flushHttp(client.paginateEventTimeline(timeline, { backwards: false }));
expect(success).toBeTruthy();
expect(timeline.getEvents().length).toEqual(1);
expect(timeline.getEvents()[0].event).toEqual(THREAD_ROOT);
expect(timeline.getPaginationToken(EventTimeline.FORWARDS))
.toEqual("start_token1");
});
});

describe("event timeline for sent events", function() {
const TXN_ID = "txn1";
const event = utils.mkMessage({
Expand Down

0 comments on commit ba48a6f

Please sign in to comment.