From d1d8e289b88bb497423248af03d3e43f96568e4a Mon Sep 17 00:00:00 2001 From: Nan Date: Wed, 30 Oct 2024 10:18:16 -0700 Subject: [PATCH 1/4] trigger ci --- iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m index d3061a94a..de420b5aa 100644 --- a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m +++ b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m @@ -50,7 +50,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( // [FIRApp configure]; - NSLog(@"Bundle URL: %@", [[NSBundle mainBundle] bundleURL]); + NSLog(@" Bundle URL: %@", [[NSBundle mainBundle] bundleURL]); [OneSignal.Debug setLogLevel:ONE_S_LL_VERBOSE]; [OneSignal.Debug setAlertLevel:ONE_S_LL_NONE]; From 7398517a2f7c2240d83547d0f351012dbe34ec39 Mon Sep 17 00:00:00 2001 From: Nan Date: Wed, 30 Oct 2024 11:24:00 -0700 Subject: [PATCH 2/4] adfafafafadf --- .github/workflows/ci.yml | 2 +- .../contents.xcworkspacedata | 3 + .../xcschemes/UnitTestApp.xcscheme | 13 +++++ .../OneSignalNotificationsTests.swift | 56 ++++++++++++++++++- ...UnitTestPlan_TestPlan_BadgeOnly.xctestplan | 24 ++++++++ 5 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 iOS_SDK/OneSignalSDK/UnitTestApp/UnitTestPlan_TestPlan_BadgeOnly.xctestplan diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e8163d6c2..b169cbc25 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: - name: Test env: scheme: ${{ 'UnitTestApp' }} - test_plan: ${{ 'UnitTestApp_TestPlan_Reduced' }} + test_plan: ${{ 'UnitTestPlan_TestPlan_BadgeOnly' }} platform: ${{ 'iOS Simulator' }} file_to_build: ${{ 'iOS_SDK/OneSignalSDK/OneSignal.xcodeproj' }} filetype_parameter: ${{ 'project' }} diff --git a/iOS_SDK/OneSignalSDK.xcworkspace/contents.xcworkspacedata b/iOS_SDK/OneSignalSDK.xcworkspace/contents.xcworkspacedata index 9979cb733..bb378804e 100644 --- a/iOS_SDK/OneSignalSDK.xcworkspace/contents.xcworkspacedata +++ b/iOS_SDK/OneSignalSDK.xcworkspace/contents.xcworkspacedata @@ -1,6 +1,9 @@ + + diff --git a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/xcshareddata/xcschemes/UnitTestApp.xcscheme b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/xcshareddata/xcschemes/UnitTestApp.xcscheme index 78545068d..bf007ec61 100644 --- a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/xcshareddata/xcschemes/UnitTestApp.xcscheme +++ b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/xcshareddata/xcschemes/UnitTestApp.xcscheme @@ -151,6 +151,9 @@ + + + + + + 0 @@ -53,7 +53,59 @@ final class OneSignalNotificationsTests: XCTestCase { XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 0) } - func testDontclearBadgesWhenAppBecomesActive() throws { + func testDontclearBadgesWhenAppBecomesActive() throws { // Unable to make it fail alone + // NotificationManager Start to register lifecycle listener + OSNotificationsManager.start() + // Set badge count > 0 + UIApplication.shared.applicationIconBadgeNumber = 1 + // Then resign active + OneSignalCoreMocks.resignActive() + // App becomes active the app + OneSignalCoreMocks.becomeActive() + // Ensure that badge count == 1 + XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 1) + } + + func testClearBadgesWhenAppEntersForeground1() throws { + // NotificationManager Start to register lifecycle listener + OSNotificationsManager.start() + // Set badge count > 0 + UIApplication.shared.applicationIconBadgeNumber = 1 + // Then background the app + OneSignalCoreMocks.backgroundApp() + // Foreground the app + OneSignalCoreMocks.foregroundApp() + // Ensure that badge count == 0 + XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 0) + } + + func testDontclearBadgesWhenAppBecomesActive2() throws { + // NotificationManager Start to register lifecycle listener + OSNotificationsManager.start() + // Set badge count > 0 + UIApplication.shared.applicationIconBadgeNumber = 1 + // Then resign active + OneSignalCoreMocks.resignActive() + // App becomes active the app + OneSignalCoreMocks.becomeActive() + // Ensure that badge count == 1 + XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 1) + } + + func testClearBadgesWhenAppEntersForeground3() throws { + // NotificationManager Start to register lifecycle listener + OSNotificationsManager.start() + // Set badge count > 0 + UIApplication.shared.applicationIconBadgeNumber = 1 + // Then background the app + OneSignalCoreMocks.backgroundApp() + // Foreground the app + OneSignalCoreMocks.foregroundApp() + // Ensure that badge count == 0 + XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 0) + } + + func testDontclearBadgesWhenAppBecomesActive4() throws { // NotificationManager Start to register lifecycle listener OSNotificationsManager.start() // Set badge count > 0 diff --git a/iOS_SDK/OneSignalSDK/UnitTestApp/UnitTestPlan_TestPlan_BadgeOnly.xctestplan b/iOS_SDK/OneSignalSDK/UnitTestApp/UnitTestPlan_TestPlan_BadgeOnly.xctestplan new file mode 100644 index 000000000..209ee99ae --- /dev/null +++ b/iOS_SDK/OneSignalSDK/UnitTestApp/UnitTestPlan_TestPlan_BadgeOnly.xctestplan @@ -0,0 +1,24 @@ +{ + "configurations" : [ + { + "id" : "0F56CD0B-5904-415C-B328-24EE0394B75B", + "name" : "Configuration 1", + "options" : { + + } + } + ], + "defaultOptions" : { + "testTimeoutsEnabled" : true + }, + "testTargets" : [ + { + "target" : { + "containerPath" : "container:OneSignal.xcodeproj", + "identifier" : "DEBA2A192C20E35E00E234DB", + "name" : "OneSignalNotificationsTests" + } + } + ], + "version" : 1 +} From 5096cd048b47951c800a6b199dc70418ecbd16d8 Mon Sep 17 00:00:00 2001 From: Nan Date: Wed, 30 Oct 2024 12:15:03 -0700 Subject: [PATCH 3/4] afgfdssgfd --- .../OSNotificationsManager.m | 2 + .../OneSignalNotificationsTests.swift | 108 +++++++++--------- 2 files changed, 58 insertions(+), 52 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m index 9ce51e29b..b0e5ed11c 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m @@ -260,8 +260,10 @@ + (void)start { + (void)registerLifecycleObserver { // Replacing swizzled lifecycle selectors with notification center observers for scene based Apps if ([OSBundleUtils isAppUsingUIScene]) { + NSLog(@"💛 registerLifecycleObserverAs UIScene "); [self registerLifecycleObserverAsUIScene]; } else { + NSLog(@"💛 registerLifecycleObserverAs UIApplication "); [self registerLifecycleObserverAsUIApplication]; } } diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift b/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift index e5c2981f8..972f50267 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift @@ -31,6 +31,8 @@ final class OneSignalNotificationsTests: XCTestCase { var token: String = "" override func setUpWithError() throws { + // Temp. logging to help debug during testing + OneSignalLog.setLogLevel(.LL_VERBOSE) // Put setup code here. This method is called before the invocation of each test method in the class. self.notifTypes = 0 self.token = "" @@ -44,6 +46,7 @@ final class OneSignalNotificationsTests: XCTestCase { // NotificationManager Start to register lifecycle listener OSNotificationsManager.start() // Set badge count > 0 + print("💛 testClearBadgesWhenAppEntersForeground setting applicationIconBadgeNumber") UIApplication.shared.applicationIconBadgeNumber = 1 // Then background the app OneSignalCoreMocks.backgroundApp() @@ -57,6 +60,7 @@ final class OneSignalNotificationsTests: XCTestCase { // NotificationManager Start to register lifecycle listener OSNotificationsManager.start() // Set badge count > 0 + print("💛 testDontclearBadgesWhenAppBecomesActive setting applicationIconBadgeNumber") UIApplication.shared.applicationIconBadgeNumber = 1 // Then resign active OneSignalCoreMocks.resignActive() @@ -65,58 +69,58 @@ final class OneSignalNotificationsTests: XCTestCase { // Ensure that badge count == 1 XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 1) } - - func testClearBadgesWhenAppEntersForeground1() throws { - // NotificationManager Start to register lifecycle listener - OSNotificationsManager.start() - // Set badge count > 0 - UIApplication.shared.applicationIconBadgeNumber = 1 - // Then background the app - OneSignalCoreMocks.backgroundApp() - // Foreground the app - OneSignalCoreMocks.foregroundApp() - // Ensure that badge count == 0 - XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 0) - } - - func testDontclearBadgesWhenAppBecomesActive2() throws { - // NotificationManager Start to register lifecycle listener - OSNotificationsManager.start() - // Set badge count > 0 - UIApplication.shared.applicationIconBadgeNumber = 1 - // Then resign active - OneSignalCoreMocks.resignActive() - // App becomes active the app - OneSignalCoreMocks.becomeActive() - // Ensure that badge count == 1 - XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 1) - } - - func testClearBadgesWhenAppEntersForeground3() throws { - // NotificationManager Start to register lifecycle listener - OSNotificationsManager.start() - // Set badge count > 0 - UIApplication.shared.applicationIconBadgeNumber = 1 - // Then background the app - OneSignalCoreMocks.backgroundApp() - // Foreground the app - OneSignalCoreMocks.foregroundApp() - // Ensure that badge count == 0 - XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 0) - } - - func testDontclearBadgesWhenAppBecomesActive4() throws { - // NotificationManager Start to register lifecycle listener - OSNotificationsManager.start() - // Set badge count > 0 - UIApplication.shared.applicationIconBadgeNumber = 1 - // Then resign active - OneSignalCoreMocks.resignActive() - // App becomes active the app - OneSignalCoreMocks.becomeActive() - // Ensure that badge count == 1 - XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 1) - } +// +// func testClearBadgesWhenAppEntersForeground1() throws { +// // NotificationManager Start to register lifecycle listener +// OSNotificationsManager.start() +// // Set badge count > 0 +// UIApplication.shared.applicationIconBadgeNumber = 1 +// // Then background the app +// OneSignalCoreMocks.backgroundApp() +// // Foreground the app +// OneSignalCoreMocks.foregroundApp() +// // Ensure that badge count == 0 +// XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 0) +// } +// +// func testDontclearBadgesWhenAppBecomesActive2() throws { +// // NotificationManager Start to register lifecycle listener +// OSNotificationsManager.start() +// // Set badge count > 0 +// UIApplication.shared.applicationIconBadgeNumber = 1 +// // Then resign active +// OneSignalCoreMocks.resignActive() +// // App becomes active the app +// OneSignalCoreMocks.becomeActive() +// // Ensure that badge count == 1 +// XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 1) +// } +// +// func testClearBadgesWhenAppEntersForeground3() throws { +// // NotificationManager Start to register lifecycle listener +// OSNotificationsManager.start() +// // Set badge count > 0 +// UIApplication.shared.applicationIconBadgeNumber = 1 +// // Then background the app +// OneSignalCoreMocks.backgroundApp() +// // Foreground the app +// OneSignalCoreMocks.foregroundApp() +// // Ensure that badge count == 0 +// XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 0) +// } +// +// func testDontclearBadgesWhenAppBecomesActive4() throws { +// // NotificationManager Start to register lifecycle listener +// OSNotificationsManager.start() +// // Set badge count > 0 +// UIApplication.shared.applicationIconBadgeNumber = 1 +// // Then resign active +// OneSignalCoreMocks.resignActive() +// // App becomes active the app +// OneSignalCoreMocks.becomeActive() +// // Ensure that badge count == 1 +// XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 1) +// } func testUpdateNotificationTypesOnAppEntersForeground() throws { // NotificationManager Start to register lifecycle listener From b216ffa154bef66c3aa04c21e5da4dc051faf8b3 Mon Sep 17 00:00:00 2001 From: Nan Date: Wed, 30 Oct 2024 16:10:26 -0700 Subject: [PATCH 4/4] Update OneSignalNotificationsTests.swift --- .../OneSignalNotificationsTests.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift b/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift index 972f50267..1b4ff49e3 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift @@ -46,13 +46,17 @@ final class OneSignalNotificationsTests: XCTestCase { // NotificationManager Start to register lifecycle listener OSNotificationsManager.start() // Set badge count > 0 - print("💛 testClearBadgesWhenAppEntersForeground setting applicationIconBadgeNumber") + print("💛 testClearBadgesWhenAppEntersForeground setting applicationIconBadgeNumber = 1") UIApplication.shared.applicationIconBadgeNumber = 1 + print("🥑 applicationIconBadgeNumber is \(UIApplication.shared.applicationIconBadgeNumber)") + // Then background the app OneSignalCoreMocks.backgroundApp() // Foreground the app OneSignalCoreMocks.foregroundApp() // Ensure that badge count == 0 + print("🥑 applicationIconBadgeNumber now is \(UIApplication.shared.applicationIconBadgeNumber)") + XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 0) } @@ -60,13 +64,17 @@ final class OneSignalNotificationsTests: XCTestCase { // NotificationManager Start to register lifecycle listener OSNotificationsManager.start() // Set badge count > 0 - print("💛 testDontclearBadgesWhenAppBecomesActive setting applicationIconBadgeNumber") + print("💛 testDontclearBadgesWhenAppBecomesActive setting applicationIconBadgeNumber = 1") UIApplication.shared.applicationIconBadgeNumber = 1 + print("🥑 applicationIconBadgeNumber is \(UIApplication.shared.applicationIconBadgeNumber)") + // Then resign active OneSignalCoreMocks.resignActive() // App becomes active the app OneSignalCoreMocks.becomeActive() // Ensure that badge count == 1 + print("🥑 applicationIconBadgeNumber now is \(UIApplication.shared.applicationIconBadgeNumber)") + XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 1) } //