change (preferences) : clean and fix tests

This commit is contained in:
ganfra 2025-04-10 18:10:50 +02:00
parent 64f139750c
commit 5fd987a116
5 changed files with 40 additions and 6 deletions

View file

@ -8,7 +8,12 @@
package io.element.android.features.messages.impl.timeline.protection
import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.matrix.api.media.MediaPreviewValue
import io.element.android.libraries.matrix.api.room.MatrixRoom
import io.element.android.libraries.matrix.api.room.join.JoinRule
import io.element.android.libraries.matrix.test.AN_EVENT_ID
import io.element.android.libraries.matrix.test.room.FakeMatrixRoom
import io.element.android.libraries.matrix.test.room.aRoomInfo
import io.element.android.libraries.preferences.api.store.AppPreferencesStore
import io.element.android.libraries.preferences.test.InMemoryAppPreferencesStore
import io.element.android.tests.testutils.WarmUpRule
@ -32,8 +37,8 @@ class TimelineProtectionPresenterTest {
}
@Test
fun `present - protected`() = runTest {
val appPreferencesStore = InMemoryAppPreferencesStore(hideImagesAndVideos = true)
fun `present - media preview value off`() = runTest {
val appPreferencesStore = InMemoryAppPreferencesStore(timelineMediaPreviewValue = MediaPreviewValue.Off)
val presenter = createPresenter(appPreferencesStore)
presenter.test {
skipItems(1)
@ -47,9 +52,42 @@ class TimelineProtectionPresenterTest {
}
}
@Test
fun `present - media preview value private in public room`() = runTest {
val appPreferencesStore = InMemoryAppPreferencesStore(timelineMediaPreviewValue = MediaPreviewValue.Private)
val room = FakeMatrixRoom(initialRoomInfo = aRoomInfo(joinRule = JoinRule.Public))
val presenter = createPresenter(appPreferencesStore, room)
presenter.test {
skipItems(1)
val initialState = awaitItem()
assertThat(initialState.protectionState).isEqualTo(ProtectionState.RenderOnly(persistentSetOf()))
// ShowContent with null should have no effect.
initialState.eventSink(TimelineProtectionEvent.ShowContent(eventId = null))
initialState.eventSink(TimelineProtectionEvent.ShowContent(eventId = AN_EVENT_ID))
val finalState = awaitItem()
assertThat(finalState.protectionState).isEqualTo(ProtectionState.RenderOnly(persistentSetOf(AN_EVENT_ID)))
}
}
@Test
fun `present - media preview value private in non public room`() = runTest {
val appPreferencesStore = InMemoryAppPreferencesStore(timelineMediaPreviewValue = MediaPreviewValue.Private)
val room = FakeMatrixRoom(initialRoomInfo = aRoomInfo(joinRule = JoinRule.Invite))
val presenter = createPresenter(appPreferencesStore, room)
presenter.test {
val initialState = awaitItem()
assertThat(initialState.protectionState).isEqualTo(ProtectionState.RenderAll)
// ShowContent with null should have no effect.
initialState.eventSink(TimelineProtectionEvent.ShowContent(eventId = null))
initialState.eventSink(TimelineProtectionEvent.ShowContent(eventId = AN_EVENT_ID))
}
}
private fun createPresenter(
appPreferencesStore: AppPreferencesStore = InMemoryAppPreferencesStore(),
room: MatrixRoom = FakeMatrixRoom(),
) = TimelineProtectionPresenter(
appPreferencesStore = appPreferencesStore,
room = room,
)
}