generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BITAU-194] Fix issue with unit tests failing occasionally; Add tests…
… for NotifcationCenterService (#1099)
- Loading branch information
1 parent
b4df4c6
commit bc0356a
Showing
3 changed files
with
84 additions
and
4 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
52 changes: 52 additions & 0 deletions
52
BitwardenShared/Core/Platform/Services/NotificationCenterServiceTests.swift
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,52 @@ | ||
import XCTest | ||
|
||
@testable import BitwardenShared | ||
|
||
final class NotificationCenterServiceTests: BitwardenTestCase { | ||
// MARK: Properties | ||
|
||
var notificationCenter: NotificationCenter! | ||
var subject: DefaultNotificationCenterService! | ||
|
||
// MARK: Setup & Teardown | ||
|
||
override func setUp() { | ||
notificationCenter = NotificationCenter() | ||
subject = DefaultNotificationCenterService(notificationCenter: notificationCenter) | ||
} | ||
|
||
override func tearDown() { | ||
notificationCenter = nil | ||
subject = nil | ||
} | ||
|
||
// MARK: Tests | ||
|
||
/// `didEnterBackgroundPublisher` publishes a notification when the app enters the background. | ||
func testDidEnterBackgroundPublisher() async throws { | ||
var iterator = subject.didEnterBackgroundPublisher().makeAsyncIterator() | ||
Task { | ||
notificationCenter.post( | ||
name: UIApplication.didEnterBackgroundNotification, | ||
object: nil | ||
) | ||
} | ||
let result: Void? = await iterator.next() | ||
|
||
XCTAssertNotNil(result) | ||
} | ||
|
||
/// `willEnterForegroundPublisher` publishes a notification when the app will enter the foreground. | ||
func testWillEnterForegroundPublisher() async throws { | ||
var iterator = subject.willEnterForegroundPublisher().makeAsyncIterator() | ||
Task { | ||
notificationCenter.post( | ||
name: UIApplication.willEnterForegroundNotification, | ||
object: nil | ||
) | ||
} | ||
let result: Void? = await iterator.next() | ||
|
||
XCTAssertNotNil(result) | ||
} | ||
} |