Skip to content

Commit

Permalink
Fix Sync E2E tests crashing (#3002)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1199230911884351/1207860806206145/f

Description:
This change fixes UpdateController usage so that it's not references in UI tests runs.
  • Loading branch information
ayoy authored Jul 22, 2024
1 parent 0af2b8f commit 0a259e9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
4 changes: 3 additions & 1 deletion DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
setUpAutofillPixelReporter()

#if SPARKLE
updateController.checkNewApplicationVersion()
if NSApp.runType != .uiTests {
updateController.checkNewApplicationVersion()
}
#endif

remoteMessagingClient?.startRefreshingRemoteMessages()
Expand Down
11 changes: 7 additions & 4 deletions DuckDuckGo/NavigationBar/View/MoreOptionsMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,14 @@ final class MoreOptionsMenu: NSMenu {

private func addUpdateItem() {
#if SPARKLE
if let update = Application.appDelegate.updateController.latestUpdate,
!update.isInstalled {
addItem(UpdateMenuItemFactory.menuItem(for: update))
addItem(NSMenuItem.separator())
guard NSApp.runType != .uiTests,
let update = Application.appDelegate.updateController.latestUpdate,
!update.isInstalled
else {
return
}
addItem(UpdateMenuItemFactory.menuItem(for: update))
addItem(NSMenuItem.separator())
#endif
}

Expand Down
4 changes: 3 additions & 1 deletion DuckDuckGo/NavigationBar/View/MoreOptionsMenuButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ final class MoreOptionsMenuButton: MouseOverButton {
super.awakeFromNib()

#if SPARKLE
updateController = Application.appDelegate.updateController
if NSApp.runType != .uiTests {
updateController = Application.appDelegate.updateController
}
#endif
subscribeToUpdateInfo()
}
Expand Down
3 changes: 3 additions & 0 deletions DuckDuckGo/Updates/ReleaseNotesTabExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ final class ReleaseNotesTabExtension: NavigationResponder {

@MainActor
private func setUpScript(for url: URL?) {
guard NSApp.runType != .uiTests else {
return
}
let updateController = Application.appDelegate.updateController!
Publishers.CombineLatest(updateController.isUpdateBeingLoadedPublisher, updateController.latestUpdatePublisher)
.receive(on: DispatchQueue.main)
Expand Down
3 changes: 3 additions & 0 deletions DuckDuckGo/Updates/ReleaseNotesUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ final class ReleaseNotesUserScript: NSObject, Subfeature {
}

public func onUpdate() {
guard NSApp.runType != .uiTests else {
return
}
guard let webView = webView else {
return assertionFailure("Could not access webView")
}
Expand Down

0 comments on commit 0a259e9

Please sign in to comment.