Fix quality issues.

This commit is contained in:
Benoit Marty 2024-09-27 17:38:21 +02:00
parent 9f44cff403
commit a6db076dfa
3 changed files with 79 additions and 72 deletions

View file

@ -13,8 +13,7 @@ import org.matrix.rustcomponents.sdk.Timeline
import org.matrix.rustcomponents.sdk.TimelineDiff
import org.matrix.rustcomponents.sdk.TimelineListener
class FakeRustTimeline(
) : Timeline(NoPointer) {
class FakeRustTimeline : Timeline(NoPointer) {
private var listener: TimelineListener? = null
override suspend fun addListener(listener: TimelineListener): TaskHandle {
this.listener = listener

View file

@ -33,7 +33,8 @@ import uniffi.matrix_sdk_ui.EventItemOrigin
@OptIn(ExperimentalCoroutinesApi::class)
class TimelineItemsSubscriberTest {
@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>> =
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
val timeline = FakeRustTimeline()
@ -52,9 +53,11 @@ class TimelineItemsSubscriberTest {
timelineItemsSubscriber.unsubscribeIfNeeded()
}
}
}
@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>> =
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
val timeline = FakeRustTimeline()
@ -73,9 +76,11 @@ class TimelineItemsSubscriberTest {
timelineItemsSubscriber.unsubscribeIfNeeded()
}
}
}
@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>> =
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
val timeline = FakeRustTimeline()
@ -106,9 +111,11 @@ class TimelineItemsSubscriberTest {
}
onNewSyncedEventRecorder.assertions().isCalledOnce()
}
}
@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(
coroutineScope = cancellableScope,
)
@ -117,6 +124,7 @@ class TimelineItemsSubscriberTest {
timelineItemsSubscriber.unsubscribeIfNeeded()
timelineItemsSubscriber.unsubscribeIfNeeded()
}
}
private fun TestScope.createTimelineItemsSubscriber(
coroutineScope: CoroutineScope,