From 7398517a2f7c2240d83547d0f351012dbe34ec39 Mon Sep 17 00:00:00 2001 From: Nan Date: Wed, 30 Oct 2024 11:24:00 -0700 Subject: [PATCH] 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 +}