You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

367 lines
14 KiB

// Copyright © 2015 Abhishek Banthia
import XCTest
class PreferencesTest: XCTestCase {
var app: XCUIApplication!
override func setUp() {
super.setUp()
continueAfterFailure = false
app = XCUIApplication()
app.launchArguments.append(CLUITestingLaunchArgument)
app.launch()
if app.tables["FloatingTableView"].exists {
app.tapMenubarIcon()
app.buttons["FloatingPin"].click()
}
}
func testRemovingButtonVisibility() {
app.tapMenubarIcon()
app.tables["mainTableView"].typeKey(",", modifierFlags: .command)
let predicate = NSPredicate(format: "identifier BEGINSWITH 'DeleteTimezone'", "")
let beforeTimezoneSelected = app.windows["Clocker"].checkBoxes.matching(predicate).firstMatch
XCTAssertFalse(beforeTimezoneSelected.isEnabled)
if app.tables["TimezoneTableView"].tableRows.count <= 0 {
XCTFail("There are no timezones.")
}
app.windows["Clocker"].tables["TimezoneTableView"].tableRows.firstMatch.click()
XCTAssertTrue(app.checkBoxes["DeleteTimezone"].isEnabled)
}
func testAddingATimezone() {
app.tapMenubarIcon()
app.tables["mainTableView"].typeKey(",", modifierFlags: .command)
if app.sheets.count == 0 {
app.windows["Clocker"].checkBoxes["AddTimezone"].click()
}
app.sheets.radioGroups.radioButtons["Search by Timezone(s)"].click()
addAPlace(place: "UTC", to: app)
let matchPredicate = NSPredicate(format: "value == %@", "UTC")
let matchingFields = app.windows["Clocker"].textFields.matching(matchPredicate)
XCTAssertTrue(matchingFields.count > 0, "Matching Fields count was zero")
deleteAPlace(place: "UTC", for: app)
}
6 years ago
func testEditingLabel() {
let placeToAdd = "Auckland"
6 years ago
app.tapMenubarIcon()
app.tables["mainTableView"].typeKey(",", modifierFlags: .command)
6 years ago
if app.sheets.count == 0 {
app.windows["Clocker"].checkBoxes["AddTimezone"].click()
}
6 years ago
addAPlace(place: placeToAdd, to: app)
6 years ago
let matchPredicate = NSPredicate(format: "value == %@", placeToAdd)
let matchingFields = app.windows["Clocker"].textFields.matching(matchPredicate)
XCTAssertTrue(matchingFields.count > 1, "Matching Fields count was zero")
6 years ago
matchingFields.element(boundBy: 1).doubleClick()
matchingFields.element(boundBy: 1).typeText("NZ")
app.typeKey(XCUIKeyboardKey.return, modifierFlags: [])
app.tapMenubarIcon()
6 years ago
let labelPredicate = NSPredicate(format: "label == %@", "NZ")
let cells = app.tables["mainTableView"].cells.matching(labelPredicate)
XCTAssert(cells.count > 0)
6 years ago
app.tables["mainTableView"].typeKey(",", modifierFlags: .command)
deleteAPlace(place: placeToAdd, for: app)
}
func testSortingByTimezoneDifference() {
app.tapMenubarIcon()
app.tables["mainTableView"].typeKey(",", modifierFlags: .command)
deleteAllPlaces(app: app)
addAPlace(place: "New Zealand", to: app)
addAPlace(place: "San Francisco", to: app)
addAPlace(place: "Florida", to: app, shouldSleep: false) // Last elements don't need to sleep
app.windows["Clocker"].checkBoxes["SortButton"].click()
XCTAssertTrue(app.windows["Clocker"].checkBoxes["Sort by Time Difference"].exists)
app.windows["Clocker"].checkBoxes["Sort by Time Difference"].click()
var actualLabels: [String] = []
let newFormattedAddressQuery = app.windows["Clocker"].textFields
for elementIndex in 0 ..< newFormattedAddressQuery.count {
if let currentValue = newFormattedAddressQuery.element(boundBy: elementIndex).value as? String, elementIndex % 2 == 0 {
actualLabels.append(currentValue)
}
}
XCTAssertEqual(actualLabels, ["New Zealand", "Florida", "San Francisco"])
app.windows["Clocker"].checkBoxes["Sort by Time Difference"].click()
var actualReversedLabels: [String] = []
let newReversedQuery = app.windows["Clocker"].textFields
for elementIndex in 0 ..< newReversedQuery.count {
if let currentValue = newReversedQuery.element(boundBy: elementIndex).value as? String, elementIndex % 2 == 0 {
actualReversedLabels.append(currentValue)
}
}
XCTAssertEqual(actualReversedLabels, ["San Francisco", "Florida", "New Zealand"])
addAPlace(place: "Omaha", to: app)
addAPlace(place: "Mumbai", to: app)
}
6 years ago
func testSortingByTimezoneName() {
app.tapMenubarIcon()
app.tables["mainTableView"].typeKey(",", modifierFlags: .command)
app.windows["Clocker"].checkBoxes["SortButton"].click()
XCTAssertTrue(app.windows["Clocker"].checkBoxes["Sort by Time Difference"].exists)
XCTAssertTrue(app.windows["Clocker"].checkBoxes["Sort by Label"].exists)
XCTAssertTrue(app.windows["Clocker"].checkBoxes["Sort by Name"].exists)
var formattedAddress: [String] = []
let formattedAddressQuery = app.windows["Clocker"].textFields
for elementIndex in 0 ..< formattedAddressQuery.count {
if let currentValue = formattedAddressQuery.element(boundBy: elementIndex).value as? String, elementIndex % 2 == 0 {
formattedAddress.append(currentValue)
}
}
formattedAddress.sort()
if let value = app.windows["Clocker"].checkBoxes["Sort by Name"].value as? Int, value == 0 {
app.windows["Clocker"].checkBoxes["Sort by Name"].click()
}
var newformattedAddress: [String] = []
let newFormattedAddressQuery = app.windows["Clocker"].textFields
for elementIndex in 0 ..< newFormattedAddressQuery.count {
if let currentValue = newFormattedAddressQuery.element(boundBy: elementIndex).value as? String, elementIndex % 2 == 0 {
newformattedAddress.append(currentValue)
}
}
XCTAssertEqual(newformattedAddress, formattedAddress)
app.windows["Clocker"].checkBoxes["SortButton"].click()
XCTAssertFalse(app.windows["Clocker"].checkBoxes["Sort by Time Difference"].exists)
XCTAssertFalse(app.windows["Clocker"].checkBoxes["Sort by Label"].exists)
XCTAssertFalse(app.windows["Clocker"].checkBoxes["Sort by Name"].exists)
}
func testSortingByCustomLabel() {
app.tapMenubarIcon()
app.tables["mainTableView"].typeKey(",", modifierFlags: .command)
addAPlace(place: "Aurangabad", to: app)
addAPlace(place: "Zimbabwe", to: app)
addAPlace(place: "Portland", to: app, shouldSleep: false)
app.windows["Clocker"].checkBoxes["SortButton"].click()
XCTAssertTrue(app.windows["Clocker"].checkBoxes["Sort by Label"].exists)
var expectedLabels: [String] = []
let formattedAddressQuery = app.windows["Clocker"].textFields
for elementIndex in 0 ..< formattedAddressQuery.count {
if let currentValue = formattedAddressQuery.element(boundBy: elementIndex).value as? String, elementIndex % 2 == 1 {
expectedLabels.append(currentValue)
}
}
expectedLabels.sort()
if let value = app.windows["Clocker"].checkBoxes["Sort by Label"].value as? Int, value == 0 {
app.windows["Clocker"].checkBoxes["Sort by Label"].click()
}
var actualLabels: [String] = []
let newFormattedAddressQuery = app.windows["Clocker"].textFields
for elementIndex in 0 ..< newFormattedAddressQuery.count {
if let currentValue = newFormattedAddressQuery.element(boundBy: elementIndex).value as? String, elementIndex % 2 == 1 {
actualLabels.append(currentValue)
}
}
XCTAssertEqual(actualLabels, expectedLabels)
deleteAPlace(place: "Aurangabad", for: app)
deleteAPlace(place: "Zimbabwe", for: app)
deleteAPlace(place: "Portland", for: app, shouldSleep: false)
}
func testSearchingWithMisspelledName() {
app.tapMenubarIcon()
app.tables["mainTableView"].typeKey(",", modifierFlags: .command)
6 years ago
if app.sheets.count == 0 {
app.windows["Clocker"].checkBoxes["AddTimezone"].click()
}
6 years ago
let searchField = app.searchFields["AvailableSearchField"]
searchField.reset(text: "StuJjlqh7AcJFnBuOdgNa2dQ4WrIajP9Mo8R83FV7fIZ3B8zE2n")
6 years ago
sleep(1)
6 years ago
let maxCharacterCountPredicate = NSPredicate(format: "value like %@", "Only 50 characters allowed!")
let currentSheets = app.sheets.firstMatch.staticTexts
let maxCharacterQuery = currentSheets.matching(maxCharacterCountPredicate)
6 years ago
XCTAssertTrue(maxCharacterQuery.count > 0)
6 years ago
addAPlace(place: "asdakjhdasdahsdasd", to: app, shouldSleep: false)
XCTAssertTrue(app.sheets.staticTexts["Please select a timezone!"].exists)
let informativeLabelPredicate = NSPredicate(format: "placeholderValue like %@", "No results! 😔 Try entering the exact name.")
let sheets = app.sheets.firstMatch.staticTexts
let query = sheets.matching(informativeLabelPredicate)
XCTAssertTrue(query.count > 0)
addAPlace(place: "Cambodia", to: app)
let newInformativeLabelPredicate = NSPredicate(format: "placeholderValue like %@", "No results! 😔 Try entering the exact name.")
let newSheets = app.sheets.firstMatch.staticTexts
let newQuery = newSheets.matching(newInformativeLabelPredicate)
XCTAssertTrue(newQuery.count == 0, "New Query returned \(newQuery.count)")
XCTAssertFalse(app.sheets.staticTexts["Please select a timezone!"].exists)
deleteAPlace(place: "Cambodia", for: app, shouldSleep: false)
}
func testPlaceholderStrings() {
app.tapMenubarIcon()
app.tables["mainTableView"].typeKey(",", modifierFlags: .command)
if app.sheets.count == 0 {
app.windows["Clocker"].checkBoxes["AddTimezone"].click()
}
app.sheets.radioGroups.radioButtons["Search by Timezone(s)"].click()
let expectedPlaceholder = "Enter a timezone name"
let currentPlaceholder = app.sheets.searchFields["AvailableSearchField"]
XCTAssertTrue(currentPlaceholder.exists, "Search Field doesn't exist")
XCTAssertEqual(currentPlaceholder.placeholderValue!, expectedPlaceholder)
let newPlaceholderValue = "Enter a city, state or country name"
app.sheets.radioGroups.radioButtons["Search By City"].click()
let newPlaceholder = app.sheets.searchFields["AvailableSearchField"]
XCTAssertTrue(newPlaceholder.exists, "Search Field doesn't exist")
XCTAssertEqual(newPlaceholder.placeholderValue!, newPlaceholderValue)
}
6 years ago
func testNoTimezone() {
app.tapMenubarIcon()
app.buttons["Preferences"].click()
6 years ago
deleteAllTimezones()
6 years ago
XCTAssertTrue(app.staticTexts["NoTimezoneEmoji"].exists)
XCTAssertTrue(app.staticTexts["NoTimezoneMessage"].exists)
6 years ago
app.tapMenubarIcon()
XCTAssertTrue(app.buttons["EmptyAddTimezone"].exists)
6 years ago
addAPlace(place: "Omaha", to: app)
addAPlace(place: "Mumbai", to: app)
6 years ago
deleteAllTimezones()
6 years ago
XCTAssertTrue(app.staticTexts["NoTimezoneEmoji"].exists)
XCTAssertTrue(app.staticTexts["NoTimezoneMessage"].exists)
6 years ago
addAPlace(place: "Omaha", to: app)
addAPlace(place: "Mumbai", to: app)
}
6 years ago
func testWarningIfMoreThanOneMenubarIsSelected() {
app.tapMenubarIcon()
app.buttons["Preferences"].click()
6 years ago
let preferencesTable = app.tables["TimezoneTableView"]
XCTAssertTrue(preferencesTable.exists)
6 years ago
// Let's reset all checkboxes
let favouritedMenubarsQuery = preferencesTable.checkBoxes.matching(NSPredicate(format: "value == 1", ""))
6 years ago
if favouritedMenubarsQuery.count > 1 {
6 years ago
for _ in 0 ..< favouritedMenubarsQuery.count {
let checkbox = favouritedMenubarsQuery.element(boundBy: 0)
checkbox.click()
}
}
6 years ago
// Let's make sure we have > 1 timezones first
let favourites = preferencesTable.tableRows
XCTAssertTrue(favourites.count > 1)
6 years ago
// Select two timezones
let unfavouritedMenubarsQuery = preferencesTable.checkBoxes.matching(NSPredicate(format: "value == 0", ""))
6 years ago
if unfavouritedMenubarsQuery.count > 1 {
6 years ago
for _ in 0 ..< 2 {
let checkbox = unfavouritedMenubarsQuery.element(boundBy: 0)
checkbox.click()
}
}
6 years ago
XCTAssertTrue(app.dialogs.count > 0)
6 years ago
let compactModeButton = app.dialogs.buttons["Enable Compact Mode"]
6 years ago
if compactModeButton.isHittable {
6 years ago
compactModeButton.click()
XCTAssertTrue(app.dialogs.count == 0)
}
}
6 years ago
private func deleteAllTimezones() {
let clockerWindow = app.windows["Clocker"]
let rowQueryCount = clockerWindow.tables["TimezoneTableView"].tableRows.count
6 years ago
if rowQueryCount > 0 {
let currentElement = clockerWindow.tables["TimezoneTableView"].tableRows.firstMatch
currentElement.click()
6 years ago
for _ in 0 ..< rowQueryCount {
clockerWindow.typeKey(XCUIKeyboardKey.delete,
modifierFlags: XCUIElement.KeyModifierFlags())
}
}
}
}
extension XCUIApplication {
func tapMenubarIcon() {
if menuBars.count < 2 {
XCTFail("Unable to find menubar options")
}
statusItems.firstMatch.click()
}
}