diff --git a/features/announcement/impl/src/test/kotlin/io/element/android/features/announcement/impl/AnnouncementPresenterTest.kt b/features/announcement/impl/src/test/kotlin/io/element/android/features/announcement/impl/AnnouncementPresenterTest.kt new file mode 100644 index 0000000000..87cd68a405 --- /dev/null +++ b/features/announcement/impl/src/test/kotlin/io/element/android/features/announcement/impl/AnnouncementPresenterTest.kt @@ -0,0 +1,50 @@ +/* + * Copyright 2025 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.features.announcement.impl + +import com.google.common.truth.Truth.assertThat +import io.element.android.features.announcement.impl.store.AnnouncementStore +import io.element.android.features.announcement.impl.store.InMemoryAnnouncementStore +import io.element.android.tests.testutils.test +import kotlinx.coroutines.test.runTest +import org.junit.Test + +class AnnouncementPresenterTest { + @Test + fun `present - initial state`() = runTest { + val presenter = createAnnouncementPresenter() + presenter.test { + val state = awaitItem() + assertThat(state.showSpaceAnnouncement).isFalse() + } + } + + @Test + fun `present - showSpaceAnnouncement value depends on the value in the store`() = runTest { + val store = InMemoryAnnouncementStore() + val presenter = createAnnouncementPresenter( + announcementStore = store, + ) + presenter.test { + val state = awaitItem() + assertThat(state.showSpaceAnnouncement).isFalse() + store.setSpaceAnnouncementValue(AnnouncementStore.SpaceAnnouncement.Show) + val updatedState = awaitItem() + assertThat(updatedState.showSpaceAnnouncement).isTrue() + store.setSpaceAnnouncementValue(AnnouncementStore.SpaceAnnouncement.Shown) + val finalState = awaitItem() + assertThat(finalState.showSpaceAnnouncement).isFalse() + } + } +} + +private fun createAnnouncementPresenter( + announcementStore: AnnouncementStore = InMemoryAnnouncementStore(), +) = AnnouncementPresenter( + announcementStore = announcementStore, +) diff --git a/features/announcement/impl/src/test/kotlin/io/element/android/features/announcement/impl/store/InMemoryAnnouncementStore.kt b/features/announcement/impl/src/test/kotlin/io/element/android/features/announcement/impl/store/InMemoryAnnouncementStore.kt new file mode 100644 index 0000000000..0f99ef66bd --- /dev/null +++ b/features/announcement/impl/src/test/kotlin/io/element/android/features/announcement/impl/store/InMemoryAnnouncementStore.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2025 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.features.announcement.impl.store + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow + +class InMemoryAnnouncementStore( + initialSpaceAnnouncement: AnnouncementStore.SpaceAnnouncement = AnnouncementStore.SpaceAnnouncement.NeverShown, +) : AnnouncementStore { + private val spaceAnnouncement = MutableStateFlow(initialSpaceAnnouncement) + override suspend fun setSpaceAnnouncementValue(value: AnnouncementStore.SpaceAnnouncement) { + spaceAnnouncement.value = value + } + + override fun spaceAnnouncementFlow(): Flow { + return spaceAnnouncement.asStateFlow() + } + + override suspend fun reset() { + spaceAnnouncement.value = AnnouncementStore.SpaceAnnouncement.NeverShown + } +} diff --git a/features/announcement/impl/src/test/kotlin/io/element/android/features/rageshake/impl/AnnouncementPresenterTest.kt b/features/announcement/impl/src/test/kotlin/io/element/android/features/rageshake/impl/AnnouncementPresenterTest.kt deleted file mode 100644 index 5bfa74bc27..0000000000 --- a/features/announcement/impl/src/test/kotlin/io/element/android/features/rageshake/impl/AnnouncementPresenterTest.kt +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright 2025 New Vector Ltd. - * - * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial - * Please see LICENSE files in the repository root for full details. - */ - -package io.element.android.features.rageshake.impl - -import kotlinx.coroutines.test.runTest -import org.junit.Test - -class AnnouncementPresenterTest { - @Test - fun `present - initial test`() = runTest { - // TODO - } -}