From 6dfdfd8a32ebda233ff5fed8ec75777473b26cef Mon Sep 17 00:00:00 2001 From: Nan Date: Tue, 25 Jun 2024 10:48:04 -0700 Subject: [PATCH] [nit] run swiflint --- .../MockOSDispatchQueue.swift | 6 +++--- .../OneSignalCoreMocks/OneSignalCoreMocks.swift | 16 ++++++++-------- .../OneSignalNotificationsTests.swift | 17 ++++++++--------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalCoreMocks/MockOSDispatchQueue.swift b/iOS_SDK/OneSignalSDK/OneSignalCoreMocks/MockOSDispatchQueue.swift index b02525282..842dd1be8 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalCoreMocks/MockOSDispatchQueue.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalCoreMocks/MockOSDispatchQueue.swift @@ -30,7 +30,7 @@ import OneSignalOSCore public class MockDispatchQueue: OSDispatchQueue { let requestDispatch = DispatchQueue(label: "MockDispatchQueue") var numDispatches = 0 - + public init() {} public func async(execute work: @escaping @convention(block) () -> Void) { @@ -46,8 +46,8 @@ public class MockDispatchQueue: OSDispatchQueue { self.numDispatches += 1 } } - - public func waitForDispatches(_ numDispatches: Int) -> Void { + + public func waitForDispatches(_ numDispatches: Int) { while self.numDispatches < numDispatches { requestDispatch.sync { Thread.sleep(forTimeInterval: TimeInterval(1)) diff --git a/iOS_SDK/OneSignalSDK/OneSignalCoreMocks/OneSignalCoreMocks.swift b/iOS_SDK/OneSignalSDK/OneSignalCoreMocks/OneSignalCoreMocks.swift index 4e452adeb..75276eb68 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalCoreMocks/OneSignalCoreMocks.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalCoreMocks/OneSignalCoreMocks.swift @@ -51,9 +51,9 @@ public class OneSignalCoreMocks: NSObject { let expectation = XCTestExpectation(description: "Wait for \(seconds) seconds") _ = XCTWaiter.wait(for: [expectation], timeout: seconds) } - + @objc public static func backgroundApp() { - if (OSBundleUtils.isAppUsingUIScene()) { + if OSBundleUtils.isAppUsingUIScene() { if #available(iOS 13.0, *) { NotificationCenter.default.post(name: UIScene.willDeactivateNotification, object: nil) NotificationCenter.default.post(name: UIScene.didEnterBackgroundNotification, object: nil) @@ -63,9 +63,9 @@ public class OneSignalCoreMocks: NSObject { NotificationCenter.default.post(name: UIApplication.didEnterBackgroundNotification, object: nil) } } - + @objc public static func foregroundApp() { - if (OSBundleUtils.isAppUsingUIScene()) { + if OSBundleUtils.isAppUsingUIScene() { if #available(iOS 13.0, *) { NotificationCenter.default.post(name: UIScene.willEnterForegroundNotification, object: nil) NotificationCenter.default.post(name: UIScene.didActivateNotification, object: nil) @@ -75,9 +75,9 @@ public class OneSignalCoreMocks: NSObject { NotificationCenter.default.post(name: UIApplication.didBecomeActiveNotification, object: nil) } } - + @objc public static func resignActive() { - if (OSBundleUtils.isAppUsingUIScene()) { + if OSBundleUtils.isAppUsingUIScene() { if #available(iOS 13.0, *) { NotificationCenter.default.post(name: UIScene.willDeactivateNotification, object: nil) } @@ -85,9 +85,9 @@ public class OneSignalCoreMocks: NSObject { NotificationCenter.default.post(name: UIApplication.willResignActiveNotification, object: nil) } } - + @objc public static func becomeActive() { - if (OSBundleUtils.isAppUsingUIScene()) { + if OSBundleUtils.isAppUsingUIScene() { if #available(iOS 13.0, *) { NotificationCenter.default.post(name: UIScene.didActivateNotification, object: nil) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift b/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift index e452ae22e..e2f84df9d 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift @@ -12,7 +12,7 @@ import OneSignalCoreMocks import UIKit final class OneSignalNotificationsTests: XCTestCase { - + var notifTypes: Int32 = 0 var token: String = "" @@ -38,7 +38,7 @@ final class OneSignalNotificationsTests: XCTestCase { // Ensure that badge count == 0 XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 0) } - + func testDontclearBadgesWhenAppBecomesActive() throws { // NotificationManager Start to register lifecycle listener OSNotificationsManager.start() @@ -51,25 +51,24 @@ final class OneSignalNotificationsTests: XCTestCase { // Ensure that badge count == 0 XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 1) } - + func testUpdateNotificationTypesOnAppEntersForeground() throws { // NotificationManager Start to register lifecycle listener OSNotificationsManager.start() - + OSNotificationsManager.delegate = self - + XCTAssertEqual(self.notifTypes, 0) - + // Then background the app OneSignalCoreMocks.backgroundApp() - + // Foreground the app for within 30 seconds OneSignalCoreMocks.foregroundApp() - + // Ensure that the delegate is updated with the new notification type XCTAssertEqual(self.notifTypes, ERROR_PUSH_NEVER_PROMPTED) } - }