mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-07 04:48:34 +00:00
Unit test fixes (#1846)
* Prevent notification manager tests from failing during randomised testing * Fix flakey logging tests * Fix flakey room notification muting tests
This commit is contained in:
@@ -24,6 +24,9 @@ class LoggingTests: XCTestCase {
|
||||
}
|
||||
|
||||
override func setUpWithError() throws {
|
||||
// Force MXLogger to flush stderr and clean up after itself
|
||||
MXLog.configure(logLevel: .info, redirectToFiles: false)
|
||||
|
||||
MXLogger.deleteLogFiles()
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import XCTest
|
||||
|
||||
@testable import ElementX
|
||||
|
||||
@MainActor
|
||||
final class NotificationManagerTests: XCTestCase {
|
||||
var notificationManager: NotificationManager!
|
||||
private let clientProxy = MockClientProxy(userID: "@test:user.net")
|
||||
@@ -36,6 +37,8 @@ final class NotificationManagerTests: XCTestCase {
|
||||
override func setUp() {
|
||||
AppSettings.reset()
|
||||
notificationCenter = UserNotificationCenterMock()
|
||||
notificationCenter.requestAuthorizationOptionsReturnValue = true
|
||||
|
||||
notificationManager = NotificationManager(notificationCenter: notificationCenter, appSettings: appSettings)
|
||||
notificationManager.start()
|
||||
notificationManager.setUserSession(mockUserSession)
|
||||
@@ -65,7 +68,6 @@ final class NotificationManagerTests: XCTestCase {
|
||||
XCTAssertFalse(success)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func test_whenRegistered_pusherIsCalledWithCorrectValues() async throws {
|
||||
let pushkeyData = Data("1234".utf8)
|
||||
_ = await notificationManager.register(with: pushkeyData)
|
||||
@@ -95,7 +97,6 @@ final class NotificationManagerTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_whenRegisteredAndPusherTagIsSetInSettings_tagNotGenerated() async throws {
|
||||
notificationCenter.requestAuthorizationOptionsReturnValue = true
|
||||
appSettings.pusherProfileTag = "12345"
|
||||
_ = await notificationManager.register(with: Data())
|
||||
XCTAssertEqual(appSettings.pusherProfileTag, "12345")
|
||||
@@ -141,7 +142,6 @@ final class NotificationManagerTests: XCTestCase {
|
||||
|
||||
func test_whenStartAndAuthorizationGranted_delegateCalled() async throws {
|
||||
authorizationStatusWasGranted = false
|
||||
notificationCenter.requestAuthorizationOptionsReturnValue = true
|
||||
notificationManager.delegate = self
|
||||
let expectation: XCTestExpectation = expectation(description: "registerForRemoteNotifications delegate function should be called")
|
||||
expectation.assertForOverFulfill = false
|
||||
@@ -210,7 +210,6 @@ final class NotificationManagerTests: XCTestCase {
|
||||
|
||||
// The center calls the delivered and the removal functions when an id is passed
|
||||
notificationCenter.deliveredNotificationsClosure = nil
|
||||
notificationCenter.requestAuthorizationOptionsReturnValue = true
|
||||
notificationCenter.deliveredNotificationsReturnValue = []
|
||||
let expectation = expectation(description: "Notification should be removed")
|
||||
notificationCenter.removeDeliveredNotificationsWithIdentifiersClosure = { _ in
|
||||
@@ -224,7 +223,6 @@ final class NotificationManagerTests: XCTestCase {
|
||||
|
||||
func test_InvitesNotificationsRemoval() async {
|
||||
let expectation = expectation(description: "Notification should be removed")
|
||||
notificationCenter.requestAuthorizationOptionsReturnValue = true
|
||||
notificationCenter.deliveredNotificationsReturnValue = []
|
||||
notificationCenter.removeDeliveredNotificationsWithIdentifiersClosure = { _ in
|
||||
expectation.fulfill()
|
||||
|
||||
@@ -561,15 +561,18 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
|
||||
|
||||
XCTAssertFalse(context.viewState.isProcessingMuteToggleAction)
|
||||
|
||||
do {
|
||||
let deferred = deferFulfillment(context.$viewState) { state in
|
||||
state.notificationSettingsState.isLoaded
|
||||
let deferred = deferFulfillment(context.$viewState) { state in
|
||||
switch state.notificationSettingsState {
|
||||
case .loaded(settings: let settings):
|
||||
return settings.mode == .mute
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
notificationSettingsProxyMock.callbacks.send(.settingsDidChange)
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
|
||||
notificationSettingsProxyMock.callbacks.send(.settingsDidChange)
|
||||
try await deferred.fulfill()
|
||||
|
||||
if case .loaded(let newNotificationSettingsState) = viewModel.state.notificationSettingsState {
|
||||
XCTAssertFalse(newNotificationSettingsState.isDefault)
|
||||
XCTAssertEqual(newNotificationSettingsState.mode, .mute)
|
||||
@@ -591,15 +594,18 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
|
||||
|
||||
XCTAssertFalse(context.viewState.isProcessingMuteToggleAction)
|
||||
|
||||
do {
|
||||
let deferred = deferFulfillment(context.$viewState) { state in
|
||||
state.notificationSettingsState.isLoaded
|
||||
let deferred = deferFulfillment(context.$viewState) { state in
|
||||
switch state.notificationSettingsState {
|
||||
case .loaded(settings: let settings):
|
||||
return settings.mode == .allMessages
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
notificationSettingsProxyMock.callbacks.send(.settingsDidChange)
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
|
||||
notificationSettingsProxyMock.callbacks.send(.settingsDidChange)
|
||||
try await deferred.fulfill()
|
||||
|
||||
if case .loaded(let newNotificationSettingsState) = viewModel.state.notificationSettingsState {
|
||||
XCTAssertFalse(newNotificationSettingsState.isDefault)
|
||||
XCTAssertEqual(newNotificationSettingsState.mode, .allMessages)
|
||||
|
||||
Reference in New Issue
Block a user