From 8133bb2a275bd88ff85eefe9de62b1fa2d6a379d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 8 Oct 2025 11:38:11 +0200 Subject: [PATCH] Add missing tests on DefaultAnnouncementService --- .../impl/DefaultAnnouncementServiceTest.kt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/features/announcement/impl/src/test/kotlin/io/element/android/features/announcement/impl/DefaultAnnouncementServiceTest.kt b/features/announcement/impl/src/test/kotlin/io/element/android/features/announcement/impl/DefaultAnnouncementServiceTest.kt index f16d7db26d..990f506223 100644 --- a/features/announcement/impl/src/test/kotlin/io/element/android/features/announcement/impl/DefaultAnnouncementServiceTest.kt +++ b/features/announcement/impl/src/test/kotlin/io/element/android/features/announcement/impl/DefaultAnnouncementServiceTest.kt @@ -7,6 +7,7 @@ package io.element.android.features.announcement.impl +import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.features.announcement.api.Announcement import io.element.android.features.announcement.impl.spaces.SpaceAnnouncementState @@ -36,6 +37,41 @@ class DefaultAnnouncementServiceTest { assertThat(announcementStore.announcementStatusFlow(Announcement.Space).first()).isEqualTo(AnnouncementStatus.Shown) } + @Test + fun `when showing NewNotificationSound announcement, announcement is set to show even if it was already shown`() = runTest { + val announcementStore = InMemoryAnnouncementStore() + val sut = createDefaultAnnouncementService( + announcementStore = announcementStore, + ) + assertThat(announcementStore.announcementStatusFlow(Announcement.NewNotificationSound).first()).isEqualTo(AnnouncementStatus.NeverShown) + sut.showAnnouncement(Announcement.NewNotificationSound) + assertThat(announcementStore.announcementStatusFlow(Announcement.NewNotificationSound).first()).isEqualTo(AnnouncementStatus.Show) + // Simulate user close the announcement + sut.onAnnouncementDismissed(Announcement.NewNotificationSound) + // Calling again showAnnouncement should set it back to Show + sut.showAnnouncement(Announcement.NewNotificationSound) + assertThat(announcementStore.announcementStatusFlow(Announcement.NewNotificationSound).first()).isEqualTo(AnnouncementStatus.Show) + } + + @Test + fun `test announcementsToShowFlow`() = runTest { + val announcementStore = InMemoryAnnouncementStore() + val sut = createDefaultAnnouncementService( + announcementStore = announcementStore, + ) + sut.announcementsToShowFlow().test { + assertThat(awaitItem()).isEmpty() + announcementStore.setAnnouncementStatus(Announcement.Space, AnnouncementStatus.Show) + assertThat(awaitItem()).containsExactly(Announcement.Space) + announcementStore.setAnnouncementStatus(Announcement.NewNotificationSound, AnnouncementStatus.Show) + assertThat(awaitItem()).containsExactly(Announcement.Space, Announcement.NewNotificationSound) + announcementStore.setAnnouncementStatus(Announcement.Space, AnnouncementStatus.Shown) + assertThat(awaitItem()).containsExactly(Announcement.NewNotificationSound) + announcementStore.setAnnouncementStatus(Announcement.NewNotificationSound, AnnouncementStatus.Shown) + assertThat(awaitItem()).isEmpty() + } + } + private fun createDefaultAnnouncementService( announcementStore: AnnouncementStore = InMemoryAnnouncementStore(), announcementPresenter: Presenter = Presenter { anAnnouncementState() },