Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bookmarks search UI tests #3161

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2584,10 +2584,12 @@
BB7B5F992C4ED73800BA4AF8 /* BookmarksSearchAndSortMetrics.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB7B5F972C4ED73800BA4AF8 /* BookmarksSearchAndSortMetrics.swift */; };
BBB881882C4029BA001247C6 /* BookmarkListTreeControllerSearchDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBB881872C4029BA001247C6 /* BookmarkListTreeControllerSearchDataSource.swift */; };
BBB881892C4029BA001247C6 /* BookmarkListTreeControllerSearchDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBB881872C4029BA001247C6 /* BookmarkListTreeControllerSearchDataSource.swift */; };
BBBB65402C77BB9400E69AC6 /* BookmarkSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBB653F2C77BB9400E69AC6 /* BookmarkSearchTests.swift */; };
BBBEE1BF2C4FF63600035ABA /* SortBookmarksViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBEE1BE2C4FF63600035ABA /* SortBookmarksViewModelTests.swift */; };
BBBEE1C02C4FF63600035ABA /* SortBookmarksViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBEE1BE2C4FF63600035ABA /* SortBookmarksViewModelTests.swift */; };
BBC063E82C5A9E4B007BDC18 /* BookmarkManagementDetailViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBC063E72C5A9E4B007BDC18 /* BookmarkManagementDetailViewModelTests.swift */; };
BBC063E92C5A9E4B007BDC18 /* BookmarkManagementDetailViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBC063E72C5A9E4B007BDC18 /* BookmarkManagementDetailViewModelTests.swift */; };
BBCD467A2C8643EC004DB483 /* XCUIApplicationExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBCD46792C8643EC004DB483 /* XCUIApplicationExtension.swift */; };
BBE013EA2C5BFD660025F2C6 /* BookmarksEmptyStateContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBE013E92C5BFD660025F2C6 /* BookmarksEmptyStateContent.swift */; };
BBE013EB2C5BFD660025F2C6 /* BookmarksEmptyStateContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBE013E92C5BFD660025F2C6 /* BookmarksEmptyStateContent.swift */; };
BBFB727F2C48047C0088884C /* SortBookmarksViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBFB727E2C48047C0088884C /* SortBookmarksViewModel.swift */; };
Expand Down Expand Up @@ -4331,8 +4333,10 @@
BB5789712B2CA70F0009DFE2 /* DataBrokerProtectionSubscriptionEventHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataBrokerProtectionSubscriptionEventHandler.swift; sourceTree = "<group>"; };
BB7B5F972C4ED73800BA4AF8 /* BookmarksSearchAndSortMetrics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksSearchAndSortMetrics.swift; sourceTree = "<group>"; };
BBB881872C4029BA001247C6 /* BookmarkListTreeControllerSearchDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkListTreeControllerSearchDataSource.swift; sourceTree = "<group>"; };
BBBB653F2C77BB9400E69AC6 /* BookmarkSearchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkSearchTests.swift; sourceTree = "<group>"; };
BBBEE1BE2C4FF63600035ABA /* SortBookmarksViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortBookmarksViewModelTests.swift; sourceTree = "<group>"; };
BBC063E72C5A9E4B007BDC18 /* BookmarkManagementDetailViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkManagementDetailViewModelTests.swift; sourceTree = "<group>"; };
BBCD46792C8643EC004DB483 /* XCUIApplicationExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCUIApplicationExtension.swift; sourceTree = "<group>"; };
BBE013E92C5BFD660025F2C6 /* BookmarksEmptyStateContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksEmptyStateContent.swift; sourceTree = "<group>"; };
BBFB727E2C48047C0088884C /* SortBookmarksViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortBookmarksViewModel.swift; sourceTree = "<group>"; };
BBFF355C2C4AF26200DA3289 /* BookmarksSortModeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksSortModeTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6310,6 +6314,7 @@
EE9D81C22BC57A3700338BE3 /* StateRestorationTests.swift */,
7B4CE8E626F02134009134B1 /* TabBarTests.swift */,
56A054522C2592CE007D8FAB /* OnboardingUITests.swift */,
BBBB653F2C77BB9400E69AC6 /* BookmarkSearchTests.swift */,
);
path = UITests;
sourceTree = "<group>";
Expand Down Expand Up @@ -8742,6 +8747,7 @@
children = (
EE02D4192BB4609900DBE6B3 /* UITests.swift */,
EEBCE6812BA444FA00B9DF00 /* XCUIElementExtension.swift */,
BBCD46792C8643EC004DB483 /* XCUIApplicationExtension.swift */,
);
path = Common;
sourceTree = "<group>";
Expand Down Expand Up @@ -11506,7 +11512,9 @@
EE02D41C2BB460A600DBE6B3 /* BrowsingHistoryTests.swift in Sources */,
EE02D41A2BB4609900DBE6B3 /* UITests.swift in Sources */,
EE0429E02BA31D2F009EB20F /* FindInPageTests.swift in Sources */,
BBCD467A2C8643EC004DB483 /* XCUIApplicationExtension.swift in Sources */,
EE02D4212BB460FE00DBE6B3 /* StringExtension.swift in Sources */,
BBBB65402C77BB9400E69AC6 /* BookmarkSearchTests.swift in Sources */,
56A054532C2592CE007D8FAB /* OnboardingUITests.swift in Sources */,
EE9D81C32BC57A3700338BE3 /* StateRestorationTests.swift in Sources */,
EEC7BE2E2BC6C09500F86835 /* AddressBarKeyboardShortcutsTests.swift in Sources */,
Expand Down
6 changes: 6 additions & 0 deletions DuckDuckGo/Bookmarks/View/BookmarkListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ final class BookmarkListViewController: NSViewController {
private lazy var stackView = NSStackView()
private lazy var newBookmarkButton = MouseOverButton(image: .addBookmark, target: self, action: #selector(newBookmarkButtonClicked))
private lazy var newFolderButton = MouseOverButton(image: .addFolder, target: outlineView.menu, action: #selector(FolderMenuItemSelectors.newFolder))
.withAccessibilityIdentifier("BookmarkListViewController.newFolderButton")
private lazy var searchBookmarksButton = MouseOverButton(image: .searchBookmarks, target: self, action: #selector(searchBookmarkButtonClicked))
.withAccessibilityIdentifier("BookmarkListViewController.searchBookmarksButton")
private lazy var sortBookmarksButton = MouseOverButton(image: .bookmarkSortAsc, target: self, action: #selector(sortBookmarksButtonClicked))

private lazy var buttonsDivider = NSBox()
Expand All @@ -53,10 +55,14 @@ final class BookmarkListViewController: NSViewController {

private lazy var emptyState = NSView()
private lazy var emptyStateTitle = NSTextField()
.withAccessibilityIdentifier(BookmarksEmptyStateContent.titleAccessibilityIdentifier)
private lazy var emptyStateMessage = NSTextField()
.withAccessibilityIdentifier(BookmarksEmptyStateContent.descriptionAccessibilityIdentifier)
private lazy var emptyStateImageView = NSImageView(image: .bookmarksEmpty)
.withAccessibilityIdentifier(BookmarksEmptyStateContent.imageAccessibilityIdentifier)
private lazy var importButton = NSButton(title: UserText.importBookmarksButtonTitle, target: self, action: #selector(onImportClicked))
private lazy var searchBar = NSSearchField()
.withAccessibilityIdentifier("BookmarkListViewController.searchBar")
private var boxDividerTopConstraint = NSLayoutConstraint()

private let bookmarkManager: BookmarkManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ final class BookmarkManagementDetailViewController: NSViewController, NSMenuItem
.withAccessibilityIdentifier("BookmarkManagementDetailViewController.sortItemsButton")

lazy var searchBar = NSSearchField()
.withAccessibilityIdentifier("BookmarkManagementDetailViewController.searchBar")
private lazy var separator = NSBox()
private lazy var scrollView = NSScrollView()
private lazy var tableView = NSTableView()

private lazy var emptyState = NSView()
private lazy var emptyStateImageView = NSImageView(image: .bookmarksEmpty)
.withAccessibilityIdentifier(BookmarksEmptyStateContent.imageAccessibilityIdentifier)
private lazy var emptyStateTitle = NSTextField()
.withAccessibilityIdentifier(BookmarksEmptyStateContent.titleAccessibilityIdentifier)
private lazy var emptyStateMessage = NSTextField()
.withAccessibilityIdentifier(BookmarksEmptyStateContent.descriptionAccessibilityIdentifier)
private lazy var importButton = NSButton(title: UserText.importBookmarksButtonTitle, target: self, action: #selector(onImportClicked))

weak var delegate: BookmarkManagementDetailViewControllerDelegate?
Expand Down
12 changes: 12 additions & 0 deletions DuckDuckGo/Bookmarks/ViewModel/BookmarksEmptyStateContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ enum BookmarksEmptyStateContent {
case noBookmarks
case noSearchResults

static var titleAccessibilityIdentifier: String {
"BookmarksEmptyStateContent.emptyStateTitle"
}

static var descriptionAccessibilityIdentifier: String {
"BookmarksEmptyStateContent.emptyStateMessage"
}

static var imageAccessibilityIdentifier: String {
"BookmarksEmptyStateContent.emptyStateImageView"
}

var title: String {
switch self {
case .noBookmarks: return UserText.bookmarksEmptyStateTitle
Expand Down
40 changes: 21 additions & 19 deletions DuckDuckGo/Menus/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,28 +290,30 @@ final class MainMenu: NSMenu {
}

func buildBookmarksMenu() -> NSMenuItem {
NSMenuItem(title: UserText.bookmarks).submenu(bookmarksMenu.buildItems {
NSMenuItem(title: UserText.bookmarkThisPage, action: #selector(MainViewController.bookmarkThisPage), keyEquivalent: "d")
NSMenuItem(title: UserText.bookmarkAllTabs, action: #selector(MainViewController.bookmarkAllOpenTabs), keyEquivalent: [.command, .shift, "d"])
manageBookmarksMenuItem
bookmarksMenuToggleBookmarksBarMenuItem
NSMenuItem.separator()
NSMenuItem(title: UserText.bookmarks)
.withAccessibilityIdentifier("MainMenu.bookmarks")
Copy link
Collaborator Author

@jotaemepereira jotaemepereira Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ This the only change to this class. I added an accessibility identifier, but I had to fix the indentation.

.submenu(bookmarksMenu.buildItems {
NSMenuItem(title: UserText.bookmarkThisPage, action: #selector(MainViewController.bookmarkThisPage), keyEquivalent: "d")
NSMenuItem(title: UserText.bookmarkAllTabs, action: #selector(MainViewController.bookmarkAllOpenTabs), keyEquivalent: [.command, .shift, "d"])
manageBookmarksMenuItem
bookmarksMenuToggleBookmarksBarMenuItem
NSMenuItem.separator()

importBookmarksMenuItem
NSMenuItem(title: UserText.exportBookmarks, action: #selector(AppDelegate.openExportBookmarks))
NSMenuItem.separator()
importBookmarksMenuItem
NSMenuItem(title: UserText.exportBookmarks, action: #selector(AppDelegate.openExportBookmarks))
NSMenuItem.separator()

NSMenuItem(title: UserText.favorites)
.submenu(favoritesMenu.buildItems {
NSMenuItem(title: UserText.mainMenuHistoryFavoriteThisPage, action: #selector(MainViewController.favoriteThisPage))
.withImage(.favorite)
.withAccessibilityIdentifier("MainMenu.favoriteThisPage")
NSMenuItem.separator()
})
.withImage(.favorite)
NSMenuItem(title: UserText.favorites)
.submenu(favoritesMenu.buildItems {
NSMenuItem(title: UserText.mainMenuHistoryFavoriteThisPage, action: #selector(MainViewController.favoriteThisPage))
.withImage(.favorite)
.withAccessibilityIdentifier("MainMenu.favoriteThisPage")
NSMenuItem.separator()
})
.withImage(.favorite)

NSMenuItem.separator()
})
NSMenuItem.separator()
})
}

func buildWindowMenu() -> NSMenuItem {
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/Menus/MainMenuActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ extension MainViewController {
@objc func resetBookmarks(_ sender: Any?) {
LocalBookmarkManager.shared.resetBookmarks()
UserDefaults.standard.set(false, forKey: UserDefaultsWrapper<Bool>.Key.homePageContinueSetUpImport.rawValue)
UserDefaults.standard.set(false, forKey: UserDefaultsWrapper<Bool>.Key.bookmarksBarPromptShown.rawValue)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ I had to to add this to be consistent between new tests. When we reset bookmarks, I want to reset the show bookmarks bar prompt dialog, so it’s shown.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes perfect sense 👍 but why are you adjusting onboardingFinished in the line below? It feels to me like a side effect (one wouldn't normally expect onboarding flag to be adjusted when you reset bookmarks, and especially not to have that flag set to true).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was needed for the show bookmarks bar dialog to appear, but that is not the case. I removed it

}

@objc func resetPinnedTabs(_ sender: Any?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ final class NavigationBarViewController: NSViewController {
bookmarkListButton.sendAction(on: .leftMouseDown)
bookmarkListButton.registerForDraggedTypes(BookmarkDragDropManager.draggedTypes)
bookmarkListButton.delegate = self
bookmarkListButton.setAccessibilityIdentifier("NavigationBarViewController.bookmarkListButton")
downloadsButton.sendAction(on: .leftMouseDown)
networkProtectionButton.sendAction(on: .leftMouseDown)
passwordManagementButton.sendAction(on: .leftMouseDown)
Expand Down
Loading
Loading