Skip to content

Commit

Permalink
Add bookmarks search UI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jotaemepereira committed Aug 27, 2024
1 parent 407e351 commit 131b5dd
Show file tree
Hide file tree
Showing 9 changed files with 488 additions and 19 deletions.
8 changes: 8 additions & 0 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2541,6 +2541,8 @@
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 */; };
BBBB65422C77C46100E69AC6 /* BookmarksUtilites.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBB65412C77C46100E69AC6 /* BookmarksUtilites.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 */; };
Expand Down Expand Up @@ -4237,6 +4239,8 @@
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>"; };
BBBB65412C77C46100E69AC6 /* BookmarksUtilites.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksUtilites.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>"; };
BBE013E92C5BFD660025F2C6 /* BookmarksEmptyStateContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksEmptyStateContent.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6165,6 +6169,7 @@
EE9D81C22BC57A3700338BE3 /* StateRestorationTests.swift */,
7B4CE8E626F02134009134B1 /* TabBarTests.swift */,
56A054522C2592CE007D8FAB /* OnboardingUITests.swift */,
BBBB653F2C77BB9400E69AC6 /* BookmarkSearchTests.swift */,
);
path = UITests;
sourceTree = "<group>";
Expand Down Expand Up @@ -8560,6 +8565,7 @@
children = (
EE02D4192BB4609900DBE6B3 /* UITests.swift */,
EEBCE6812BA444FA00B9DF00 /* XCUIElementExtension.swift */,
BBBB65412C77C46100E69AC6 /* BookmarksUtilites.swift */,
);
path = Common;
sourceTree = "<group>";
Expand Down Expand Up @@ -11282,12 +11288,14 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BBBB65422C77C46100E69AC6 /* BookmarksUtilites.swift in Sources */,
EEBCE6842BA4643200B9DF00 /* NSSizeExtension.swift in Sources */,
EE7F74912BB5D76600CD9456 /* BookmarksBarTests.swift in Sources */,
EE02D41C2BB460A600DBE6B3 /* BrowsingHistoryTests.swift in Sources */,
EE02D41A2BB4609900DBE6B3 /* UITests.swift in Sources */,
EE0429E02BA31D2F009EB20F /* FindInPageTests.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 @@ -37,7 +37,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: self, action: #selector(newFolderButtonClicked))
.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 var isSearchVisible = false

Expand All @@ -50,10 +52,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 var cancellables = Set<AnyCancellable>()
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 @@ -285,28 +285,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")
.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
4 changes: 4 additions & 0 deletions DuckDuckGo/Menus/MainMenuActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,10 @@ 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)
UserDefaults.standard.set(true, forKey: UserDefaultsWrapper<Bool>.Key.onboardingFinished.rawValue)
}

@objc func resetPinnedTabs(_ sender: Any?) {

Check failure on line 806 in DuckDuckGo/Menus/MainMenuActions.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Limit vertical whitespace to a single empty line; currently 2 (vertical_whitespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ final class NavigationBarViewController: NSViewController {

optionsButton.sendAction(on: .leftMouseDown)
bookmarkListButton.sendAction(on: .leftMouseDown)
bookmarkListButton.setAccessibilityIdentifier("NavigationBarViewController.bookmarkListButton")
downloadsButton.sendAction(on: .leftMouseDown)
networkProtectionButton.sendAction(on: .leftMouseDown)
passwordManagementButton.sendAction(on: .leftMouseDown)
Expand Down
Loading

0 comments on commit 131b5dd

Please sign in to comment.