mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 19:36:08 +03:00
Timeline: fix tests and add message order check
This commit is contained in:
parent
458e3ee5e8
commit
cad14c93d0
4 changed files with 32 additions and 37 deletions
|
@ -368,3 +368,13 @@ class CommonTestHelper(context: Context) {
|
||||||
session.close()
|
session.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun List<TimelineEvent>.checkSendOrder(baseTextMessage: String, numberOfMessages: Int, startIndex: Int): Boolean {
|
||||||
|
return drop(startIndex)
|
||||||
|
.take(numberOfMessages)
|
||||||
|
.foldRightIndexed(true) { index, timelineEvent, acc ->
|
||||||
|
val body = timelineEvent.root.content.toModel<MessageContent>()?.body
|
||||||
|
val currentMessageSuffix = numberOfMessages - index
|
||||||
|
acc && (body == null || body.startsWith(baseTextMessage) && body.endsWith("#$currentMessageSuffix"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import im.vector.matrix.android.api.session.room.timeline.Timeline
|
||||||
import im.vector.matrix.android.api.session.room.timeline.TimelineSettings
|
import im.vector.matrix.android.api.session.room.timeline.TimelineSettings
|
||||||
import im.vector.matrix.android.common.CommonTestHelper
|
import im.vector.matrix.android.common.CommonTestHelper
|
||||||
import im.vector.matrix.android.common.CryptoTestHelper
|
import im.vector.matrix.android.common.CryptoTestHelper
|
||||||
|
import im.vector.matrix.android.common.checkSendOrder
|
||||||
import org.amshove.kluent.shouldBeFalse
|
import org.amshove.kluent.shouldBeFalse
|
||||||
import org.amshove.kluent.shouldBeTrue
|
import org.amshove.kluent.shouldBeTrue
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
|
@ -90,10 +91,12 @@ class TimelineBackToPreviousLastForwardTest : InstrumentedTest {
|
||||||
// Bob stop to sync
|
// Bob stop to sync
|
||||||
bobSession.stopSync()
|
bobSession.stopSync()
|
||||||
|
|
||||||
|
val messageRoot = "First messages from Alice"
|
||||||
|
|
||||||
// Alice sends 30 messages
|
// Alice sends 30 messages
|
||||||
commonTestHelper.sendTextMessage(
|
commonTestHelper.sendTextMessage(
|
||||||
roomFromAlicePOV,
|
roomFromAlicePOV,
|
||||||
"First messages from Alice",
|
messageRoot,
|
||||||
30)
|
30)
|
||||||
|
|
||||||
// Bob start to sync
|
// Bob start to sync
|
||||||
|
@ -109,7 +112,7 @@ class TimelineBackToPreviousLastForwardTest : InstrumentedTest {
|
||||||
|
|
||||||
// Ok, we have the 10 last messages from Alice.
|
// Ok, we have the 10 last messages from Alice.
|
||||||
snapshot.size == 10
|
snapshot.size == 10
|
||||||
&& snapshot.all { it.root.content.toModel<MessageContent>()?.body?.startsWith("First messages from Alice").orFalse() }
|
&& snapshot.all { it.root.content.toModel<MessageContent>()?.body?.startsWith(messageRoot).orFalse() }
|
||||||
}
|
}
|
||||||
|
|
||||||
bobTimeline.addListener(eventsListener)
|
bobTimeline.addListener(eventsListener)
|
||||||
|
@ -159,33 +162,8 @@ class TimelineBackToPreviousLastForwardTest : InstrumentedTest {
|
||||||
// Bob can see the first event of the room (so Back pagination has worked)
|
// Bob can see the first event of the room (so Back pagination has worked)
|
||||||
snapshot.lastOrNull()?.root?.getClearType() == EventType.STATE_ROOM_CREATE
|
snapshot.lastOrNull()?.root?.getClearType() == EventType.STATE_ROOM_CREATE
|
||||||
// 8 for room creation item, and 30 for the forward pagination
|
// 8 for room creation item, and 30 for the forward pagination
|
||||||
&& snapshot.size == 8
|
&& snapshot.size == 38
|
||||||
}
|
&& snapshot.checkSendOrder(messageRoot, 30, 0)
|
||||||
|
|
||||||
bobTimeline.addListener(eventsListener)
|
|
||||||
|
|
||||||
bobTimeline.paginate(Timeline.Direction.FORWARDS, 50)
|
|
||||||
|
|
||||||
commonTestHelper.await(lock)
|
|
||||||
bobTimeline.removeAllListeners()
|
|
||||||
|
|
||||||
bobTimeline.hasMoreToLoad(Timeline.Direction.FORWARDS).shouldBeTrue()
|
|
||||||
bobTimeline.hasMoreToLoad(Timeline.Direction.BACKWARDS).shouldBeFalse()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do it again, now we should have a next token, so we can paginate FORWARD
|
|
||||||
run {
|
|
||||||
val lock = CountDownLatch(1)
|
|
||||||
val eventsListener = commonTestHelper.createEventListener(lock) { snapshot ->
|
|
||||||
Timber.e("Bob timeline updated: with ${snapshot.size} events:")
|
|
||||||
snapshot.forEach {
|
|
||||||
Timber.w(" event ${it.root}")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bob can see the first event of the room (so Back pagination has worked)
|
|
||||||
snapshot.lastOrNull()?.root?.getClearType() == EventType.STATE_ROOM_CREATE
|
|
||||||
// 8 for room creation item, and 30 for the forward pagination
|
|
||||||
&& snapshot.size == 8 + 30
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bobTimeline.addListener(eventsListener)
|
bobTimeline.addListener(eventsListener)
|
||||||
|
@ -197,8 +175,8 @@ class TimelineBackToPreviousLastForwardTest : InstrumentedTest {
|
||||||
|
|
||||||
bobTimeline.hasMoreToLoad(Timeline.Direction.FORWARDS).shouldBeFalse()
|
bobTimeline.hasMoreToLoad(Timeline.Direction.FORWARDS).shouldBeFalse()
|
||||||
bobTimeline.hasMoreToLoad(Timeline.Direction.BACKWARDS).shouldBeFalse()
|
bobTimeline.hasMoreToLoad(Timeline.Direction.BACKWARDS).shouldBeFalse()
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
bobTimeline.dispose()
|
bobTimeline.dispose()
|
||||||
|
|
||||||
cryptoTestData.cleanUp(commonTestHelper)
|
cryptoTestData.cleanUp(commonTestHelper)
|
||||||
|
|
|
@ -25,6 +25,7 @@ import im.vector.matrix.android.api.session.room.timeline.Timeline
|
||||||
import im.vector.matrix.android.api.session.room.timeline.TimelineSettings
|
import im.vector.matrix.android.api.session.room.timeline.TimelineSettings
|
||||||
import im.vector.matrix.android.common.CommonTestHelper
|
import im.vector.matrix.android.common.CommonTestHelper
|
||||||
import im.vector.matrix.android.common.CryptoTestHelper
|
import im.vector.matrix.android.common.CryptoTestHelper
|
||||||
|
import im.vector.matrix.android.common.checkSendOrder
|
||||||
import org.amshove.kluent.shouldBeFalse
|
import org.amshove.kluent.shouldBeFalse
|
||||||
import org.amshove.kluent.shouldBeTrue
|
import org.amshove.kluent.shouldBeTrue
|
||||||
import org.junit.FixMethodOrder
|
import org.junit.FixMethodOrder
|
||||||
|
@ -58,9 +59,10 @@ class TimelineForwardPaginationTest : InstrumentedTest {
|
||||||
val roomFromAlicePOV = aliceSession.getRoom(aliceRoomId)!!
|
val roomFromAlicePOV = aliceSession.getRoom(aliceRoomId)!!
|
||||||
|
|
||||||
// Alice sends X messages
|
// Alice sends X messages
|
||||||
|
val message = "Message from Alice"
|
||||||
val sentMessages = commonTestHelper.sendTextMessage(
|
val sentMessages = commonTestHelper.sendTextMessage(
|
||||||
roomFromAlicePOV,
|
roomFromAlicePOV,
|
||||||
"Message from Alice",
|
message,
|
||||||
numberOfMessagesToSend)
|
numberOfMessagesToSend)
|
||||||
|
|
||||||
// Alice clear the cache
|
// Alice clear the cache
|
||||||
|
@ -85,7 +87,7 @@ class TimelineForwardPaginationTest : InstrumentedTest {
|
||||||
|
|
||||||
// Ok, we have the 10 last messages of the initial sync
|
// Ok, we have the 10 last messages of the initial sync
|
||||||
snapshot.size == 10
|
snapshot.size == 10
|
||||||
&& snapshot.all { it.root.content.toModel<MessageContent>()?.body?.startsWith("Message from Alice").orFalse() }
|
&& snapshot.all { it.root.content.toModel<MessageContent>()?.body?.startsWith(message).orFalse() }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the timeline at last sent message
|
// Open the timeline at last sent message
|
||||||
|
@ -163,9 +165,9 @@ class TimelineForwardPaginationTest : InstrumentedTest {
|
||||||
snapshot.forEach {
|
snapshot.forEach {
|
||||||
Timber.w(" event ${it.root.content}")
|
Timber.w(" event ${it.root.content}")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6 for room creation item (backward pagination),and numberOfMessagesToSend (all the message of the room)
|
// 6 for room creation item (backward pagination),and numberOfMessagesToSend (all the message of the room)
|
||||||
snapshot.size == 6 + numberOfMessagesToSend
|
snapshot.size == 6 + numberOfMessagesToSend
|
||||||
|
&& snapshot.checkSendOrder(message, numberOfMessagesToSend, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
aliceTimeline.addListener(aliceEventsListener)
|
aliceTimeline.addListener(aliceEventsListener)
|
||||||
|
|
|
@ -25,6 +25,7 @@ import im.vector.matrix.android.api.session.room.timeline.Timeline
|
||||||
import im.vector.matrix.android.api.session.room.timeline.TimelineSettings
|
import im.vector.matrix.android.api.session.room.timeline.TimelineSettings
|
||||||
import im.vector.matrix.android.common.CommonTestHelper
|
import im.vector.matrix.android.common.CommonTestHelper
|
||||||
import im.vector.matrix.android.common.CryptoTestHelper
|
import im.vector.matrix.android.common.CryptoTestHelper
|
||||||
|
import im.vector.matrix.android.common.checkSendOrder
|
||||||
import org.amshove.kluent.shouldBeFalse
|
import org.amshove.kluent.shouldBeFalse
|
||||||
import org.amshove.kluent.shouldBeTrue
|
import org.amshove.kluent.shouldBeTrue
|
||||||
import org.junit.FixMethodOrder
|
import org.junit.FixMethodOrder
|
||||||
|
@ -85,10 +86,11 @@ class TimelinePreviousLastForwardTest : InstrumentedTest {
|
||||||
// Bob stop to sync
|
// Bob stop to sync
|
||||||
bobSession.stopSync()
|
bobSession.stopSync()
|
||||||
|
|
||||||
|
val firstMessage = "First messages from Alice"
|
||||||
// Alice sends 30 messages
|
// Alice sends 30 messages
|
||||||
val firstMessageFromAliceId = commonTestHelper.sendTextMessage(
|
val firstMessageFromAliceId = commonTestHelper.sendTextMessage(
|
||||||
roomFromAlicePOV,
|
roomFromAlicePOV,
|
||||||
"First messages from Alice",
|
firstMessage,
|
||||||
30)
|
30)
|
||||||
.last()
|
.last()
|
||||||
.eventId
|
.eventId
|
||||||
|
@ -106,7 +108,7 @@ class TimelinePreviousLastForwardTest : InstrumentedTest {
|
||||||
|
|
||||||
// Ok, we have the 10 last messages from Alice. This will be our future previous lastForward chunk
|
// Ok, we have the 10 last messages from Alice. This will be our future previous lastForward chunk
|
||||||
snapshot.size == 10
|
snapshot.size == 10
|
||||||
&& snapshot.all { it.root.content.toModel<MessageContent>()?.body?.startsWith("First messages from Alice").orFalse() }
|
&& snapshot.all { it.root.content.toModel<MessageContent>()?.body?.startsWith(firstMessage).orFalse() }
|
||||||
}
|
}
|
||||||
|
|
||||||
bobTimeline.addListener(eventsListener)
|
bobTimeline.addListener(eventsListener)
|
||||||
|
@ -120,10 +122,11 @@ class TimelinePreviousLastForwardTest : InstrumentedTest {
|
||||||
// Bob stop to sync
|
// Bob stop to sync
|
||||||
bobSession.stopSync()
|
bobSession.stopSync()
|
||||||
|
|
||||||
|
val secondMessage = "Second messages from Alice"
|
||||||
// Alice sends again 30 messages
|
// Alice sends again 30 messages
|
||||||
commonTestHelper.sendTextMessage(
|
commonTestHelper.sendTextMessage(
|
||||||
roomFromAlicePOV,
|
roomFromAlicePOV,
|
||||||
"Second messages from Alice",
|
secondMessage,
|
||||||
30)
|
30)
|
||||||
|
|
||||||
// Bob start to sync
|
// Bob start to sync
|
||||||
|
@ -139,7 +142,7 @@ class TimelinePreviousLastForwardTest : InstrumentedTest {
|
||||||
|
|
||||||
// Ok, we have the 10 last messages from Alice. This will be our future previous lastForward chunk
|
// Ok, we have the 10 last messages from Alice. This will be our future previous lastForward chunk
|
||||||
snapshot.size == 10
|
snapshot.size == 10
|
||||||
&& snapshot.all { it.root.content.toModel<MessageContent>()?.body?.startsWith("Second messages from Alice").orFalse() }
|
&& snapshot.all { it.root.content.toModel<MessageContent>()?.body?.startsWith(secondMessage).orFalse() }
|
||||||
}
|
}
|
||||||
|
|
||||||
bobTimeline.addListener(eventsListener)
|
bobTimeline.addListener(eventsListener)
|
||||||
|
@ -216,6 +219,8 @@ class TimelinePreviousLastForwardTest : InstrumentedTest {
|
||||||
snapshot.lastOrNull()?.root?.getClearType() == EventType.STATE_ROOM_CREATE
|
snapshot.lastOrNull()?.root?.getClearType() == EventType.STATE_ROOM_CREATE
|
||||||
// 8 for room creation item 60 message from Alice
|
// 8 for room creation item 60 message from Alice
|
||||||
&& snapshot.size == 8 + 60
|
&& snapshot.size == 8 + 60
|
||||||
|
&& snapshot.checkSendOrder(secondMessage, 30, 0)
|
||||||
|
&& snapshot.checkSendOrder(firstMessage, 30, 30)
|
||||||
}
|
}
|
||||||
|
|
||||||
bobTimeline.addListener(eventsListener)
|
bobTimeline.addListener(eventsListener)
|
||||||
|
|
Loading…
Reference in a new issue