mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Attempt to improve unit test reliability:
- synchronize mock properties on the main queue - sleep for longer when processing routes - finish encoding before deallocating the keyed archiver - wait for NotificationCenter notifications to be delivered - change were we process remote notification permissions
This commit is contained in:
committed by
Stefan Ceriu
parent
da598302df
commit
7645971812
@@ -17,6 +17,10 @@
|
||||
import Foundation
|
||||
|
||||
final class MockCoder: NSKeyedArchiver {
|
||||
deinit {
|
||||
finishEncoding()
|
||||
}
|
||||
|
||||
override func decodeObject(forKey _: String) -> Any { "" }
|
||||
override func decodeInt64(forKey key: String) -> Int64 { 0 }
|
||||
}
|
||||
|
||||
@@ -212,10 +212,14 @@ final class NotificationManagerTests: XCTestCase {
|
||||
}
|
||||
// No interaction if the object is nil or of the wrong type
|
||||
NotificationCenter.default.post(name: .roomMarkedAsRead, object: nil)
|
||||
try? await Task.sleep(for: .seconds(0.25)) // Wait for the notification to be delivered
|
||||
|
||||
XCTAssertEqual(notificationCenter.deliveredNotificationsCallsCount, 0)
|
||||
XCTAssertEqual(notificationCenter.removeDeliveredNotificationsWithIdentifiersCallsCount, 0)
|
||||
|
||||
NotificationCenter.default.post(name: .roomMarkedAsRead, object: 1)
|
||||
try? await Task.sleep(for: .seconds(0.25)) // Wait for the notification to be delivered
|
||||
|
||||
XCTAssertEqual(notificationCenter.deliveredNotificationsCallsCount, 0)
|
||||
XCTAssertEqual(notificationCenter.removeDeliveredNotificationsWithIdentifiersCallsCount, 0)
|
||||
|
||||
@@ -226,7 +230,10 @@ final class NotificationManagerTests: XCTestCase {
|
||||
notificationCenter.removeDeliveredNotificationsWithIdentifiersClosure = { _ in
|
||||
expectation.fulfill()
|
||||
}
|
||||
|
||||
NotificationCenter.default.post(name: .roomMarkedAsRead, object: "RoomID")
|
||||
try? await Task.sleep(for: .seconds(0.25)) // Wait for the notification to be delivered
|
||||
|
||||
await fulfillment(of: [expectation])
|
||||
XCTAssertEqual(notificationCenter.deliveredNotificationsCallsCount, 1)
|
||||
XCTAssertEqual(notificationCenter.removeDeliveredNotificationsWithIdentifiersCallsCount, 1)
|
||||
@@ -238,7 +245,10 @@ final class NotificationManagerTests: XCTestCase {
|
||||
notificationCenter.removeDeliveredNotificationsWithIdentifiersClosure = { _ in
|
||||
expectation.fulfill()
|
||||
}
|
||||
|
||||
NotificationCenter.default.post(name: .invitesScreenAppeared, object: nil)
|
||||
try? await Task.sleep(for: .seconds(0.25)) // Wait for the notification to be delivered
|
||||
|
||||
await fulfillment(of: [expectation])
|
||||
XCTAssertEqual(notificationCenter.deliveredNotificationsCallsCount, 1)
|
||||
XCTAssertEqual(notificationCenter.removeDeliveredNotificationsWithIdentifiersCallsCount, 1)
|
||||
|
||||
@@ -155,12 +155,8 @@ class RoomFlowCoordinatorTests: XCTestCase {
|
||||
|
||||
private func process(route: AppRoute) async throws {
|
||||
roomFlowCoordinator.handleAppRoute(route, animated: true)
|
||||
if case .childRoom = route {
|
||||
// A single yield isn't enough when creating the new flow coordinator.
|
||||
try await Task.sleep(for: .milliseconds(100))
|
||||
} else {
|
||||
await Task.yield()
|
||||
}
|
||||
// A single yield isn't enough when creating the new flow coordinator.
|
||||
try await Task.sleep(for: .milliseconds(100))
|
||||
}
|
||||
|
||||
private func process(route: AppRoute, expectedAction: RoomFlowCoordinatorAction) async throws {
|
||||
|
||||
Reference in New Issue
Block a user