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
import XCTest
final class SavedPostsUITests: XCTestCase {
func testSaveOpenAndRemovePost() throws {
try XCTSkipIf(UIDevice.current.userInterfaceIdiom == .pad, "Requires the iPhone tab layout")
continueAfterFailure = false
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
let tabs = app.tabBars.buttons
let savedTab = tabs["Saved Posts"]
XCTAssertTrue(savedTab.waitForExistence(timeout: 10))
XCTAssertFalse(tabs["Settings"].exists)
let compose = tabs["New post"]
XCTAssertTrue(compose.exists)
XCTAssertLessThan(savedTab.frame.midX, compose.frame.midX)
let controls = app.buttons["postControls-post-1"].firstMatch
XCTAssertTrue(controls.waitForExistence(timeout: 10))
controls.tap()
app.buttons["Save post"].tap()
savedTab.tap()
let savedTitle = app.navigationBars["Saved Posts"]
XCTAssertTrue(savedTitle.waitForExistence(timeout: 5))
let post = app.buttons["postText-post-1"].firstMatch
XCTAssertTrue(post.waitForExistence(timeout: 5))
post.tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
app.navigationBars.buttons["Saved Posts"].tap()
controls.tap()
app.buttons["Remove from Saved Posts"].tap()
XCTAssertTrue(app.staticTexts["No saved posts"].waitForExistence(timeout: 5))
tabs["Timeline"].tap()
XCTAssertTrue(post.waitForExistence(timeout: 5))
controls.tap()
XCTAssertTrue(app.buttons["Save post"].exists)
}
func testIPadSavedPostsFobOpensList() throws {
try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Requires iPad")
continueAfterFailure = false
XCUIDevice.shared.orientation = .landscapeLeft
defer { XCUIDevice.shared.orientation = .portrait }
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
let actions = app.buttons["togglePadActionsButton"]
let saved = app.buttons["padSavedPostsButton"]
XCTAssertTrue(actions.waitForExistence(timeout: 10))
XCTAssertFalse(saved.exists)
actions.tap()
XCTAssertTrue(saved.waitForExistence(timeout: 5))
let search = app.buttons["padSearchButton"]
XCTAssertTrue(search.exists)
XCTAssertTrue(app.buttons["padSettingsButton"].exists)
XCTAssertLessThan(saved.frame.midX, search.frame.midX)
XCTAssertEqual(saved.frame.midY, search.frame.midY, accuracy: 4)
saved.tap()
XCTAssertTrue(app.navigationBars["Saved Posts"].waitForExistence(timeout: 5))
XCTAssertTrue(app.staticTexts["No saved posts"].waitForExistence(timeout: 5))
app.buttons["Done"].tap()
XCTAssertTrue(app.navigationBars["Saved Posts"].waitForNonExistence(timeout: 5))
}
}