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.

233 lines
7.2 KiB

// Copyright © 2015 Abhishek Banthia
import XCTest
extension String {
func localizedString() -> String {
5 years ago
let bundle = Bundle(for: FloatingWindowTests.self)
5 years ago
return NSLocalizedString(self, bundle: bundle, comment: "")
}
}
class FloatingWindowTests: 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["Pin"].click()
}
4 years ago
addUIInterruptionMonitor(withDescription: "Reminders Access") { (alert) -> Bool in
Logger.info("Interruption Handler called")
Logger.info(alert.description)
4 years ago
let alertButton = alert.buttons["OK"]
if alertButton.exists {
Logger.info("Okay button found")
4 years ago
alertButton.tap()
return true
}
return false
}
}
override func tearDown() {
super.tearDown()
}
func testFloatingWindow() {
let cell = app.tables["FloatingTableView"].cells.firstMatch
let extraOptionButton = cell.buttons.firstMatch
extraOptionButton.click()
let remindersCheckbox = app.checkBoxes["ReminderCheckbox"]
remindersCheckbox.click()
sleep(1)
XCTAssertTrue(app.popovers.datePickers.firstMatch.isEnabled)
remindersCheckbox.click()
sleep(1)
XCTAssertFalse(app.popovers.datePickers.firstMatch.isEnabled)
}
func testAddingANote() {
let expectedText = "This is a really important note to me and my friends"
if app.buttons["Pin"].exists {
app.buttons["Pin"].click()
}
let cell = app.tables["FloatingTableView"].cells.firstMatch
let extraOptionButton = cell.buttons.firstMatch
extraOptionButton.click()
let notesTextView = app.textViews["NotesTextView"]
notesTextView.click()
app.textViews["NotesTextView"].click(forDuration: 2, thenDragTo: notesTextView)
notesTextView.reset(text: "This is a really important note to me and my friends")
let saveButton = app.buttons["SaveButton"]
saveButton.click()
if let noteLabelInCell = cell.staticTexts["This is a really important note to me and my friends"].value as? String {
XCTAssert(noteLabelInCell == expectedText)
}
}
func testSettingAReminder() {
if app.buttons["Pin"].exists {
app.buttons["Pin"].click()
}
let cell = app.tables["FloatingTableView"].cells.firstMatch
let extraOptionButton = cell.buttons.firstMatch
extraOptionButton.click()
let remindersCheckbox = app.checkBoxes["ReminderCheckbox"]
remindersCheckbox.click()
app.buttons["SaveButton"].click()
app.tapMenubarIcon()
}
func testMarkingSlider() {
if app.buttons["Pin"].exists {
app.buttons["Pin"].click()
}
let floatingSlider = app.sliders["FloatingSlider"].exists
app.buttons["FloatingPreferences"].click()
6 years ago
let appearanceTab = app.toolbars.buttons.element(boundBy: 1)
appearanceTab.click()
let miscTab = app.tabs.element(boundBy: 1)
miscTab.click()
if floatingSlider {
app.radioGroups["FutureSlider"].radioButtons["No"].click()
} else {
app.radioGroups["FutureSlider"].radioButtons["Yes"].click()
}
let newFloatingSliderExists = app.sliders["FloatingSlider"].exists
XCTAssertNotEqual(floatingSlider, newFloatingSliderExists)
}
func testHidingMenubarOptions() {
if app.buttons["Pin"].exists {
app.buttons["Pin"].click()
}
app.buttons["FloatingPreferences"].click()
app.windows["Clocker"].toolbars.buttons["Preferences Tab".localizedString()].click()
let menubarDisplayQuery = app.tables.checkBoxes.matching(NSPredicate(format: "value == 1", ""))
let menubarDisplayQueryCount = menubarDisplayQuery.count
6 years ago
for index in 0 ..< menubarDisplayQueryCount where index < menubarDisplayQueryCount {
6 years ago
menubarDisplayQuery.element(boundBy: 0).click()
sleep(1)
}
let appearanceTab = app.toolbars.buttons.element(boundBy: 1)
appearanceTab.click()
5 years ago
// Select Misc tab
let miscTab = app.tabs.element(boundBy: 1)
miscTab.click()
XCTAssertTrue(app.staticTexts["InformationLabel"].exists)
let generalTab = app.toolbars.buttons.element(boundBy: 0)
generalTab.click()
app.tables["TimezoneTableView"].checkBoxes.firstMatch.click()
appearanceTab.click()
XCTAssertFalse(app.staticTexts["InformationLabel"].exists)
}
/// Make sure to ensure supplementary/relative date label is turned on!
func testMovingSlider() {
if app.buttons["Pin"].exists {
app.buttons["Pin"].click()
}
let floatingSlider = app.sliders["FloatingSlider"].exists
if floatingSlider {
5 years ago
let tomorrowPredicate = NSPredicate(format: "identifier like %@", "RelativeDate")
let tomorrow = app.tables.tableRows.staticTexts.matching(tomorrowPredicate)
var previousValues: [String] = []
6 years ago
for index in 0 ..< tomorrow.count {
let element = tomorrow.element(boundBy: index)
guard let supplementaryText = element.value as? String else {
continue
}
previousValues.append(supplementaryText)
}
app.sliders["FloatingSlider"].adjust(toNormalizedSliderPosition: 0.7)
sleep(1)
app.sliders["FloatingSlider"].adjust(toNormalizedSliderPosition: 1)
let newTomorrow = app.tables.tableRows.staticTexts.matching(tomorrowPredicate)
var newValues: [String] = []
6 years ago
for index in 0 ..< newTomorrow.count {
let element = newTomorrow.element(boundBy: index)
guard let supplementaryText = element.value as? String else {
continue
}
newValues.append(supplementaryText)
}
4 years ago
XCTAssertNotEqual(newValues, previousValues)
}
}
}
extension XCUIElement {
func reset(text: String) {
guard let stringValue = value as? String else {
XCTFail("Tried to clear and enter text into a non string value")
return
}
if let hasKeyboardFocus = value(forKey: "hasKeyboardFocus") as? Bool, hasKeyboardFocus == false {
click()
}
for _ in 0 ..< stringValue.count {
typeKey(XCUIKeyboardKey.delete, modifierFlags: XCUIElement.KeyModifierFlags())
}
guard let newStringValue = value as? String else {
XCTFail("Tried to clear and enter text into a non string value")
return
}
for _ in 0 ..< newStringValue.count {
typeKey(XCUIKeyboardKey.forwardDelete, modifierFlags: XCUIElement.KeyModifierFlags())
}
typeText(text)
}
}