Fix quality issues.
This commit is contained in:
parent
9f44cff403
commit
a6db076dfa
3 changed files with 79 additions and 72 deletions
|
|
@ -13,8 +13,7 @@ import org.matrix.rustcomponents.sdk.Timeline
|
||||||
import org.matrix.rustcomponents.sdk.TimelineDiff
|
import org.matrix.rustcomponents.sdk.TimelineDiff
|
||||||
import org.matrix.rustcomponents.sdk.TimelineListener
|
import org.matrix.rustcomponents.sdk.TimelineListener
|
||||||
|
|
||||||
class FakeRustTimeline(
|
class FakeRustTimeline : Timeline(NoPointer) {
|
||||||
) : Timeline(NoPointer) {
|
|
||||||
private var listener: TimelineListener? = null
|
private var listener: TimelineListener? = null
|
||||||
override suspend fun addListener(listener: TimelineListener): TaskHandle {
|
override suspend fun addListener(listener: TimelineListener): TaskHandle {
|
||||||
this.listener = listener
|
this.listener = listener
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,8 @@ import uniffi.matrix_sdk_ui.EventItemOrigin
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
class TimelineItemsSubscriberTest {
|
class TimelineItemsSubscriberTest {
|
||||||
@Test
|
@Test
|
||||||
fun `when timeline emits an empty list of items, the flow must emits an empty list`() = runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
|
fun `when timeline emits an empty list of items, the flow must emits an empty list`() {
|
||||||
|
runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
|
||||||
val timelineItems: MutableSharedFlow<List<MatrixTimelineItem>> =
|
val timelineItems: MutableSharedFlow<List<MatrixTimelineItem>> =
|
||||||
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
|
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
|
||||||
val timeline = FakeRustTimeline()
|
val timeline = FakeRustTimeline()
|
||||||
|
|
@ -52,9 +53,11 @@ class TimelineItemsSubscriberTest {
|
||||||
timelineItemsSubscriber.unsubscribeIfNeeded()
|
timelineItemsSubscriber.unsubscribeIfNeeded()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when timeline emits a non empty list of items, the flow must emits a non empty list`() = runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
|
fun `when timeline emits a non empty list of items, the flow must emits a non empty list`() {
|
||||||
|
runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
|
||||||
val timelineItems: MutableSharedFlow<List<MatrixTimelineItem>> =
|
val timelineItems: MutableSharedFlow<List<MatrixTimelineItem>> =
|
||||||
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
|
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
|
||||||
val timeline = FakeRustTimeline()
|
val timeline = FakeRustTimeline()
|
||||||
|
|
@ -73,9 +76,11 @@ class TimelineItemsSubscriberTest {
|
||||||
timelineItemsSubscriber.unsubscribeIfNeeded()
|
timelineItemsSubscriber.unsubscribeIfNeeded()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when timeline emits an item with SYNC origin, the callback onNewSyncedEvent is invoked`() = runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
|
fun `when timeline emits an item with SYNC origin, the callback onNewSyncedEvent is invoked`() {
|
||||||
|
runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
|
||||||
val timelineItems: MutableSharedFlow<List<MatrixTimelineItem>> =
|
val timelineItems: MutableSharedFlow<List<MatrixTimelineItem>> =
|
||||||
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
|
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
|
||||||
val timeline = FakeRustTimeline()
|
val timeline = FakeRustTimeline()
|
||||||
|
|
@ -106,9 +111,11 @@ class TimelineItemsSubscriberTest {
|
||||||
}
|
}
|
||||||
onNewSyncedEventRecorder.assertions().isCalledOnce()
|
onNewSyncedEventRecorder.assertions().isCalledOnce()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `multiple subscriptions does not have side effect`() = runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
|
fun `multiple subscriptions does not have side effect`() {
|
||||||
|
runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
|
||||||
val timelineItemsSubscriber = testScope.createTimelineItemsSubscriber(
|
val timelineItemsSubscriber = testScope.createTimelineItemsSubscriber(
|
||||||
coroutineScope = cancellableScope,
|
coroutineScope = cancellableScope,
|
||||||
)
|
)
|
||||||
|
|
@ -117,6 +124,7 @@ class TimelineItemsSubscriberTest {
|
||||||
timelineItemsSubscriber.unsubscribeIfNeeded()
|
timelineItemsSubscriber.unsubscribeIfNeeded()
|
||||||
timelineItemsSubscriber.unsubscribeIfNeeded()
|
timelineItemsSubscriber.unsubscribeIfNeeded()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun TestScope.createTimelineItemsSubscriber(
|
private fun TestScope.createTimelineItemsSubscriber(
|
||||||
coroutineScope: CoroutineScope,
|
coroutineScope: CoroutineScope,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue