From 668fb37da97074c3f04a413f961c926ce4613854 Mon Sep 17 00:00:00 2001
From: Danila Fedorin <danila.fedorin@gmail.com>
Date: Fri, 17 Sep 2021 14:42:52 -0700
Subject: [PATCH] Test appending as well as prepending

---
 src/matrix/room/timeline/persistence/GapWriter.js | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/matrix/room/timeline/persistence/GapWriter.js b/src/matrix/room/timeline/persistence/GapWriter.js
index 4d8cc78c..c4c2e5bb 100644
--- a/src/matrix/room/timeline/persistence/GapWriter.js
+++ b/src/matrix/room/timeline/persistence/GapWriter.js
@@ -544,7 +544,7 @@ export function tests() {
             assert.equal(contextFragment.nextId, null);
             assert.equal(syncFragment.previousId, null);
         },
-        "Context sync near another fragment appends to that fragment.": async assert => {
+        "Context sync after another fragment appends to that fragment.": async assert => {
             const mocks = await setup();
             const { timelineMock } = mocks;
             timelineMock.append(20);
@@ -556,6 +556,18 @@ export function tests() {
             const events = await allFragmentEvents(mocks, firstFragments[0].id);
             assert.deepEqual(events.map(e => e.event_id), eventIds(0, 16));
         },
+        "Context sync before another fragment prepends to that fragment.": async assert => {
+            const mocks = await setup();
+            const { timelineMock } = mocks;
+            timelineMock.append(20);
+            const {fragments: firstFragments} = await contextAndWrite(mocks, eventId(11));
+            const {fragments: secondFragments} = await contextAndWrite(mocks, eventId(5));
+
+            assert.equal(firstFragments.length, 1);
+            assert.equal(secondFragments.length, 0);
+            const events = await allFragmentEvents(mocks, firstFragments[0].id);
+            assert.deepEqual(events.map(e => e.event_id), eventIds(0, 16));
+        },
         "Context sync between two fragments links the two fragments, and fills one of them.": async assert => {
             const mocks = await setup();
             const { timelineMock } = mocks;