-
Notifications
You must be signed in to change notification settings - Fork 27
/
SearchSettingsUITest.swift
123 lines (100 loc) · 4.5 KB
/
SearchSettingsUITest.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import XCTest
let defaultSearchEngine1 = "Yahoo"
let defaultSearchEngine2 = "Amazon.com"
let customSearchEngine = ["name": "youtube", "url": "http://youtube.com/search?q=%s"]
class SearchSettingsUITests: BaseTestCase {
var navigator: Navigator!
var app: XCUIApplication!
override func setUp() {
super.setUp()
app = XCUIApplication()
navigator = createScreenGraph(app).navigator(self)
}
override func tearDown() {
super.tearDown()
}
func testDefaultSearchEngine() {
navigator.goto(SearchSettings)
// Check the default browser
let defaultSearchEngine = app.tables.cells.element(boundBy: 0)
waitforExistence(app.tables.cells.staticTexts[defaultSearchEngine1])
// Change to another browser and check it is set as default
defaultSearchEngine.tap()
let listOfEngines = app.tables
listOfEngines.staticTexts[defaultSearchEngine2].tap()
waitforExistence(app.tables.cells.staticTexts[defaultSearchEngine2])
}
func testCustomSearchEngineIsEditable() {
navigator.goto(SearchSettings)
// Add a custom search engine
addCustomSearchEngine()
// Check that the custom search appears on the list
waitforExistence(app.tables.cells.staticTexts[customSearchEngine["name"]!])
// Check that it can be edited
XCTAssertTrue(app.buttons["Edit"].isEnabled)
app.buttons["Edit"].tap()
waitforExistence(app.tables.buttons["Delete \(customSearchEngine["name"]!)"])
}
private func addCustomSearchEngine() {
waitforExistence(app.tables.cells["customEngineViewButton"])
app.tables.cells["customEngineViewButton"].tap()
waitforExistence(app.tables.cells.staticTexts["Search Engine"])
app.tables.cells.textViews["customEngineTitle"].tap()
app.tables.cells.textViews["customEngineTitle"].typeText(customSearchEngine["name"]!)
app.tables.cells.textViews["customEngineUrl"].tap()
app.tables.cells.textViews["customEngineUrl"].typeText(customSearchEngine["url"]!)
app.buttons["Save"].tap()
// Check that custom engine has been added successfully
waitforExistence(app.tables.cells.staticTexts[customSearchEngine["name"]!])
}
func testCustomSearchEngineAsDefaultIsNotEditable() {
navigator.goto(SearchSettings)
// Edit is disabled
XCTAssertFalse(app.buttons["Edit"].isEnabled)
addCustomSearchEngine()
// Edit is enabled
XCTAssertTrue(app.buttons["Edit"].isEnabled)
// Select the custom engine as the default one
let defaultSearchEngine = app.tables.cells.element(boundBy: 0)
defaultSearchEngine.tap()
let listOfEngines = app.tables
listOfEngines.staticTexts[customSearchEngine["name"]!].tap()
// Edit is disabled
XCTAssertFalse(app.buttons["Edit"].isEnabled)
}
func testNavigateToSearchPickerTurnsOffEditing() {
navigator.goto(SearchSettings)
// Edit is disabled
XCTAssertFalse(app.buttons["Edit"].isEnabled)
addCustomSearchEngine()
// Edit is enabled
XCTAssertTrue(app.buttons["Edit"].isEnabled)
app.buttons["Edit"].tap()
XCTAssertTrue(app.buttons["Done"].isEnabled)
// Navigate to the search engine picker and back
let defaultSearchEngine = app.tables.cells.element(boundBy: 0)
defaultSearchEngine.tap()
app.buttons["Cancel"].tap()
// Check to see we're not in editing state, edit is enable and done does not appear
XCTAssertTrue(app.buttons["Edit"].isEnabled)
waitforNoExistence(app.buttons["Done"])
}
func testDeletingLastCustomEngineExitsEditing() {
navigator.goto(SearchSettings)
// Edit is disabled
XCTAssertFalse(app.buttons["Edit"].isEnabled)
// Add a custom search engine
addCustomSearchEngine()
XCTAssertTrue(app.buttons["Edit"].isEnabled)
app.buttons["Edit"].tap()
XCTAssertTrue(app.buttons["Done"].isEnabled)
// Remove the custom search engine and check that edit is disabled
let tablesQuery = app.tables
tablesQuery.buttons["Delete \(customSearchEngine["name"]!)"].tap()
tablesQuery.buttons["Delete"].tap()
XCTAssertFalse(app.buttons["Edit"].isEnabled)
}
}