| @@ -1,13 +1,15 @@ |
| 1 | import XCTest |
1 | import XCTest |
| 2 | |
2 | |
| 3 | /// Opens every step of the cup by the labels VoiceOver sees and runs Xcode's accessibility audit |
3 | /// Opens every step of every model by the labels VoiceOver sees and runs Xcode's accessibility audit |
| 4 | /// on each screen, at the default text size and at the largest accessibility size. Also checks |
4 | /// on each screen, at the default text size and at the largest accessibility size. Also checks |
| 5 | /// that two-finger gestures on the paper change the view without advancing the fold or touching |
5 | /// that two-finger gestures on the paper change the view without advancing the fold or touching |
| 6 | /// the diagram. XCUITest has no two-finger drag, so a pinch and a rotation stand in for it. |
6 | /// the diagram. XCUITest has no two-finger drag, so a pinch and a rotation stand in for it. |
| 7 | final class AccessibilityAuditTests: XCTestCase { |
7 | final class AccessibilityAuditTests: XCTestCase { |
| 8 | static let largestText = "UICTContentSizeCategoryAccessibilityXXXL" |
8 | static let largestText = "UICTContentSizeCategoryAccessibilityXXXL" |
| 9 | /// Elements that exist only under `-UITesting`. |
9 | /// Elements that exist only under `-UITesting`. |
| 10 | static let testHooks: Set<String> = ["fold.path", "paper.camera"] |
10 | static let testHooks: Set<String> = ["fold.path", "paper.camera", "step.kind"] |
| |
11 | /// Every model in the list, by title, with its number of steps. |
| |
12 | static let models = [("Cup", 6), ("Box", 12)] |
| 11 | |
13 | |
| 12 | private var sizeName = "" |
14 | private var sizeName = "" |
| 13 | |
15 | |
| @@ -59,7 +61,8 @@ final class AccessibilityAuditTests: XCTestCase { |
| 59 | |
61 | |
| 60 | // MARK: - Helpers |
62 | // MARK: - Helpers |
| 61 | |
63 | |
| 62 | /// The model list, then every step of the cup, each advanced by the user's own drag. |
64 | /// The model list, then every step of every model, each advanced by the user's own drag: a |
| |
65 | /// reorient drag on a turn-over or rotate step, the fold drag otherwise. |
| 63 | private func everyScreen(textSize: String?) throws { |
66 | private func everyScreen(textSize: String?) throws { |
| 64 | sizeName = textSize == nil ? "default" : "largest" |
67 | sizeName = textSize == nil ? "default" : "largest" |
| 65 | let app = XCUIApplication() |
68 | let app = XCUIApplication() |
| @@ -67,21 +70,26 @@ final class AccessibilityAuditTests: XCTestCase { |
| 67 | if let textSize { app.launchArguments += ["-UIPreferredContentSizeCategoryName", textSize] } |
70 | if let textSize { app.launchArguments += ["-UIPreferredContentSizeCategoryName", textSize] } |
| 68 | app.launch() |
71 | app.launch() |
| 69 | try audit(app, "models") |
72 | try audit(app, "models") |
| 70 | app.buttons["Cup"].tap() |
73 | for (title, steps) in Self.models { |
| 71 | let index = app.staticTexts["step.index"] |
74 | app.buttons[title].tap() |
| 72 | XCTAssertTrue(index.waitForExistence(timeout: 5)) |
75 | let index = app.staticTexts["step.index"] |
| 73 | while true { |
76 | XCTAssertTrue(index.waitForExistence(timeout: 5)) |
| 74 | let step = index.label |
77 | while true { |
| 75 | try audit(app, "step \(step)") |
78 | let step = index.label |
| 76 | if app.staticTexts["diagram.caption"].label.hasPrefix("Turn over") { |
79 | try audit(app, "\(title) step \(step)") |
| 77 | dragAcross(app.otherElements["fold.paper"]) |
80 | if ["turnOver", "rotate"].contains(stepKind(app)) { |
| 78 | } else { |
81 | dragAcross(app.otherElements["fold.paper"]) |
| 79 | completeCurrentFold(app) |
82 | } else { |
| |
83 | completeCurrentFold(app) |
| |
84 | } |
| |
85 | if index.label == step { break } |
| 80 | } |
86 | } |
| 81 | if index.label == step { break } |
87 | // Stopping before the last step means an advance failed. |
| |
88 | XCTAssertEqual(index.label, "\(steps)", title) |
| |
89 | try audit(app, "\(title) finished") |
| |
90 | app.navigationBars.buttons.firstMatch.tap() |
| |
91 | XCTAssertTrue(app.buttons[title].waitForExistence(timeout: 5)) |
| 82 | } |
92 | } |
| 83 | // The cup has six steps; stopping earlier means an advance failed. |
| |
| 84 | XCTAssertEqual(index.label, "6") |
| |
| 85 | } |
93 | } |
| 86 | |
94 | |
| 87 | private func audit(_ app: XCUIApplication, _ name: String) throws { |
95 | private func audit(_ app: XCUIApplication, _ name: String) throws { |