Skip to content

Commit

Permalink
symplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SabrinaTardio committed May 8, 2024
1 parent 65a3bd1 commit 06b3c22
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 208 deletions.
23 changes: 14 additions & 9 deletions DuckDuckGo/Common/Utilities/AlertPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,26 @@
import Foundation

public protocol AlertPresenting {
func showAlert(_ alert: NSAlert)
func showSyncPausedAlert(title: String, informative: String)
}

public struct StandardAlertPresenter: AlertPresenting {
public init () {}
@MainActor
public func showAlert(_ alert: NSAlert) {
let response = alert.runModal()
public func showSyncPausedAlert(title: String, informative: String) {
Task {
await MainActor.run {
let alert = NSAlert.syncPaused(title: title, informative: informative)
let response = alert.runModal()

switch response {
case .alertSecondButtonReturn:
alert.window.sheetParent?.endSheet(alert.window)
WindowControllersManager.shared.showPreferencesTab(withSelectedPane: .sync)
default:
break
switch response {
case .alertSecondButtonReturn:
alert.window.sheetParent?.endSheet(alert.window)
WindowControllersManager.shared.showPreferencesTab(withSelectedPane: .sync)
default:
break
}
}
}
}
}
56 changes: 25 additions & 31 deletions DuckDuckGo/Sync/SyncErrorHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,37 +301,31 @@ extension SyncErrorHandler: SyncErrorHandling {

// swiftlint:disable:next cyclomatic_complexity
private func showSyncPausedAlertIfNeeded(for errorType: AsyncErrorType) {
Task {
await MainActor.run {
var alert: NSAlert
switch errorType {
case .bookmarksCountLimitExceeded, .bookmarksRequestSizeLimitExceeded:
guard !didShowBookmarksSyncPausedError else { return }
alert = NSAlert.syncPaused(title: UserText.syncBookmarkPausedAlertTitle, informative: UserText.syncBookmarkPausedAlertDescription)
didShowBookmarksSyncPausedError = true
case .credentialsCountLimitExceeded, .credentialsRequestSizeLimitExceeded:
guard !didShowCredentialsSyncPausedError else { return }
alert = NSAlert.syncPaused(title: UserText.syncCredentialsPausedAlertTitle, informative: UserText.syncCredentialsPausedAlertDescription)
didShowCredentialsSyncPausedError = true
case .badRequestBookmarks:
guard !didShowBookmarksSyncPausedError else { return }
alert = NSAlert.syncPaused(title: UserText.syncBookmarkPausedAlertTitle, informative: UserText.syncBookmarksBadRequestAlertDescription)
didShowBookmarksSyncPausedError = true
case .badRequestCredentials:
guard !didShowCredentialsSyncPausedError else { return }
alert = NSAlert.syncPaused(title: UserText.syncBookmarkPausedAlertTitle, informative: UserText.syncCredentialsBadRequestAlertDescription)
didShowCredentialsSyncPausedError = true
case .invalidLoginCredentials:
guard !didShowInvalidLoginSyncPausedError else { return }
alert = NSAlert.syncPaused(title: UserText.syncPausedAlertTitle, informative: UserText.syncInvalidLoginAlertDescription)
didShowInvalidLoginSyncPausedError = true
case .tooManyRequests:
guard shouldShowAlertForNonActionableError() == true else { return }
alert = NSAlert.syncPaused(title: UserText.syncErrorAlertTitle, informative: UserText.syncTooManyRequestsAlertDescription)
lastErrorNotificationTime = Date()
}
alertPresenter.showAlert(alert)
}
switch errorType {
case .bookmarksCountLimitExceeded, .bookmarksRequestSizeLimitExceeded:
guard !didShowBookmarksSyncPausedError else { return }
alertPresenter.showSyncPausedAlert(title: UserText.syncBookmarkPausedAlertTitle, informative: UserText.syncBookmarkPausedAlertDescription)
didShowBookmarksSyncPausedError = true
case .credentialsCountLimitExceeded, .credentialsRequestSizeLimitExceeded:
guard !didShowCredentialsSyncPausedError else { return }
alertPresenter.showSyncPausedAlert(title: UserText.syncCredentialsPausedAlertTitle, informative: UserText.syncCredentialsPausedAlertDescription)
didShowCredentialsSyncPausedError = true
case .badRequestBookmarks:
guard !didShowBookmarksSyncPausedError else { return }
alertPresenter.showSyncPausedAlert(title: UserText.syncBookmarkPausedAlertTitle, informative: UserText.syncBookmarksBadRequestAlertDescription)
didShowBookmarksSyncPausedError = true
case .badRequestCredentials:
guard !didShowCredentialsSyncPausedError else { return }
alertPresenter.showSyncPausedAlert(title: UserText.syncBookmarkPausedAlertTitle, informative: UserText.syncCredentialsBadRequestAlertDescription)
didShowCredentialsSyncPausedError = true
case .invalidLoginCredentials:
guard !didShowInvalidLoginSyncPausedError else { return }
alertPresenter.showSyncPausedAlert(title: UserText.syncPausedAlertTitle, informative: UserText.syncInvalidLoginAlertDescription)
didShowInvalidLoginSyncPausedError = true
case .tooManyRequests:
guard shouldShowAlertForNonActionableError() == true else { return }
alertPresenter.showSyncPausedAlert(title: UserText.syncErrorAlertTitle, informative: UserText.syncTooManyRequestsAlertDescription)
lastErrorNotificationTime = Date()
}
}

Expand Down
Loading

0 comments on commit 06b3c22

Please sign in to comment.