Skip to content

Commit

Permalink
Implement bookmarks sort UI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jotaemepereira committed Aug 27, 2024
1 parent fd58733 commit ea47dab
Show file tree
Hide file tree
Showing 7 changed files with 308 additions and 67 deletions.
8 changes: 8 additions & 0 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2539,6 +2539,8 @@
BB5789722B2CA70F0009DFE2 /* DataBrokerProtectionSubscriptionEventHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB5789712B2CA70F0009DFE2 /* DataBrokerProtectionSubscriptionEventHandler.swift */; };
BB7B5F982C4ED73800BA4AF8 /* BookmarksSearchAndSortMetrics.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB7B5F972C4ED73800BA4AF8 /* BookmarksSearchAndSortMetrics.swift */; };
BB7B5F992C4ED73800BA4AF8 /* BookmarksSearchAndSortMetrics.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB7B5F972C4ED73800BA4AF8 /* BookmarksSearchAndSortMetrics.swift */; };
BB9673C32C7E3B1100C65BF4 /* BookmarkSortTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB9673C22C7E3B1100C65BF4 /* BookmarkSortTests.swift */; };
BB9673C52C7E682100C65BF4 /* XCUIApplicationExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB9673C42C7E682100C65BF4 /* XCUIApplicationExtension.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 */; };
Expand Down Expand Up @@ -4238,6 +4240,8 @@
BB470EBA2C5A66D6002EE91D /* BookmarkManagementDetailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkManagementDetailViewModel.swift; sourceTree = "<group>"; };
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>"; };
BB9673C22C7E3B1100C65BF4 /* BookmarkSortTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkSortTests.swift; sourceTree = "<group>"; };
BB9673C42C7E682100C65BF4 /* XCUIApplicationExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCUIApplicationExtension.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>"; };
Expand Down Expand Up @@ -6170,6 +6174,7 @@
7B4CE8E626F02134009134B1 /* TabBarTests.swift */,
56A054522C2592CE007D8FAB /* OnboardingUITests.swift */,
BBBB653F2C77BB9400E69AC6 /* BookmarkSearchTests.swift */,
BB9673C22C7E3B1100C65BF4 /* BookmarkSortTests.swift */,
);
path = UITests;
sourceTree = "<group>";
Expand Down Expand Up @@ -8566,6 +8571,7 @@
EE02D4192BB4609900DBE6B3 /* UITests.swift */,
EEBCE6812BA444FA00B9DF00 /* XCUIElementExtension.swift */,
BBBB65412C77C46100E69AC6 /* BookmarksUtilites.swift */,
BB9673C42C7E682100C65BF4 /* XCUIApplicationExtension.swift */,
);
path = Common;
sourceTree = "<group>";
Expand Down Expand Up @@ -11289,6 +11295,7 @@
buildActionMask = 2147483647;
files = (
BBBB65422C77C46100E69AC6 /* BookmarksUtilites.swift in Sources */,
BB9673C32C7E3B1100C65BF4 /* BookmarkSortTests.swift in Sources */,
EEBCE6842BA4643200B9DF00 /* NSSizeExtension.swift in Sources */,
EE7F74912BB5D76600CD9456 /* BookmarksBarTests.swift in Sources */,
EE02D41C2BB460A600DBE6B3 /* BrowsingHistoryTests.swift in Sources */,
Expand All @@ -11306,6 +11313,7 @@
EEBCE6832BA463DD00B9DF00 /* NSImageExtensions.swift in Sources */,
EEBCE6822BA444FA00B9DF00 /* XCUIElementExtension.swift in Sources */,
EED735362BB46B6000F173D6 /* AutocompleteTests.swift in Sources */,
BB9673C52C7E682100C65BF4 /* XCUIApplicationExtension.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/Bookmarks/View/BookmarkListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ final class BookmarkListViewController: NSViewController {
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))
.withAccessibilityIdentifier("BookmarkListViewController.sortBookmarksButton")
private var isSearchVisible = false

private lazy var buttonsDivider = NSBox()
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/Menus/MainMenuActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ extension MainViewController {
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)
LocalBookmarkManager.shared.sortMode = .manual
}

@objc func resetPinnedTabs(_ sender: Any?) {
Expand Down
66 changes: 14 additions & 52 deletions UITests/BookmarkSearchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class BookmarkSearchTests: XCTestCase {
private enum AccessibilityIdentifiers {
static let bookmarkButton = "AddressBarButtonsViewController.bookmarkButton"
static let addressBarTextField = "AddressBarViewController.addressBarTextField"
static let manageBookmarksMenuItem = "MainMenu.manageBookmarksMenuItem"
static let bookmarksMenu = "MainMenu.bookmarks"
static let bookmarksPanelShortcutButton = "NavigationBarViewController.bookmarkListButton"
static let optionsButton = "NavigationBarViewController.optionsButton"
static let resetBookmarksMenuItem = "MainMenu.resetBookmarks"
static let searchBookmarksButton = "BookmarkListViewController.searchBookmarksButton"
Expand All @@ -48,7 +46,7 @@ class BookmarkSearchTests: XCTestCase {
app.launchEnvironment["UITEST_MODE"] = "1"
app.launch()
BookmarkUtilities.resetBookmarks(app: app, resetMenuItem: app.menuItems[AccessibilityIdentifiers.resetBookmarksMenuItem])
enforceSingleWindow()
app.enforceSingleWindow()
}

// MARK: - Tests
Expand All @@ -66,14 +64,14 @@ class BookmarkSearchTests: XCTestCase {
func testFilteredResultsInPanel() {
addThreeBookmarks()
closeShowBookmarksBarAlert()
openBookmarksPanel()
app.openBookmarksPanel()
searchInBookmarksPanel(for: "Bookmark #2")
assertOnlyBookmarkExists(on: app.outlines.firstMatch, bookmarkTitle: "Bookmark #2")
}

func testFilteredResultsInManager() {
addThreeBookmarks()
openBookmarksManager()
app.openBookmarksManager()
searchInBookmarksManager(for: "Bookmark #2")
assertOnlyBookmarkExists(on: app.tables.firstMatch, bookmarkTitle: "Bookmark #2")
}
Expand All @@ -95,33 +93,28 @@ class BookmarkSearchTests: XCTestCase {
}

func testSearchActionIsHiddenOnBookmarksPanelWhenUserHasNoBookmarks() {
openBookmarksPanel()
app.openBookmarksPanel()
let bookmarksPanelPopover = app.popovers.firstMatch
XCTAssertFalse(bookmarksPanelPopover.buttons[AccessibilityIdentifiers.searchBookmarksButton].exists)
}

// MARK: - Utilities

private func enforceSingleWindow() {
app.typeKey("w", modifierFlags: [.command, .option, .shift])
app.typeKey("n", modifierFlags: .command)
}

private func addBookmarkAndOpenBookmarksPanel(bookmarkPageTitle: String, in folder: String? = nil) {
addBookmark(pageTitle: bookmarkPageTitle, in: folder)
closeShowBookmarksBarAlert()
openBookmarksPanel()
app.openBookmarksPanel()
}

private func addBookmarkAndOpenBookmarksManager(bookmarkPageTitle: String, in folder: String? = nil) {
addBookmark(pageTitle: bookmarkPageTitle, in: folder)
openBookmarksManager()
app.openBookmarksManager()
}

private func addThreeBookmarks() {
["Bookmark #1", "Bookmark #2", "Bookmark #3"].forEach {
addBookmark(pageTitle: $0)
openNewTab()
app.openNewTab()
}
}

Expand Down Expand Up @@ -182,29 +175,17 @@ class BookmarkSearchTests: XCTestCase {
popover.buttons[AccessibilityIdentifiers.searchBookmarksButton].tap()
}

private func openBookmarksPanel() {
BookmarkUtilities.showAndTapBookmarksPanelShortcut(app: app, bookmarksPanelShortcutButton: app.buttons[AccessibilityIdentifiers.bookmarksPanelShortcutButton])
}

private func openBookmarksManager() {
BookmarkUtilities.openBookmarksManager(app: app, manageBookmarksMenuItem: app.menuItems[AccessibilityIdentifiers.manageBookmarksMenuItem])
}

private func openNewTab() {
app.typeKey("t", modifierFlags: .command)
}

private func testShowInFolderFunctionality(in mode: BookmarkMode) {
createFolderWithSubFolder()
openNewTab()
app.openNewTab()
addBookmark(pageTitle: "Bookmark #1", in: "Folder #2")
closeShowBookmarksBarAlert()

if mode == .panel {
openBookmarksPanel()
app.openBookmarksPanel()
searchInBookmarksPanel(for: "Bookmark #1")
} else {
openBookmarksManager()
app.openBookmarksManager()
searchInBookmarksManager(for: "Bookmark #1")
}

Expand Down Expand Up @@ -245,9 +226,9 @@ class BookmarkSearchTests: XCTestCase {
addThreeBookmarks()
if mode == .panel {
closeShowBookmarksBarAlert()
openBookmarksPanel()
app.openBookmarksPanel()
} else {
openBookmarksManager()
app.openBookmarksManager()
}
searchInBookmarks(mode: mode)

Expand All @@ -260,7 +241,7 @@ class BookmarkSearchTests: XCTestCase {
clearSearchInBookmarksManager()
}

verifyBookmarkOrder(expectedOrder: ["Bookmark #1", "Bookmark #2", "Bookmark #3"], mode: mode)
BookmarkUtilities.verifyBookmarkOrder(app: app, expectedOrder: ["Bookmark #1", "Bookmark #2", "Bookmark #3"], mode: mode)
}

private func searchInBookmarks(mode: BookmarkMode) {
Expand Down Expand Up @@ -293,21 +274,8 @@ class BookmarkSearchTests: XCTestCase {
app.typeKey(.delete, modifierFlags: [])
}

private func verifyBookmarkOrder(expectedOrder: [String], mode: BookmarkMode) {
let rowCount = (mode == .panel ? app.popovers.firstMatch.outlines.firstMatch : app.tables.firstMatch).cells.count
XCTAssertEqual(rowCount, expectedOrder.count, "Row count does not match expected count.")

for index in 0..<rowCount {
let cell = (mode == .panel ? app.popovers.firstMatch.outlines.firstMatch : app.tables.firstMatch).cells.element(boundBy: index)
XCTAssertTrue(cell.exists, "Cell at index \(index) does not exist.")

let cellLabel = cell.staticTexts[expectedOrder[index]]
XCTAssertTrue(cellLabel.exists, "Cell at index \(index) has unexpected label.")
}
}

private func createFolderWithSubFolder() {
openBookmarksPanel()
app.openBookmarksPanel()
let bookmarksPanel = app.popovers.firstMatch
bookmarksPanel.buttons[AccessibilityIdentifiers.newFolderButton].tap()

Expand All @@ -327,9 +295,3 @@ class BookmarkSearchTests: XCTestCase {
BookmarkUtilities.dismissPopover(app: app, buttonIdentifier: "Hide")
}
}

// Enum to represent bookmark modes
private enum BookmarkMode {
case panel
case manager
}
Loading

0 comments on commit ea47dab

Please sign in to comment.