App/UITests/StepListTests.swift

main
fold/App/UITests/StepListTests.swift history · blame · raw

72 lines · 3143 bytes

7 symbols in this file
 1import XCTest
 2
 3final class StepListTests: XCTestCase {
 4    override func setUp() {
 5        continueAfterFailure = false
 6    }
 7
 8    func testTheStepListOpensAChosenStepAtItsStart() {
 9        let app = XCUIApplication(); app.launch()
10        app.buttons["Cup"].tap()
11        app.buttons["steps.button"].tap()
12        app.buttons["step.5"].tap()
13        XCTAssertEqual(app.staticTexts["step.index"].label, "5")
14        XCTAssertEqual(app.otherElements["fold.paper"].value as? String, "0%")
15    }
16
17    func testTheStepListNamesEveryStep() {
18        let app = XCUIApplication(); app.launch()
19        app.buttons["Cup"].tap()
20        let caption = app.staticTexts["diagram.caption"].label
21        app.buttons["steps.button"].tap()
22        let rows = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'step.'"))
23        XCTAssertTrue(rows.firstMatch.waitForExistence(timeout: 5))
24        XCTAssertEqual(rows.count, 6)
25        for n in 1...6 {
26            let label = app.buttons["step.\(n)"].label
27            XCTAssertTrue(label.hasPrefix("Step \(n), "), label)
28            XCTAssertGreaterThan(label.count, "Step \(n), ".count)
29        }
30        XCTAssertEqual(app.buttons["step.1"].label, "Step 1, \(caption)")
31        XCTAssertTrue(app.buttons["step.1"].isSelected)
32        XCTAssertFalse(app.buttons["step.2"].isSelected)
33        XCTAssertTrue(app.staticTexts["Steps"].exists)
34    }
35
36    func testTheStepListOpensScrolledToTheCurrentStep() {
37        // at the largest text size the cup's six rows do not fit the sheet
38        let app = XCUIApplication()
39        app.launchArguments = ["-UIPreferredContentSizeCategoryName", AccessibilityAuditTests.largestText]
40        app.launch()
41        app.buttons["Cup"].tap()
42        app.buttons["steps.button"].tap()
43        XCTAssertTrue(app.buttons["step.1"].waitForExistence(timeout: 5))
44        let last = app.buttons["step.6"]
45        for _ in 0..<8 where !(last.exists && last.isHittable) { app.collectionViews.firstMatch.swipeUp() }
46        last.tap()
47        XCTAssertTrue(last.waitForNonExistence(timeout: 5))
48        app.buttons["steps.button"].tap()
49        let row = app.buttons["step.6"]
50        XCTAssertTrue(row.waitForExistence(timeout: 5))
51        XCTAssertTrue(row.isHittable)
52        XCTAssertFalse(app.buttons["step.1"].isHittable)
53    }
54
55    func testChoosingTheCurrentStepClosesTheListAndLeavesTheFoldAlone() {
56        let app = XCUIApplication(); app.launchArguments = ["-UITesting"]; app.launch()
57        app.buttons["Cup"].tap()
58        dragCurrentFold(app, to: 0.5)
59        let released = app.otherElements["fold.paper"].value as? String
60        app.buttons["steps.button"].tap()
61        app.buttons["step.1"].tap()
62        XCTAssertTrue(app.buttons["step.1"].waitForNonExistence(timeout: 5))
63        XCTAssertEqual(app.staticTexts["step.index"].label, "1")
64        XCTAssertEqual(app.otherElements["fold.paper"].value as? String, released)
65    }
66
67    func testTheTitleCountsTheSteps() {
68        let app = XCUIApplication(); app.launch()
69        app.buttons["Cup"].tap()
70        XCTAssertTrue(app.navigationBars["Step 1 of 6"].waitForExistence(timeout: 5))
71    }
72}