Timeline test: check timeline is initialized and disposed
This commit is contained in:
parent
39edc780fe
commit
61ca79a2da
3 changed files with 27 additions and 40 deletions
|
|
@ -1,31 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2023 New Vector Ltd
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@file:OptIn(ExperimentalCoroutinesApi::class)
|
|
||||||
|
|
||||||
package io.element.android.features.messages.timeline
|
|
||||||
|
|
||||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
||||||
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
|
||||||
|
|
||||||
// TODO Move to common module to reuse
|
|
||||||
fun testCoroutineDispatchers() = CoroutineDispatchers(
|
|
||||||
io = UnconfinedTestDispatcher(),
|
|
||||||
computation = UnconfinedTestDispatcher(),
|
|
||||||
main = UnconfinedTestDispatcher(),
|
|
||||||
diffUpdateDispatcher = UnconfinedTestDispatcher(),
|
|
||||||
)
|
|
||||||
|
|
@ -48,12 +48,27 @@ class TimelinePresenterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `present - load more`() = runTest {
|
fun `present - makes sure timeline is initialized and disposed`() = runTest {
|
||||||
val matrixTimeline = FakeMatrixTimeline()
|
val fakeTimeline = FakeMatrixTimeline()
|
||||||
val matrixRoom = FakeMatrixRoom(matrixTimeline = matrixTimeline)
|
|
||||||
val presenter = TimelinePresenter(
|
val presenter = TimelinePresenter(
|
||||||
timelineItemsFactory = aTimelineItemsFactory(),
|
timelineItemsFactory = aTimelineItemsFactory(),
|
||||||
room = matrixRoom,
|
room = FakeMatrixRoom(matrixTimeline = fakeTimeline),
|
||||||
|
)
|
||||||
|
assertThat(fakeTimeline.isInitialized).isFalse()
|
||||||
|
moleculeFlow(RecompositionClock.Immediate) {
|
||||||
|
presenter.present()
|
||||||
|
}.test {
|
||||||
|
skipItems(2)
|
||||||
|
assertThat(fakeTimeline.isInitialized).isTrue()
|
||||||
|
}
|
||||||
|
assertThat(fakeTimeline.isInitialized).isFalse()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - load more`() = runTest {
|
||||||
|
val presenter = TimelinePresenter(
|
||||||
|
timelineItemsFactory = aTimelineItemsFactory(),
|
||||||
|
room = FakeMatrixRoom(),
|
||||||
)
|
)
|
||||||
moleculeFlow(RecompositionClock.Immediate) {
|
moleculeFlow(RecompositionClock.Immediate) {
|
||||||
presenter.present()
|
presenter.present()
|
||||||
|
|
@ -73,11 +88,9 @@ class TimelinePresenterTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `present - set highlighted event`() = runTest {
|
fun `present - set highlighted event`() = runTest {
|
||||||
val matrixTimeline = FakeMatrixTimeline()
|
|
||||||
val matrixRoom = FakeMatrixRoom(matrixTimeline = matrixTimeline)
|
|
||||||
val presenter = TimelinePresenter(
|
val presenter = TimelinePresenter(
|
||||||
timelineItemsFactory = aTimelineItemsFactory(),
|
timelineItemsFactory = aTimelineItemsFactory(),
|
||||||
room = matrixRoom,
|
room = FakeMatrixRoom(),
|
||||||
)
|
)
|
||||||
moleculeFlow(RecompositionClock.Immediate) {
|
moleculeFlow(RecompositionClock.Immediate) {
|
||||||
presenter.present()
|
presenter.present()
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ class FakeMatrixTimeline(
|
||||||
|
|
||||||
private val paginationState: MutableStateFlow<MatrixTimeline.PaginationState> = MutableStateFlow(initialPaginationState)
|
private val paginationState: MutableStateFlow<MatrixTimeline.PaginationState> = MutableStateFlow(initialPaginationState)
|
||||||
private val timelineItems: MutableStateFlow<List<MatrixTimelineItem>> = MutableStateFlow(initialTimelineItems)
|
private val timelineItems: MutableStateFlow<List<MatrixTimelineItem>> = MutableStateFlow(initialTimelineItems)
|
||||||
|
var isInitialized = false
|
||||||
|
|
||||||
fun updatePaginationState(update: (MatrixTimeline.PaginationState.() -> MatrixTimeline.PaginationState)) {
|
fun updatePaginationState(update: (MatrixTimeline.PaginationState.() -> MatrixTimeline.PaginationState)) {
|
||||||
paginationState.value = update(paginationState.value)
|
paginationState.value = update(paginationState.value)
|
||||||
|
|
@ -62,9 +63,13 @@ class FakeMatrixTimeline(
|
||||||
return Result.success(Unit)
|
return Result.success(Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initialize() = Unit
|
override fun initialize() {
|
||||||
|
isInitialized = true
|
||||||
|
}
|
||||||
|
|
||||||
override fun dispose() = Unit
|
override fun dispose() {
|
||||||
|
isInitialized = false
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun sendMessage(message: String): Result<Unit> {
|
override suspend fun sendMessage(message: String): Result<Unit> {
|
||||||
return Result.success(Unit)
|
return Result.success(Unit)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue