2019-01-18 10:12:08 +00:00
|
|
|
/*
|
2019-01-25 13:04:59 +00:00
|
|
|
* Copyright 2019 New Vector Ltd
|
2019-01-18 10:12:08 +00:00
|
|
|
*
|
2019-01-25 13:04:59 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2019-01-18 10:12:08 +00:00
|
|
|
*
|
2019-01-25 13:04:59 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2019-01-18 10:12:08 +00:00
|
|
|
*/
|
|
|
|
|
2018-12-14 18:23:49 +00:00
|
|
|
package im.vector.matrix.android.session.room.timeline
|
|
|
|
|
2019-01-16 18:25:43 +00:00
|
|
|
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
|
|
|
import androidx.test.annotation.UiThreadTest
|
2018-12-14 18:23:49 +00:00
|
|
|
import com.zhuinden.monarchy.Monarchy
|
|
|
|
import im.vector.matrix.android.InstrumentedTest
|
|
|
|
import im.vector.matrix.android.LiveDataTestObserver
|
2019-01-03 20:25:51 +00:00
|
|
|
import im.vector.matrix.android.internal.session.room.members.RoomMemberExtractor
|
2019-01-14 15:18:39 +00:00
|
|
|
import im.vector.matrix.android.internal.session.room.timeline.DefaultTimelineService
|
2018-12-14 18:23:49 +00:00
|
|
|
import im.vector.matrix.android.internal.session.room.timeline.TokenChunkEventPersistor
|
2019-01-03 20:25:51 +00:00
|
|
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
2018-12-14 18:23:49 +00:00
|
|
|
import im.vector.matrix.android.testCoroutineDispatchers
|
|
|
|
import io.realm.Realm
|
|
|
|
import io.realm.RealmConfiguration
|
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
|
|
|
|
internal class TimelineHolderTest : InstrumentedTest {
|
|
|
|
|
|
|
|
@get:Rule val testRule = InstantTaskExecutorRule()
|
|
|
|
private lateinit var monarchy: Monarchy
|
|
|
|
|
|
|
|
@Before
|
|
|
|
fun setup() {
|
|
|
|
Realm.init(context())
|
|
|
|
val testConfiguration = RealmConfiguration.Builder().name("test-realm").build()
|
|
|
|
Realm.deleteRealm(testConfiguration)
|
|
|
|
monarchy = Monarchy.Builder().setRealmConfiguration(testConfiguration).build()
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@UiThreadTest
|
|
|
|
fun backPaginate_shouldLoadMoreEvents_whenLoadAroundIsCalled() {
|
|
|
|
val roomId = "roomId"
|
|
|
|
val taskExecutor = TaskExecutor(testCoroutineDispatchers)
|
|
|
|
val tokenChunkEventPersistor = TokenChunkEventPersistor(monarchy)
|
|
|
|
val paginationTask = FakePaginationTask(tokenChunkEventPersistor)
|
|
|
|
val getContextOfEventTask = FakeGetContextOfEventTask(tokenChunkEventPersistor)
|
|
|
|
RoomDataHelper.fakeInitialSync(monarchy, roomId)
|
2019-03-21 19:21:45 +00:00
|
|
|
val timelineHolder = DefaultTimelineService(roomId, monarchy, taskExecutor, getContextOfEventTask, RoomMemberExtractor(roomId))
|
2018-12-14 18:23:49 +00:00
|
|
|
val timelineObserver = LiveDataTestObserver.test(timelineHolder.timeline())
|
|
|
|
timelineObserver.awaitNextValue().assertHasValue()
|
2019-01-14 15:18:39 +00:00
|
|
|
var timelineData = timelineObserver.value()
|
|
|
|
timelineData.events.size shouldEqual 30
|
|
|
|
(0 until timelineData.events.size).map {
|
|
|
|
timelineData.events.loadAround(it)
|
2018-12-14 18:23:49 +00:00
|
|
|
}
|
|
|
|
timelineObserver.awaitNextValue().assertHasValue()
|
2019-01-14 15:18:39 +00:00
|
|
|
timelineData = timelineObserver.value()
|
|
|
|
timelineData.events.size shouldEqual 60
|
2018-12-14 18:23:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|