Skip to content

Commit

Permalink
[nit] run swiflint
Browse files Browse the repository at this point in the history
  • Loading branch information
nan-li committed Jun 25, 2024
1 parent 22ecd89 commit a6b5ed5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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))
Expand Down
16 changes: 8 additions & 8 deletions iOS_SDK/OneSignalSDK/OneSignalCoreMocks/OneSignalCoreMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -75,19 +75,19 @@ 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)
}
} else {
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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import OneSignalCoreMocks
import UIKit

final class OneSignalNotificationsTests: XCTestCase {

var notifTypes: Int32 = 0
var token: String = ""

Expand All @@ -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()
Expand All @@ -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)
}


}

Expand Down

0 comments on commit a6b5ed5

Please sign in to comment.