Browse Source

Fix quality issues.

pull/3554/head
Benoit Marty 3 weeks ago
parent
commit
7628d480a8
  1. 3
      libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeRustTimeline.kt
  2. 16
      libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/timeline/TimelineItemsSubscriberTest.kt

3
libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeRustTimeline.kt

@ -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

16
libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/timeline/TimelineItemsSubscriberTest.kt

@ -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…
Cancel
Save