-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement bookmarks sort UI tests (#3162)
Task/Issue URL: https://app.asana.com/0/1204006570077678/1208153822177986/f Tech Design URL: CC: ## Description Adds UI tests for bookmarks sort: - Test that changing sort in the panel is reflected in the Bookmarks Manager page and vice versa - Test that manual, name ascending and name descending sorting work as expected (both in panel and manager) - Test that selected sorting is persisted through browser restarts ## Steps to test this PR 1. Run the `BookmarkSortTests` class 2. Check the UI tests work. **Definition of Done**: * [x] Does this PR satisfy our [Definition of Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)? — ###### Internal references: [Pull Request Review Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f) [Software Engineering Expectations](https://app.asana.com/0/59792373528535/199064865822552) [Technical Design Template](https://app.asana.com/0/59792373528535/184709971311943) [Pull Request Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f)
- Loading branch information
1 parent
8561bd2
commit 10359ba
Showing
6 changed files
with
259 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
// | ||
// BookmarkSortTests.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import XCTest | ||
|
||
class BookmarkSortTests: XCTestCase { | ||
private var app: XCUIApplication! | ||
|
||
private enum AccessibilityIdentifiers { | ||
static let addressBarTextField = "AddressBarViewController.addressBarTextField" | ||
static let resetBookmarksMenuItem = "MainMenu.resetBookmarks" | ||
static let sortBookmarksButtonPanel = "BookmarkListViewController.sortBookmarksButton" | ||
static let sortBookmarksButtonManager = "BookmarkManagementDetailViewController.sortItemsButton" | ||
} | ||
|
||
override class func setUp() { | ||
UITests.firstRun() | ||
} | ||
|
||
override func setUpWithError() throws { | ||
continueAfterFailure = false | ||
app = XCUIApplication() | ||
app.launchEnvironment["UITEST_MODE"] = "1" | ||
app.launch() | ||
app.resetBookmarks() | ||
app.enforceSingleWindow() | ||
} | ||
|
||
func testWhenChangingSortingInThePanelIsReflectedInTheManager() { | ||
app.openBookmarksPanel() | ||
selectSortByName(mode: .panel) | ||
app.openBookmarksManager() | ||
|
||
app.buttons[AccessibilityIdentifiers.sortBookmarksButtonManager].tap() | ||
|
||
/// If the ascending and descending sort options are enabled, means that the sort in the panel was reflected here. | ||
XCTAssertTrue(app.menuItems["Ascending"].isEnabled) | ||
XCTAssertTrue(app.menuItems["Descending"].isEnabled) | ||
} | ||
|
||
func testWhenChangingSortingInTheManagerIsReflectedInThePanel() { | ||
app.openBookmarksManager() | ||
selectSortByName(mode: .manager) | ||
app.openBookmarksPanel() | ||
|
||
let bookmarksPanelPopover = app.popovers.firstMatch | ||
bookmarksPanelPopover.buttons[AccessibilityIdentifiers.sortBookmarksButtonPanel].tap() | ||
|
||
XCTAssertTrue(bookmarksPanelPopover.menuItems["Ascending"].isEnabled) | ||
XCTAssertTrue(bookmarksPanelPopover.menuItems["Descending"].isEnabled) | ||
} | ||
|
||
func testManualSortWorksAsExpectedOnBookmarksPanel() { | ||
["Bookmark #2", "Bookmark #3", "Bookmark #1"].forEach { | ||
addBookmark(pageTitle: $0) | ||
app.openNewTab() | ||
} | ||
|
||
closeShowBookmarksBarAlert() | ||
app.openBookmarksPanel() | ||
app.verifyBookmarkOrder(expectedOrder: ["Bookmark #2", "Bookmark #3", "Bookmark #1"], mode: .panel) | ||
} | ||
|
||
func testManualSortWorksAsExpectedOnBookmarksManager() { | ||
["Bookmark #2", "Bookmark #3", "Bookmark #1"].forEach { | ||
addBookmark(pageTitle: $0) | ||
app.openNewTab() | ||
} | ||
|
||
closeShowBookmarksBarAlert() | ||
app.openBookmarksManager() | ||
app.verifyBookmarkOrder(expectedOrder: ["Bookmark #2", "Bookmark #3", "Bookmark #1"], mode: .manager) | ||
} | ||
|
||
func testNameAscendingSortWorksAsExpectedOnBookmarksPanel() { | ||
["Bookmark #2", "Bookmark #3", "Bookmark #1"].forEach { | ||
addBookmark(pageTitle: $0) | ||
app.openNewTab() | ||
} | ||
|
||
closeShowBookmarksBarAlert() | ||
app.openBookmarksPanel() | ||
selectSortByName(mode: .panel) | ||
app.verifyBookmarkOrder(expectedOrder: ["Bookmark #1", "Bookmark #2", "Bookmark #3"], mode: .panel) | ||
} | ||
|
||
func testNameAscendingSortWorksAsExpectedOnBookmarksManager() { | ||
["Bookmark #2", "Bookmark #3", "Bookmark #1"].forEach { | ||
addBookmark(pageTitle: $0) | ||
app.openNewTab() | ||
} | ||
|
||
closeShowBookmarksBarAlert() | ||
app.openBookmarksManager() | ||
selectSortByName(mode: .manager) | ||
app.verifyBookmarkOrder(expectedOrder: ["Bookmark #1", "Bookmark #2", "Bookmark #3"], mode: .manager) | ||
} | ||
|
||
func testNameDescendingSortWorksAsExpectedOnBookmarksPanel() { | ||
["Bookmark #2", "Bookmark #3", "Bookmark #1"].forEach { | ||
addBookmark(pageTitle: $0) | ||
app.openNewTab() | ||
} | ||
|
||
closeShowBookmarksBarAlert() | ||
app.openBookmarksPanel() | ||
selectSortByName(mode: .panel, descending: true) | ||
app.verifyBookmarkOrder(expectedOrder: ["Bookmark #3", "Bookmark #2", "Bookmark #1"], mode: .panel) | ||
} | ||
|
||
func testNameDescendingSortWorksAsExpectedOnBookmarksManager() { | ||
["Bookmark #2", "Bookmark #3", "Bookmark #1"].forEach { | ||
addBookmark(pageTitle: $0) | ||
app.openNewTab() | ||
} | ||
|
||
closeShowBookmarksBarAlert() | ||
app.openBookmarksManager() | ||
selectSortByName(mode: .manager, descending: true) | ||
app.verifyBookmarkOrder(expectedOrder: ["Bookmark #3", "Bookmark #2", "Bookmark #1"], mode: .manager) | ||
} | ||
|
||
func testThatSortIsPersistedThroughBrowserRestarts() { | ||
app.openBookmarksPanel() | ||
selectSortByName(mode: .panel) | ||
|
||
app.terminate() | ||
let newApp = XCUIApplication() | ||
newApp.launch() | ||
|
||
app.openBookmarksPanel() | ||
Check failure on line 146 in UITests/BookmarkSortTests.swift GitHub Actions / UI tests (macos-13-xlarge)
Check failure on line 146 in UITests/BookmarkSortTests.swift GitHub Actions / UI tests (macos-13-xlarge)
|
||
|
||
let sortBookmarksPanelButton = newApp.buttons[AccessibilityIdentifiers.sortBookmarksButtonPanel] | ||
sortBookmarksPanelButton.tap() | ||
|
||
let sortByNameManual = newApp.menuItems["Manual"] | ||
let sortByNameMenuItem = newApp.menuItems["Name"] | ||
let sortByNameAscendingMenuItem = newApp.menuItems["Ascending"] | ||
let sortByNameDescendingMenuItem = newApp.menuItems["Descending"] | ||
|
||
XCTAssertTrue(sortByNameManual.isEnabled) | ||
XCTAssertTrue(sortByNameMenuItem.isEnabled) | ||
XCTAssertTrue(sortByNameAscendingMenuItem.isEnabled) | ||
XCTAssertTrue(sortByNameDescendingMenuItem.isEnabled) | ||
} | ||
|
||
// MARK: - Utilities | ||
|
||
private func tapPanelSortButton() { | ||
let bookmarksPanelPopover = app.popovers.firstMatch | ||
let sortBookmarksButton = bookmarksPanelPopover.buttons[AccessibilityIdentifiers.sortBookmarksButtonPanel] | ||
sortBookmarksButton.tap() | ||
} | ||
|
||
private func selectSortByName(mode: BookmarkMode, descending: Bool = false) { | ||
if mode == .panel { | ||
let bookmarksPanelPopover = app.popovers.firstMatch | ||
let sortBookmarksButton = bookmarksPanelPopover.buttons[AccessibilityIdentifiers.sortBookmarksButtonPanel] | ||
sortBookmarksButton.tap() | ||
bookmarksPanelPopover.menuItems["Name"].tap() | ||
|
||
if descending { | ||
sortBookmarksButton.tap() | ||
bookmarksPanelPopover.menuItems["Descending"].tap() | ||
} | ||
} else { | ||
let sortBookmarksButton = app.buttons[AccessibilityIdentifiers.sortBookmarksButtonManager] | ||
sortBookmarksButton.tap() | ||
app.menuItems["Name"].tap() | ||
|
||
if descending { | ||
sortBookmarksButton.tap() | ||
app.menuItems["Descending"].tap() | ||
/// Here we hover over the sort button, because if we stay where the 'Descending' was selected | ||
/// the label of the bookmark being hovered is different because it shows the URL. | ||
sortBookmarksButton.hover() | ||
} | ||
} | ||
} | ||
|
||
private func addBookmark(pageTitle: String, in folder: String? = nil) { | ||
let urlForBookmarksBar = UITests.simpleServedPage(titled: pageTitle) | ||
app.openSiteToBookmark(url: urlForBookmarksBar, | ||
pageTitle: pageTitle, | ||
bookmarkingViaDialog: true, | ||
escapingDialog: true, | ||
folderName: folder) | ||
} | ||
|
||
private func closeShowBookmarksBarAlert() { | ||
app.dismissPopover(buttonIdentifier: "Hide") | ||
} | ||
} |
Oops, something went wrong.