|
7 | 7 |
|
8 | 8 | package io.element.android.features.announcement.impl |
9 | 9 |
|
| 10 | +import app.cash.turbine.test |
10 | 11 | import com.google.common.truth.Truth.assertThat |
11 | 12 | import io.element.android.features.announcement.api.Announcement |
12 | 13 | import io.element.android.features.announcement.impl.spaces.SpaceAnnouncementState |
@@ -36,6 +37,41 @@ class DefaultAnnouncementServiceTest { |
36 | 37 | assertThat(announcementStore.announcementStatusFlow(Announcement.Space).first()).isEqualTo(AnnouncementStatus.Shown) |
37 | 38 | } |
38 | 39 |
|
| 40 | + @Test |
| 41 | + fun `when showing NewNotificationSound announcement, announcement is set to show even if it was already shown`() = runTest { |
| 42 | + val announcementStore = InMemoryAnnouncementStore() |
| 43 | + val sut = createDefaultAnnouncementService( |
| 44 | + announcementStore = announcementStore, |
| 45 | + ) |
| 46 | + assertThat(announcementStore.announcementStatusFlow(Announcement.NewNotificationSound).first()).isEqualTo(AnnouncementStatus.NeverShown) |
| 47 | + sut.showAnnouncement(Announcement.NewNotificationSound) |
| 48 | + assertThat(announcementStore.announcementStatusFlow(Announcement.NewNotificationSound).first()).isEqualTo(AnnouncementStatus.Show) |
| 49 | + // Simulate user close the announcement |
| 50 | + sut.onAnnouncementDismissed(Announcement.NewNotificationSound) |
| 51 | + // Calling again showAnnouncement should set it back to Show |
| 52 | + sut.showAnnouncement(Announcement.NewNotificationSound) |
| 53 | + assertThat(announcementStore.announcementStatusFlow(Announcement.NewNotificationSound).first()).isEqualTo(AnnouncementStatus.Show) |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + fun `test announcementsToShowFlow`() = runTest { |
| 58 | + val announcementStore = InMemoryAnnouncementStore() |
| 59 | + val sut = createDefaultAnnouncementService( |
| 60 | + announcementStore = announcementStore, |
| 61 | + ) |
| 62 | + sut.announcementsToShowFlow().test { |
| 63 | + assertThat(awaitItem()).isEmpty() |
| 64 | + announcementStore.setAnnouncementStatus(Announcement.Space, AnnouncementStatus.Show) |
| 65 | + assertThat(awaitItem()).containsExactly(Announcement.Space) |
| 66 | + announcementStore.setAnnouncementStatus(Announcement.NewNotificationSound, AnnouncementStatus.Show) |
| 67 | + assertThat(awaitItem()).containsExactly(Announcement.Space, Announcement.NewNotificationSound) |
| 68 | + announcementStore.setAnnouncementStatus(Announcement.Space, AnnouncementStatus.Shown) |
| 69 | + assertThat(awaitItem()).containsExactly(Announcement.NewNotificationSound) |
| 70 | + announcementStore.setAnnouncementStatus(Announcement.NewNotificationSound, AnnouncementStatus.Shown) |
| 71 | + assertThat(awaitItem()).isEmpty() |
| 72 | + } |
| 73 | + } |
| 74 | + |
39 | 75 | private fun createDefaultAnnouncementService( |
40 | 76 | announcementStore: AnnouncementStore = InMemoryAnnouncementStore(), |
41 | 77 | announcementPresenter: Presenter<AnnouncementState> = Presenter { anAnnouncementState() }, |
|
0 commit comments