mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Removing Delivered Notifications (#1305)
* completed * changelog * tests * more tests * better naming * fix * a bit more waiting time * generated mocks * xcodegen
This commit is contained in:
@@ -14,9 +14,10 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import NotificationCenter
|
||||
import XCTest
|
||||
|
||||
import Combine
|
||||
@testable import ElementX
|
||||
|
||||
final class NotificationManagerTests: XCTestCase {
|
||||
@@ -176,6 +177,32 @@ final class NotificationManagerTests: XCTestCase {
|
||||
await notificationManager.userNotificationCenter(UNUserNotificationCenter.current(), didReceive: response)
|
||||
XCTAssertTrue(notificationTappedDelegateCalled)
|
||||
}
|
||||
|
||||
func test_MessageNotificationsRemoval() async throws {
|
||||
// No interaction if the object is nil or of the wrong type
|
||||
NotificationCenter.default.post(name: .roomMarkedAsRead, object: nil)
|
||||
try await Task.sleep(for: .microseconds(200))
|
||||
XCTAssertEqual(notificationCenter.deliveredNotificationsCallsCount, 0)
|
||||
XCTAssertEqual(notificationCenter.removeDeliveredNotificationsCallsCount, 0)
|
||||
|
||||
NotificationCenter.default.post(name: .roomMarkedAsRead, object: 1)
|
||||
try await Task.sleep(for: .microseconds(200))
|
||||
XCTAssertEqual(notificationCenter.deliveredNotificationsCallsCount, 0)
|
||||
XCTAssertEqual(notificationCenter.removeDeliveredNotificationsCallsCount, 0)
|
||||
|
||||
// The center calls the delivered and the removal functions when an id is passed
|
||||
NotificationCenter.default.post(name: .roomMarkedAsRead, object: "RoomID")
|
||||
try await Task.sleep(for: .microseconds(200))
|
||||
XCTAssertEqual(notificationCenter.deliveredNotificationsCallsCount, 1)
|
||||
XCTAssertEqual(notificationCenter.removeDeliveredNotificationsCallsCount, 1)
|
||||
}
|
||||
|
||||
func test_InvitesNotificationsRemoval() async throws {
|
||||
NotificationCenter.default.post(name: .invitesScreenAppeared, object: nil)
|
||||
try await Task.sleep(for: .microseconds(200))
|
||||
XCTAssertEqual(notificationCenter.deliveredNotificationsCallsCount, 1)
|
||||
XCTAssertEqual(notificationCenter.removeDeliveredNotificationsCallsCount, 1)
|
||||
}
|
||||
}
|
||||
|
||||
extension NotificationManagerTests: NotificationManagerDelegate {
|
||||
|
||||
@@ -17,9 +17,20 @@
|
||||
import Foundation
|
||||
import UserNotifications
|
||||
|
||||
class UserNotificationCenterSpy: UserNotificationCenterProtocol {
|
||||
final class UserNotificationCenterSpy: UserNotificationCenterProtocol {
|
||||
weak var delegate: UNUserNotificationCenterDelegate?
|
||||
|
||||
|
||||
var deliveredNotificationsCallsCount = 0
|
||||
func deliveredNotifications() async -> [UNNotification] {
|
||||
deliveredNotificationsCallsCount += 1
|
||||
return []
|
||||
}
|
||||
|
||||
var removeDeliveredNotificationsCallsCount = 0
|
||||
func removeDeliveredNotifications(withIdentifiers identifiers: [String]) {
|
||||
removeDeliveredNotificationsCallsCount += 1
|
||||
}
|
||||
|
||||
var addRequest: UNNotificationRequest?
|
||||
func add(_ request: UNNotificationRequest) async throws {
|
||||
addRequest = request
|
||||
|
||||
Reference in New Issue
Block a user