@@ -339,6 +339,52 @@ final class PushNotificationsManagerTests: XCTestCase {
339339
340340 XCTAssertEqual ( application. presentInAppMessages. first, Sample . defaultMessage)
341341 }
342+
343+ // MARK: - Foreground Notification Observable
344+
345+ func testItEmitsForegroundNotificationsWhenItReceivesANotificationWhileAppIsActive( ) {
346+ // Given
347+ application. applicationState = . active
348+
349+ var emittedNotifications = [ ForegroundNotification] ( )
350+ _ = manager. foregroundNotifications. subscribe { notification in
351+ emittedNotifications. append ( notification)
352+ }
353+
354+ let userinfo = notificationPayload ( noteID: 9_981 , type: . storeOrder)
355+
356+ // When
357+ manager. handleNotification ( userinfo) { _ in
358+ // noop
359+ }
360+
361+ // Then
362+ XCTAssertEqual ( emittedNotifications. count, 1 )
363+
364+ let emittedNotification = emittedNotifications. first!
365+ XCTAssertEqual ( emittedNotification. kind, . storeOrder)
366+ XCTAssertEqual ( emittedNotification. noteID, 9_981 )
367+ }
368+
369+ func testItDoesNotEmitForegroundNotificationsWhenItReceivesANotificationWhileAppIsNotActive( ) {
370+ // Given
371+ application. applicationState = . background
372+
373+ var emittedNotifications = [ ForegroundNotification] ( )
374+ _ = manager. foregroundNotifications. subscribe { notification in
375+ emittedNotifications. append ( notification)
376+ }
377+
378+ let userinfo = notificationPayload ( noteID: 9_981 , type: . storeOrder)
379+
380+ // When
381+ manager. handleNotification ( userinfo) { _ in
382+ // noop
383+ }
384+
385+ // Then
386+ XCTAssertTrue ( emittedNotifications. isEmpty)
387+ }
342388}
343389
344390
0 commit comments