@@ -40,7 +40,7 @@ final class OneSignalNotificationsTests: XCTestCase {
4040 // Put teardown code here. This method is called after the invocation of each test method in the class.
4141 }
4242
43- func testClearBadgesWhenAppEntersForeground( ) throws {
43+ func testClearBadgesWhenAppEntersForeground( ) throws { // Fails when running alone
4444 // NotificationManager Start to register lifecycle listener
4545 OSNotificationsManager . start ( )
4646 // Set badge count > 0
@@ -53,7 +53,59 @@ final class OneSignalNotificationsTests: XCTestCase {
5353 XCTAssertEqual ( UIApplication . shared. applicationIconBadgeNumber, 0 )
5454 }
5555
56- func testDontclearBadgesWhenAppBecomesActive( ) throws {
56+ func testDontclearBadgesWhenAppBecomesActive( ) throws { // Unable to make it fail alone
57+ // NotificationManager Start to register lifecycle listener
58+ OSNotificationsManager . start ( )
59+ // Set badge count > 0
60+ UIApplication . shared. applicationIconBadgeNumber = 1
61+ // Then resign active
62+ OneSignalCoreMocks . resignActive ( )
63+ // App becomes active the app
64+ OneSignalCoreMocks . becomeActive ( )
65+ // Ensure that badge count == 1
66+ XCTAssertEqual ( UIApplication . shared. applicationIconBadgeNumber, 1 )
67+ }
68+
69+ func testClearBadgesWhenAppEntersForeground1( ) throws {
70+ // NotificationManager Start to register lifecycle listener
71+ OSNotificationsManager . start ( )
72+ // Set badge count > 0
73+ UIApplication . shared. applicationIconBadgeNumber = 1
74+ // Then background the app
75+ OneSignalCoreMocks . backgroundApp ( )
76+ // Foreground the app
77+ OneSignalCoreMocks . foregroundApp ( )
78+ // Ensure that badge count == 0
79+ XCTAssertEqual ( UIApplication . shared. applicationIconBadgeNumber, 0 )
80+ }
81+
82+ func testDontclearBadgesWhenAppBecomesActive2( ) throws {
83+ // NotificationManager Start to register lifecycle listener
84+ OSNotificationsManager . start ( )
85+ // Set badge count > 0
86+ UIApplication . shared. applicationIconBadgeNumber = 1
87+ // Then resign active
88+ OneSignalCoreMocks . resignActive ( )
89+ // App becomes active the app
90+ OneSignalCoreMocks . becomeActive ( )
91+ // Ensure that badge count == 1
92+ XCTAssertEqual ( UIApplication . shared. applicationIconBadgeNumber, 1 )
93+ }
94+
95+ func testClearBadgesWhenAppEntersForeground3( ) throws {
96+ // NotificationManager Start to register lifecycle listener
97+ OSNotificationsManager . start ( )
98+ // Set badge count > 0
99+ UIApplication . shared. applicationIconBadgeNumber = 1
100+ // Then background the app
101+ OneSignalCoreMocks . backgroundApp ( )
102+ // Foreground the app
103+ OneSignalCoreMocks . foregroundApp ( )
104+ // Ensure that badge count == 0
105+ XCTAssertEqual ( UIApplication . shared. applicationIconBadgeNumber, 0 )
106+ }
107+
108+ func testDontclearBadgesWhenAppBecomesActive4( ) throws {
57109 // NotificationManager Start to register lifecycle listener
58110 OSNotificationsManager . start ( )
59111 // Set badge count > 0
0 commit comments