@@ -31,7 +31,9 @@ import io.element.android.libraries.push.impl.notifications.fake.FakeRoomGroupMe
3131import io.element.android.libraries.push.impl.notifications.fake.FakeSummaryGroupMessageCreator
3232import io.element.android.libraries.push.impl.notifications.fixtures.aNotifiableMessageEvent
3333import io.element.android.libraries.sessionstorage.api.SessionStore
34+ import io.element.android.libraries.sessionstorage.api.observer.SessionObserver
3435import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
36+ import io.element.android.libraries.sessionstorage.test.observer.FakeSessionObserver
3537import io.element.android.services.appnavstate.api.AppNavigationState
3638import io.element.android.services.appnavstate.api.AppNavigationStateService
3739import io.element.android.services.appnavstate.api.NavigationState
@@ -205,35 +207,70 @@ class DefaultNotificationDrawerManagerTest {
205207 )
206208 }
207209
208- private fun TestScope.createDefaultNotificationDrawerManager (
209- notificationDisplayer : NotificationDisplayer = FakeNotificationDisplayer (),
210- appNavigationStateService : AppNavigationStateService = FakeAppNavigationStateService (),
211- roomGroupMessageCreator : RoomGroupMessageCreator = FakeRoomGroupMessageCreator (),
212- summaryGroupMessageCreator : SummaryGroupMessageCreator = FakeSummaryGroupMessageCreator (),
213- activeNotificationsProvider : FakeActiveNotificationsProvider = FakeActiveNotificationsProvider (),
214- matrixClientProvider : FakeMatrixClientProvider = FakeMatrixClientProvider (),
215- sessionStore : SessionStore = InMemorySessionStore (),
216- enterpriseService : EnterpriseService = FakeEnterpriseService (),
217- ): DefaultNotificationDrawerManager {
218- return DefaultNotificationDrawerManager (
210+ @Test
211+ fun `when a session is signed out, clearAllEvent is invoked` () = runTest {
212+ val cancelNotificationResult = lambdaRecorder<String ?, Int , Unit > { _, _ -> }
213+ val notificationDisplayer = FakeNotificationDisplayer (
214+ cancelNotificationResult = cancelNotificationResult,
215+ )
216+ val summaryId = NotificationIdProvider .getSummaryNotificationId(A_SESSION_ID )
217+ val activeNotificationsProvider = FakeActiveNotificationsProvider (
218+ getNotificationsForSessionResult = {
219+ listOf (
220+ mockk {
221+ every { id } returns summaryId
222+ every { tag } returns null
223+ },
224+ )
225+ },
226+ countResult = { 1 },
227+ )
228+ val sessionObserver = FakeSessionObserver ()
229+ createDefaultNotificationDrawerManager(
219230 notificationDisplayer = notificationDisplayer,
220- notificationRenderer = NotificationRenderer (
221- notificationDisplayer = FakeNotificationDisplayer (),
222- notificationDataFactory = DefaultNotificationDataFactory (
223- notificationCreator = FakeNotificationCreator (),
224- roomGroupMessageCreator = roomGroupMessageCreator,
225- summaryGroupMessageCreator = summaryGroupMessageCreator,
226- activeNotificationsProvider = activeNotificationsProvider,
227- stringProvider = FakeStringProvider (),
228- ),
229- enterpriseService = enterpriseService,
230- sessionStore = sessionStore,
231- ),
232- appNavigationStateService = appNavigationStateService,
233- coroutineScope = backgroundScope,
234- matrixClientProvider = matrixClientProvider,
235- imageLoaderHolder = FakeImageLoaderHolder (),
236231 activeNotificationsProvider = activeNotificationsProvider,
232+ sessionObserver = sessionObserver,
233+ )
234+ // Simulate a session sign out
235+ sessionObserver.onSessionDeleted(A_SESSION_ID .value)
236+ // Verify we asked to cancel the notification with summaryId
237+ cancelNotificationResult.assertions().isCalledExactly(1 ).withSequence(
238+ listOf (value(null ), value(summaryId)),
237239 )
238240 }
239241}
242+
243+ fun TestScope.createDefaultNotificationDrawerManager (
244+ notificationDisplayer : NotificationDisplayer = FakeNotificationDisplayer (),
245+ notificationRenderer : NotificationRenderer ? = null,
246+ appNavigationStateService : AppNavigationStateService = FakeAppNavigationStateService (),
247+ roomGroupMessageCreator : RoomGroupMessageCreator = FakeRoomGroupMessageCreator (),
248+ summaryGroupMessageCreator : SummaryGroupMessageCreator = FakeSummaryGroupMessageCreator (),
249+ activeNotificationsProvider : FakeActiveNotificationsProvider = FakeActiveNotificationsProvider (),
250+ matrixClientProvider : FakeMatrixClientProvider = FakeMatrixClientProvider (),
251+ sessionStore : SessionStore = InMemorySessionStore (),
252+ enterpriseService : EnterpriseService = FakeEnterpriseService (),
253+ sessionObserver : SessionObserver = FakeSessionObserver (),
254+ ): DefaultNotificationDrawerManager {
255+ return DefaultNotificationDrawerManager (
256+ notificationDisplayer = notificationDisplayer,
257+ notificationRenderer = notificationRenderer ? : NotificationRenderer (
258+ notificationDisplayer = FakeNotificationDisplayer (),
259+ notificationDataFactory = DefaultNotificationDataFactory (
260+ notificationCreator = FakeNotificationCreator (),
261+ roomGroupMessageCreator = roomGroupMessageCreator,
262+ summaryGroupMessageCreator = summaryGroupMessageCreator,
263+ activeNotificationsProvider = activeNotificationsProvider,
264+ stringProvider = FakeStringProvider (),
265+ ),
266+ enterpriseService = enterpriseService,
267+ sessionStore = sessionStore,
268+ ),
269+ appNavigationStateService = appNavigationStateService,
270+ coroutineScope = backgroundScope,
271+ matrixClientProvider = matrixClientProvider,
272+ imageLoaderHolder = FakeImageLoaderHolder (),
273+ activeNotificationsProvider = activeNotificationsProvider,
274+ sessionObserver = sessionObserver,
275+ )
276+ }
0 commit comments