Skip to content

Commit

Permalink
Adds a series of UI tests for Bookmarks and Favorites
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1199230911884351/1205717021705367/f
Tech Design URL:
CC:

**Description**: Adds a series of UI tests for Bookmarks and Favorites

**Steps to test this PR**:
1. Open the scheme **UI Tests**
2. Navigate to the test pane
3. Run BookmarksAndFavoritesTests

**Note**: If this builds a `review` build that is treated as a first run
on your system during every test (for instance, asking you where to put
the application), please **build and run** the scheme once instead of
running its tests, and go through the new app install first run steps
once before running the tests, and answer any first install questions.

**UI Tests general guidelines for everyone**: it unfortunately isn't
possible to multitask while running UI tests on your local machine,
because you will change or intercept screen interactions that the tests
depend on. If you experience failures in your local environment, please
always send the `xcresult` bundle so it is possible to view what
happened differently on your machine, even if it seems like the same
failure as a previous failure (it may be subtly different). Since the
`xcresult` bundle will include a screen recording, for your privacy,
please consider things like your chats, calls, and open documents that
you don't want to send in a screen recording when you are running the
tests. Thank you very much for your help!
  • Loading branch information
Halle authored Apr 9, 2024
1 parent 773d073 commit 5be1c5a
Show file tree
Hide file tree
Showing 17 changed files with 780 additions and 17 deletions.
4 changes: 4 additions & 0 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3291,6 +3291,7 @@
EE339228291BDEFD009F62C1 /* JSAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE339227291BDEFD009F62C1 /* JSAlertController.swift */; };
EE3424602BA0853900173B1B /* VPNUninstaller.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE34245D2BA0853900173B1B /* VPNUninstaller.swift */; };
EE3424612BA0853900173B1B /* VPNUninstaller.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE34245D2BA0853900173B1B /* VPNUninstaller.swift */; };
EE54F7B32BBFEA49006218DB /* BookmarksAndFavoritesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE54F7B22BBFEA48006218DB /* BookmarksAndFavoritesTests.swift */; };
EE66418C2B9B1981005BCD17 /* NetworkProtectionTokenStore+SubscriptionTokenKeychainStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE66418B2B9B1981005BCD17 /* NetworkProtectionTokenStore+SubscriptionTokenKeychainStorage.swift */; };
EE66418D2B9B1981005BCD17 /* NetworkProtectionTokenStore+SubscriptionTokenKeychainStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE66418B2B9B1981005BCD17 /* NetworkProtectionTokenStore+SubscriptionTokenKeychainStorage.swift */; };
EE66666F2B56EDE4001D898D /* VPNLocationsHostingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE66666E2B56EDE4001D898D /* VPNLocationsHostingViewController.swift */; };
Expand Down Expand Up @@ -4772,6 +4773,7 @@
EE0429DF2BA31D2F009EB20F /* FindInPageTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FindInPageTests.swift; sourceTree = "<group>"; };
EE339227291BDEFD009F62C1 /* JSAlertController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSAlertController.swift; sourceTree = "<group>"; };
EE34245D2BA0853900173B1B /* VPNUninstaller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNUninstaller.swift; sourceTree = "<group>"; };
EE54F7B22BBFEA48006218DB /* BookmarksAndFavoritesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BookmarksAndFavoritesTests.swift; sourceTree = "<group>"; };
EE66418B2B9B1981005BCD17 /* NetworkProtectionTokenStore+SubscriptionTokenKeychainStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NetworkProtectionTokenStore+SubscriptionTokenKeychainStorage.swift"; sourceTree = "<group>"; };
EE66666E2B56EDE4001D898D /* VPNLocationsHostingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNLocationsHostingViewController.swift; sourceTree = "<group>"; };
EE7F74902BB5D76600CD9456 /* BookmarksBarTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BookmarksBarTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6556,6 +6558,7 @@
children = (
EEBCE6802BA444FA00B9DF00 /* Common */,
EED735352BB46B6000F173D6 /* AutocompleteTests.swift */,
EE54F7B22BBFEA48006218DB /* BookmarksAndFavoritesTests.swift */,
EE7F74902BB5D76600CD9456 /* BookmarksBarTests.swift */,
EE02D41B2BB460A600DBE6B3 /* BrowsingHistoryTests.swift */,
EE0429DF2BA31D2F009EB20F /* FindInPageTests.swift */,
Expand Down Expand Up @@ -12279,6 +12282,7 @@
EE02D41A2BB4609900DBE6B3 /* UITests.swift in Sources */,
EE0429E02BA31D2F009EB20F /* FindInPageTests.swift in Sources */,
EE02D4212BB460FE00DBE6B3 /* StringExtension.swift in Sources */,
EE54F7B32BBFEA49006218DB /* BookmarksAndFavoritesTests.swift in Sources */,
EE02D4222BB4611A00DBE6B3 /* TestsURLExtension.swift in Sources */,
7B4CE8E726F02135009134B1 /* TabBarTests.swift in Sources */,
EEBCE6832BA463DD00B9DF00 /* NSImageExtensions.swift in Sources */,
Expand Down
5 changes: 5 additions & 0 deletions DuckDuckGo/Bookmarks/Services/ContextualMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,15 @@ private extension ContextualMenu {
static func addBookmarkToFavoritesMenuItem(isFavorite: Bool, bookmark: Bookmark?) -> NSMenuItem {
let title = isFavorite ? UserText.removeFromFavorites : UserText.addToFavorites
return menuItem(title, #selector(BookmarkMenuItemSelectors.toggleBookmarkAsFavorite(_:)), bookmark)
.withAccessibilityIdentifier(isFavorite == false ? "ContextualMenu.addBookmarkToFavoritesMenuItem" :
"ContextualMenu.removeBookmarkFromFavoritesMenuItem")
}

static func addBookmarksToFavoritesMenuItem(bookmarks: [Bookmark], allFavorites: Bool) -> NSMenuItem {
let title = allFavorites ? UserText.removeFromFavorites : UserText.addToFavorites
let accessibilityValue = allFavorites ? "Favorited" : "Unfavorited"
return menuItem(title, #selector(BookmarkMenuItemSelectors.toggleBookmarkAsFavorite(_:)), bookmarks)
.withAccessibilityIdentifier("ContextualMenu.addBookmarksToFavoritesMenuItem").withAccessibilityValue(accessibilityValue)
}

static func editBookmarkMenuItem(bookmark: Bookmark?) -> NSMenuItem {
Expand All @@ -180,6 +184,7 @@ private extension ContextualMenu {

static func deleteBookmarkMenuItem(bookmark: Bookmark?) -> NSMenuItem {
menuItem(UserText.bookmarksBarContextMenuDelete, #selector(BookmarkMenuItemSelectors.deleteBookmark(_:)), bookmark)
.withAccessibilityIdentifier("ContextualMenu.deleteBookmark")
}

static func moveToEndMenuItem(entity: BaseBookmarkEntity?, parent: BookmarkFolder?) -> NSMenuItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ final class BookmarkManagementSidebarViewController: NSViewController {
tabSwitcherButton.menu = NSMenu {
for content in Tab.TabContent.displayableTabTypes {
NSMenuItem(title: content.title!, representedObject: content)
.withAccessibilityIdentifier("BookmarkManagementSidebarViewController.\(content.title!)")
}
}

Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/Bookmarks/View/BookmarkOutlineCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ final class BookmarkOutlineCellView: NSTableCellView {
faviconImageView.imageScaling = .scaleProportionallyDown
faviconImageView.wantsLayer = true
faviconImageView.layer?.cornerRadius = 2.0
faviconImageView.setAccessibilityIdentifier("BookmarkOutlineCellView.favIconImageView")

titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.isEditable = false
Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/Bookmarks/View/BookmarkTableCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ final class BookmarkTableCellView: NSTableCellView {
menuButton.translatesAutoresizingMaskIntoConstraints = false
menuButton.isBordered = false
menuButton.isHidden = true
menuButton.setAccessibilityIdentifier("BookmarkTableCellView.menuButton")
}

private func setupLayout() {
Expand Down Expand Up @@ -209,11 +210,14 @@ final class BookmarkTableCellView: NSTableCellView {

faviconImageView.image = bookmark.favicon(.small) ?? .bookmarkDefaultFavicon

faviconImageView.setAccessibilityIdentifier("BookmarkTableCellView.favIconImageView")
if bookmark.isFavorite {
accessoryImageView.isHidden = false
}

accessoryImageView.image = bookmark.isFavorite ? .favoriteFilledBorder : nil
accessoryImageView.setAccessibilityIdentifier("BookmarkTableCellView.accessoryImageView")
accessoryImageView.setAccessibilityValue(bookmark.isFavorite ? "Favorited" : "Unfavorited")
titleLabel.stringValue = bookmark.title
primaryTitleLabelValue = bookmark.title
tertiaryTitleLabelValue = bookmark.url
Expand Down
5 changes: 5 additions & 0 deletions DuckDuckGo/Common/Extensions/NSMenuItemExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ extension NSMenuItem {
return self
}

func withAccessibilityValue(_ accessibilityValue: String) -> NSMenuItem {
self.setAccessibilityValue(accessibilityValue)
return self
}

@discardableResult
func withImage(_ image: NSImage?) -> NSMenuItem {
self.image = image
Expand Down
16 changes: 8 additions & 8 deletions DuckDuckGo/HomePage/View/FavoritesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,12 @@ struct Favorite: View {
.link {
model.open(bookmark)
}.contextMenu(ContextMenu(menuItems: {
Button(UserText.openInNewTab, action: { model.openInNewTab(bookmark) })
Button(UserText.openInNewWindow, action: { model.openInNewWindow(bookmark) })
Button(UserText.openInNewTab, action: { model.openInNewTab(bookmark) }).accessibilityIdentifier("HomePage.Views.openInNewTab")
Button(UserText.openInNewWindow, action: { model.openInNewWindow(bookmark) }).accessibilityIdentifier("HomePage.Views.openInNewWindow")
Divider()
Button(UserText.edit, action: { model.edit(bookmark) })
Button(UserText.removeFavorite, action: { model.removeFavorite(bookmark) })
Button(UserText.deleteBookmark, action: { model.deleteBookmark(bookmark) })
Button(UserText.edit, action: { model.edit(bookmark) }).accessibilityIdentifier("HomePage.Views.editBookmark")
Button(UserText.removeFavorite, action: { model.removeFavorite(bookmark) }).accessibilityIdentifier("HomePage.Views.removeFavorite")
Button(UserText.deleteBookmark, action: { model.deleteBookmark(bookmark) }).accessibilityIdentifier("HomePage.Views.deleteBookmark")
}))

}
Expand All @@ -344,13 +344,13 @@ extension HomePage.Models.FavoriteModel {
var favoriteView: some View {
switch favoriteType {
case .bookmark(let bookmark):
HomePage.Views.Favorite(bookmark: bookmark)
HomePage.Views.Favorite(bookmark: bookmark)?.accessibilityIdentifier("HomePage.Models.FavoriteModel.\(bookmark.title)")

case .addButton:
HomePage.Views.FavoritesGridAddButton()
HomePage.Views.FavoritesGridAddButton().accessibilityIdentifier("HomePage.Models.FavoriteModel.addButton")

case .ghostButton:
HomePage.Views.FavoritesGridGhostButton()
HomePage.Views.FavoritesGridGhostButton().accessibilityIdentifier("HomePage.Models.FavoriteModel.ghostButton")
}
}
}
3 changes: 2 additions & 1 deletion DuckDuckGo/Menus/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import SubscriptionUI
var forwardMenuItem: NSMenuItem { historyMenu.forwardMenuItem }

// MARK: Bookmarks
let manageBookmarksMenuItem = NSMenuItem(title: UserText.mainMenuHistoryManageBookmarks, action: #selector(MainViewController.showManageBookmarks))
let manageBookmarksMenuItem = NSMenuItem(title: UserText.mainMenuHistoryManageBookmarks, action: #selector(MainViewController.showManageBookmarks)).withAccessibilityIdentifier("MainMenu.manageBookmarksMenuItem")
var bookmarksMenuToggleBookmarksBarMenuItem = NSMenuItem(title: "BookmarksBarMenuPlaceholder", action: #selector(MainViewController.toggleBookmarksBarFromMenu), keyEquivalent: "B")
let importBookmarksMenuItem = NSMenuItem(title: UserText.importBookmarks, action: #selector(AppDelegate.openImportBrowserDataWindow))
let bookmarksMenu = NSMenu(title: UserText.bookmarks)
Expand Down Expand Up @@ -306,6 +306,7 @@ import SubscriptionUI
.submenu(favoritesMenu.buildItems {
NSMenuItem(title: UserText.mainMenuHistoryFavoriteThisPage, action: #selector(MainViewController.favoriteThisPage))
.withImage(.favorite)
.withAccessibilityIdentifier("MainMenu.favoriteThisPage")
NSMenuItem.separator()
})
.withImage(.favorite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ final class AddressBarButtonsViewController: NSViewController {

private func updateBookmarkButtonVisibility() {
guard view.window?.isPopUpWindow == false else { return }
bookmarkButton.setAccessibilityIdentifier("Bookmarks Button")
bookmarkButton.setAccessibilityIdentifier("AddressBarButtonsViewController.bookmarkButton")
let hasEmptyAddressBar = textFieldValue?.isEmpty ?? true
var showBookmarkButton: Bool {
guard let tabViewModel, tabViewModel.canBeBookmarked else { return false }
Expand Down Expand Up @@ -727,15 +727,18 @@ final class AddressBarButtonsViewController: NSViewController {

private func updateBookmarkButtonImage(isUrlBookmarked: Bool = false) {
if let url = tabViewModel?.tab.content.url,
isUrlBookmarked || bookmarkManager.isUrlBookmarked(url: url) {
isUrlBookmarked || bookmarkManager.isUrlBookmarked(url: url)
{
bookmarkButton.image = .bookmarkFilled
bookmarkButton.mouseOverTintColor = NSColor.bookmarkFilledTint
bookmarkButton.toolTip = UserText.editBookmarkTooltip
bookmarkButton.setAccessibilityValue("Bookmarked")
} else {
bookmarkButton.mouseOverTintColor = nil
bookmarkButton.image = .bookmark
bookmarkButton.contentTintColor = nil
bookmarkButton.toolTip = UserText.addBookmarkTooltip
bookmarkButton.setAccessibilityValue("Unbookmarked")
}
}

Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/NavigationBar/View/MoreOptionsMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ final class MoreOptionsMenu: NSMenu {
.targetting(self)
.withImage(.bookmarks)
.withSubmenu(bookmarksSubMenu)

.withAccessibilityIdentifier("MoreOptionsMenu.openBookmarks")
addItem(withTitle: UserText.downloads, action: #selector(openDownloads), keyEquivalent: "j")
.targetting(self)
.withImage(.downloads)
Expand Down Expand Up @@ -641,6 +641,7 @@ final class BookmarksSubMenu: NSMenu {
let bookmarkPageItem = addItem(withTitle: UserText.bookmarkThisPage, action: #selector(MoreOptionsMenu.bookmarkPage(_:)), keyEquivalent: "d")
.withModifierMask([.command])
.targetting(target)
.withAccessibilityIdentifier("MoreOptionsMenu.bookmarkPage")

bookmarkPageItem.isEnabled = tabCollectionViewModel.selectedTabViewModel?.canBeBookmarked == true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ extension Preferences {
if model.isContinueSetUpAvailable {
ToggleMenuItem(UserText.newTabSetUpSectionTitle, isOn: $model.isContinueSetUpVisible)
}
ToggleMenuItem(UserText.newTabFavoriteSectionTitle, isOn: $model.isFavoriteVisible)
ToggleMenuItem(UserText.newTabFavoriteSectionTitle, isOn: $model.isFavoriteVisible).accessibilityIdentifier("Preferences.AppearanceView.showFavoritesToggle")
ToggleMenuItem(UserText.newTabRecentActivitySectionTitle, isOn: $model.isRecentActivityVisible)
}

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Tab/TabExtensions/ContextMenuManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private extension ContextMenuManager {
}

func bookmarkPageMenuItem() -> NSMenuItem {
NSMenuItem(title: UserText.bookmarkPage, action: #selector(MainViewController.bookmarkThisPage), target: nil, keyEquivalent: "")
NSMenuItem(title: UserText.bookmarkPage, action: #selector(MainViewController.bookmarkThisPage), target: nil, keyEquivalent: "").withAccessibilityIdentifier("ContextMenuManager.bookmarkPageMenuItem")
}

func openLinkInNewWindowMenuItem(from item: NSMenuItem) -> NSMenuItem {
Expand Down
1 change: 0 additions & 1 deletion UITests/AutocompleteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// limitations under the License.
//

import Common
import XCTest

class AutocompleteTests: XCTestCase {
Expand Down
Loading

0 comments on commit 5be1c5a

Please sign in to comment.