Skip to content

Commit

Permalink
Fix displaying more options menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Nov 4, 2024
1 parent badd9cf commit b3b31fe
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 52 deletions.
15 changes: 6 additions & 9 deletions DuckDuckGo/NavigationBar/View/MoreOptionsMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ final class MoreOptionsMenu: NSMenu, NSMenuDelegate {
}

let zoomMenuItem = NSMenuItem(title: UserText.zoom, action: nil, keyEquivalent: "").withImage(.optionsButtonMenuZoom)
private(set) lazy var setAsDefaultMenuItem = NSMenuItem(title: UserText.setAsDefaultBrowser, action: #selector(setAsDefault(_:)), target: self)
.withImage(.defaultBrowserMenuItem)

@MainActor
private func setupMenuItems() {
Expand All @@ -152,7 +150,12 @@ final class MoreOptionsMenu: NSMenu, NSMenuDelegate {

#endif // FEEDBACK

addItem(setAsDefaultMenuItem)
if !defaultBrowserPreferences.isDefault {
let setAsDefaultMenuItem = NSMenuItem(title: UserText.setAsDefaultBrowser, action: #selector(setAsDefault(_:)))
.targetting(self)
.withImage(.defaultBrowserMenuItem)
addItem(setAsDefaultMenuItem)
}

addItem(NSMenuItem.separator())

Expand Down Expand Up @@ -185,12 +188,6 @@ final class MoreOptionsMenu: NSMenu, NSMenuDelegate {
addItem(preferencesItem)
}

override func update() {
super.update()

setAsDefaultMenuItem.isHidden = defaultBrowserPreferences.isDefault
}

@objc func openDataBrokerProtection(_ sender: NSMenuItem) {
actionDelegate?.optionsButtonMenuRequestedDataBrokerProtection(self)
}
Expand Down
82 changes: 39 additions & 43 deletions UnitTests/Menus/MoreOptionsMenuTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,24 @@ final class MoreOptionsMenuTests: XCTestCase {
XCTAssertTrue(subscriptionManager.canPurchase)

XCTAssertEqual(moreOptionsMenu.items[0].title, UserText.sendFeedback)
XCTAssertEqual(moreOptionsMenu.items[1].title, UserText.setAsDefaultBrowser)
XCTAssertTrue(moreOptionsMenu.items[2].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[3].title, UserText.plusButtonNewTabMenuItem)
XCTAssertEqual(moreOptionsMenu.items[4].title, UserText.newWindowMenuItem)
XCTAssertEqual(moreOptionsMenu.items[5].title, UserText.newBurnerWindowMenuItem)
XCTAssertTrue(moreOptionsMenu.items[6].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[7].title, UserText.zoom)
XCTAssertTrue(moreOptionsMenu.items[8].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[9].title, UserText.bookmarks)
XCTAssertEqual(moreOptionsMenu.items[10].title, UserText.downloads)
XCTAssertEqual(moreOptionsMenu.items[11].title, UserText.passwordManagementTitle)
XCTAssertTrue(moreOptionsMenu.items[12].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[13].title, UserText.emailOptionsMenuItem)
XCTAssertTrue(moreOptionsMenu.items[14].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[15].title, UserText.subscriptionOptionsMenuItem)
XCTAssertFalse(moreOptionsMenu.items[15].hasSubmenu)
XCTAssertTrue(moreOptionsMenu.items[16].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[17].title, UserText.mainMenuHelp)
XCTAssertEqual(moreOptionsMenu.items[18].title, UserText.settings)
XCTAssertTrue(moreOptionsMenu.items[1].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[2].title, UserText.plusButtonNewTabMenuItem)
XCTAssertEqual(moreOptionsMenu.items[3].title, UserText.newWindowMenuItem)
XCTAssertEqual(moreOptionsMenu.items[4].title, UserText.newBurnerWindowMenuItem)
XCTAssertTrue(moreOptionsMenu.items[5].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[6].title, UserText.zoom)
XCTAssertTrue(moreOptionsMenu.items[7].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[8].title, UserText.bookmarks)
XCTAssertEqual(moreOptionsMenu.items[9].title, UserText.downloads)
XCTAssertEqual(moreOptionsMenu.items[10].title, UserText.passwordManagementTitle)
XCTAssertTrue(moreOptionsMenu.items[11].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[12].title, UserText.emailOptionsMenuItem)
XCTAssertTrue(moreOptionsMenu.items[13].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[14].title, UserText.subscriptionOptionsMenuItem)
XCTAssertFalse(moreOptionsMenu.items[14].hasSubmenu)
XCTAssertTrue(moreOptionsMenu.items[15].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[16].title, UserText.mainMenuHelp)
XCTAssertEqual(moreOptionsMenu.items[17].title, UserText.settings)
}

@MainActor
Expand All @@ -192,26 +191,25 @@ final class MoreOptionsMenuTests: XCTestCase {
XCTAssertTrue(subscriptionManager.canPurchase)

XCTAssertEqual(moreOptionsMenu.items[0].title, UserText.sendFeedback)
XCTAssertEqual(moreOptionsMenu.items[1].title, UserText.setAsDefaultBrowser)
XCTAssertTrue(moreOptionsMenu.items[2].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[3].title, UserText.plusButtonNewTabMenuItem)
XCTAssertEqual(moreOptionsMenu.items[4].title, UserText.newWindowMenuItem)
XCTAssertEqual(moreOptionsMenu.items[5].title, UserText.newBurnerWindowMenuItem)
XCTAssertTrue(moreOptionsMenu.items[6].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[7].title, UserText.zoom)
XCTAssertTrue(moreOptionsMenu.items[8].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[9].title, UserText.bookmarks)
XCTAssertEqual(moreOptionsMenu.items[10].title, UserText.downloads)
XCTAssertEqual(moreOptionsMenu.items[11].title, UserText.passwordManagementTitle)
XCTAssertTrue(moreOptionsMenu.items[12].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[13].title, UserText.emailOptionsMenuItem)
XCTAssertTrue(moreOptionsMenu.items[14].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[15].title, UserText.subscriptionOptionsMenuItem)
XCTAssertFalse(moreOptionsMenu.items[15].hasSubmenu)
XCTAssertEqual(moreOptionsMenu.items[16].title, UserText.freemiumDBPOptionsMenuItem)
XCTAssertTrue(moreOptionsMenu.items[17].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[18].title, UserText.mainMenuHelp)
XCTAssertEqual(moreOptionsMenu.items[19].title, UserText.settings)
XCTAssertTrue(moreOptionsMenu.items[1].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[2].title, UserText.plusButtonNewTabMenuItem)
XCTAssertEqual(moreOptionsMenu.items[3].title, UserText.newWindowMenuItem)
XCTAssertEqual(moreOptionsMenu.items[4].title, UserText.newBurnerWindowMenuItem)
XCTAssertTrue(moreOptionsMenu.items[5].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[6].title, UserText.zoom)
XCTAssertTrue(moreOptionsMenu.items[7].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[8].title, UserText.bookmarks)
XCTAssertEqual(moreOptionsMenu.items[9].title, UserText.downloads)
XCTAssertEqual(moreOptionsMenu.items[10].title, UserText.passwordManagementTitle)
XCTAssertTrue(moreOptionsMenu.items[11].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[12].title, UserText.emailOptionsMenuItem)
XCTAssertTrue(moreOptionsMenu.items[13].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[14].title, UserText.subscriptionOptionsMenuItem)
XCTAssertFalse(moreOptionsMenu.items[14].hasSubmenu)
XCTAssertEqual(moreOptionsMenu.items[15].title, UserText.freemiumDBPOptionsMenuItem)
XCTAssertTrue(moreOptionsMenu.items[16].isSeparatorItem)
XCTAssertEqual(moreOptionsMenu.items[17].title, UserText.mainMenuHelp)
XCTAssertEqual(moreOptionsMenu.items[18].title, UserText.settings)
}

@MainActor
Expand Down Expand Up @@ -288,7 +286,7 @@ final class MoreOptionsMenuTests: XCTestCase {
setupMoreOptionsMenu()

// GIVEN
let bookmarksMenu = try XCTUnwrap(moreOptionsMenu.item(at: 9)?.submenu)
let bookmarksMenu = try XCTUnwrap(moreOptionsMenu.item(at: 8)?.submenu)
let bookmarkAllTabsIndex = try XCTUnwrap(bookmarksMenu.indexOfItem(withTitle: UserText.bookmarkAllTabs))
let bookmarkAllTabsMenuItem = try XCTUnwrap(bookmarksMenu.items[bookmarkAllTabsIndex])
bookmarkAllTabsMenuItem.isEnabled = true
Expand All @@ -309,8 +307,7 @@ final class MoreOptionsMenuTests: XCTestCase {
setupMoreOptionsMenu()
moreOptionsMenu.update()

XCTAssertEqual(moreOptionsMenu.items[1].title, UserText.setAsDefaultBrowser)
XCTAssertTrue(moreOptionsMenu.items[1].isHidden)
XCTAssertNotEqual(moreOptionsMenu.items[1].title, UserText.setAsDefaultBrowser)
}

@MainActor
Expand All @@ -321,7 +318,6 @@ final class MoreOptionsMenuTests: XCTestCase {
moreOptionsMenu.update()

XCTAssertEqual(moreOptionsMenu.items[1].title, UserText.setAsDefaultBrowser)
XCTAssertFalse(moreOptionsMenu.items[1].isHidden)
}
}

Expand Down

0 comments on commit b3b31fe

Please sign in to comment.