Instead of using a magic number, explicitly test for the events we expect.
This permits a clear error when the events are missing / extra and while not making the test invulnerable to future changes in events, should be explicit on what's changed.
This commit is contained in:
parent
f7303789a0
commit
5a1545058b
@ -140,9 +140,24 @@ class TimelineForwardPaginationTest : InstrumentedTest {
|
|||||||
aliceTimeline.hasMoreToLoad(Timeline.Direction.BACKWARDS).shouldBeFalse()
|
aliceTimeline.hasMoreToLoad(Timeline.Direction.BACKWARDS).shouldBeFalse()
|
||||||
|
|
||||||
assertEquals(EventType.STATE_ROOM_CREATE, snapshot.lastOrNull()?.root?.getClearType())
|
assertEquals(EventType.STATE_ROOM_CREATE, snapshot.lastOrNull()?.root?.getClearType())
|
||||||
// 6 for room creation item (backward pagination), 1 for the context, and 50 for the forward pagination
|
|
||||||
// 6 + 1 + 50
|
// We explicitly test all the types we expect here, as we expect 51 messages and "some" state events
|
||||||
assertEquals(57, snapshot.size)
|
// But state events can change over time. So this acts as a kinda documentation of what we expect and
|
||||||
|
// provides a good error message if it doesn't match
|
||||||
|
|
||||||
|
val snapshotTypes = mutableMapOf<String?, Int>()
|
||||||
|
snapshot.groupingBy { it -> it.root.type }.eachCountTo(snapshotTypes)
|
||||||
|
// Some state events on room creation
|
||||||
|
assertEquals("m.room.name", 1, snapshotTypes.remove("m.room.name"))
|
||||||
|
assertEquals("m.room.guest_access", 1, snapshotTypes.remove("m.room.guest_access"))
|
||||||
|
assertEquals("m.room.history_visibility", 1, snapshotTypes.remove("m.room.history_visibility"))
|
||||||
|
assertEquals("m.room.join_rules", 1, snapshotTypes.remove("m.room.join_rules"))
|
||||||
|
assertEquals("m.room.power_levels", 1, snapshotTypes.remove("m.room.power_levels"))
|
||||||
|
assertEquals("m.room.create", 1, snapshotTypes.remove("m.room.create"))
|
||||||
|
assertEquals("m.room.member", 1, snapshotTypes.remove("m.room.member"))
|
||||||
|
// 50 from pagination + 1 context
|
||||||
|
assertEquals("m.room.message", 51, snapshotTypes.remove("m.room.message"))
|
||||||
|
assertEquals("Additional events found in timeline", setOf<String>(), snapshotTypes.keys)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alice paginates once again FORWARD for 50 events
|
// Alice paginates once again FORWARD for 50 events
|
||||||
@ -152,8 +167,8 @@ class TimelineForwardPaginationTest : InstrumentedTest {
|
|||||||
val snapshot = runBlocking {
|
val snapshot = runBlocking {
|
||||||
aliceTimeline.awaitPaginate(Timeline.Direction.FORWARDS, 50)
|
aliceTimeline.awaitPaginate(Timeline.Direction.FORWARDS, 50)
|
||||||
}
|
}
|
||||||
// 6 for room creation item (backward pagination),and numberOfMessagesToSend (all the message of the room)
|
// 7 for room creation item (backward pagination),and numberOfMessagesToSend (all the message of the room)
|
||||||
snapshot.size == 6 + numberOfMessagesToSend &&
|
snapshot.size == 7 + numberOfMessagesToSend &&
|
||||||
snapshot.checkSendOrder(message, numberOfMessagesToSend, 0)
|
snapshot.checkSendOrder(message, numberOfMessagesToSend, 0)
|
||||||
|
|
||||||
// The timeline is fully loaded
|
// The timeline is fully loaded
|
||||||
|
Loading…
Reference in New Issue
Block a user