-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51a699d
commit b92af1d
Showing
3 changed files
with
57 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import XCTest | ||
@testable import IterableSDK | ||
|
||
class NotificationObserverTests: XCTestCase { | ||
private var internalAPI: InternalIterableAPI! | ||
private var mockNotificationStateProvider: MockNotificationStateProvider! | ||
private var mockLocalStorage: MockLocalStorage! | ||
private var mockNotificationCenter: MockNotificationCenter! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
mockNotificationStateProvider = MockNotificationStateProvider(enabled: false) | ||
mockLocalStorage = MockLocalStorage() | ||
mockNotificationCenter = MockNotificationCenter() | ||
|
||
let config = IterableConfig() | ||
internalAPI = InternalIterableAPI.initializeForTesting( | ||
config: config, | ||
notificationStateProvider: mockNotificationStateProvider, | ||
localStorage: mockLocalStorage, | ||
notificationCenter: mockNotificationCenter | ||
) | ||
} | ||
|
||
func testNotificationStateChangeUpdatesStorage() { | ||
// Arrange | ||
mockLocalStorage.isNotificationsEnabled = false | ||
mockNotificationStateProvider.enabled = true | ||
|
||
// Act | ||
mockNotificationCenter.post(name: UIApplication.didBecomeActiveNotification, object: nil, userInfo: nil) | ||
|
||
// Small delay to allow async operation to complete | ||
let expectation = XCTestExpectation(description: "Wait for state update") | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { | ||
expectation.fulfill() | ||
} | ||
wait(for: [expectation], timeout: 1.0) | ||
|
||
// Assert | ||
XCTAssertTrue(mockLocalStorage.isNotificationsEnabled) | ||
} | ||
} |