From e9a49fdf740d19817701eeb710dae239ab919fa7 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Fri, 14 Jan 2022 17:07:06 +0530 Subject: [PATCH] Use hsApi mock --- src/matrix/room/timeline/Timeline.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/matrix/room/timeline/Timeline.js b/src/matrix/room/timeline/Timeline.js index ee0de044..69ab4eba 100644 --- a/src/matrix/room/timeline/Timeline.js +++ b/src/matrix/room/timeline/Timeline.js @@ -765,9 +765,24 @@ export function tests() { }, "context entry is fetched from hs": async assert => { + const hsApi = { + context() { + const result = { + event: withTextBody("foo", createEvent("m.room.message", "event_id_1", alice)), + state: [{ + type: MEMBER_EVENT_TYPE, + user_id: alice, + content: { + displayName: "", + avatarUrl: "" + } + }] + }; + return { response: () => result }; + } + }; const timeline = new Timeline({roomId, storage: await createMockStorage(), closeCallback: () => {}, - fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock()}); - const entryA = new EventEntry({ event: withTextBody("foo", createEvent("m.room.message", "event_id_1", alice)), eventIndex: 1 }); + fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock(), hsApi}); let event = withContent({ body: "bar", msgtype: "m.text", @@ -778,12 +793,11 @@ export function tests() { } }, createEvent("m.room.message", "event_id_2", bob)); const entryB = new EventEntry({ event, eventIndex: 2 }); - timeline._getEventFromHomeserver = () => entryA await timeline.load(new User(alice), "join", new NullLogItem()); timeline.entries.subscribe({ onAdd: () => null, onUpdate: () => null }); timeline.addEntries([entryB]); await poll(() => entryB.contextEntry); - assert.deepEqual(entryB.contextEntry, entryA); + assert.strictEqual(entryB.contextEntry.id, "event_id_1"); }, "context entry has a list of entries to which it forms the context": async assert => {