|
| 1 | +// |
| 2 | +// SwiftCurrent_SwiftUI_UITests.swift |
| 3 | +// SwiftCurrent_SwiftUI_UITests |
| 4 | +// |
| 5 | +// Created by Richard Gist on 9/1/21. |
| 6 | +// Copyright © 2021 WWT and Tyler Thompson. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +import XCTest |
| 10 | + |
| 11 | +class SwiftCurrent_SwiftUI_UITests: XCTestCase { |
| 12 | + |
| 13 | + override func setUpWithError() throws { |
| 14 | + // In UI tests it is usually best to stop immediately when a failure occurs. |
| 15 | + continueAfterFailure = false |
| 16 | + } |
| 17 | + |
| 18 | + func testBackingUpWithDefaultModals() throws { |
| 19 | + // UI tests must launch the application that they test. |
| 20 | + let app = XCUIApplication() |
| 21 | + app.launch ( |
| 22 | + .xcuiTest(true), |
| 23 | + .testingView(.fourItemWorkflow), |
| 24 | + .presentationType(.FR2, .modal), |
| 25 | + .presentationType(.FR3, .modal), |
| 26 | + .presentationType(.FR4, .modal) |
| 27 | + ) |
| 28 | + |
| 29 | + XCTAssert(app.staticTexts["This is FR1"].exists) |
| 30 | + app.buttons.matching(identifier: "Navigate forward").lastMatch.tap() |
| 31 | + |
| 32 | + XCTAssert(app.staticTexts["This is FR2"].exists) |
| 33 | + app.buttons.matching(identifier: "Navigate forward").lastMatch.tap() |
| 34 | + |
| 35 | + XCTAssert(app.staticTexts["This is FR3"].exists) |
| 36 | + app.buttons.matching(identifier: "Navigate forward").lastMatch.tap() |
| 37 | + |
| 38 | + XCTAssert(app.staticTexts["This is FR4"].exists) |
| 39 | + app.buttons.matching(identifier: "Navigate backward").lastMatch.tap() |
| 40 | + |
| 41 | + XCTAssert(app.staticTexts["This is FR3"].exists) |
| 42 | + app.buttons.matching(identifier: "Navigate backward").lastMatch.tap() |
| 43 | + |
| 44 | + XCTAssert(app.staticTexts["This is FR2"].exists) |
| 45 | + app.buttons.matching(identifier: "Navigate backward").lastMatch.tap() |
| 46 | + |
| 47 | + XCTAssert(app.staticTexts["This is FR1"].exists) |
| 48 | + } |
| 49 | + |
| 50 | + func testBackingUpWithFullScreenCovers() throws { |
| 51 | + // UI tests must launch the application that they test. |
| 52 | + let app = XCUIApplication() |
| 53 | + app.launch ( |
| 54 | + .xcuiTest(true), |
| 55 | + .testingView(.fourItemWorkflow), |
| 56 | + .presentationType(.FR2, .modal(.fullScreenCover)), |
| 57 | + .presentationType(.FR3, .modal(.fullScreenCover)), |
| 58 | + .presentationType(.FR4, .modal(.fullScreenCover)) |
| 59 | + ) |
| 60 | + |
| 61 | + XCTAssert(app.staticTexts["This is FR1"].exists) |
| 62 | + app.buttons.matching(identifier: "Navigate forward").firstMatch.tap() |
| 63 | + |
| 64 | + XCTAssert(app.staticTexts["This is FR2"].exists) |
| 65 | + app.buttons.matching(identifier: "Navigate forward").firstMatch.tap() |
| 66 | + |
| 67 | + XCTAssert(app.staticTexts["This is FR3"].exists) |
| 68 | + app.buttons.matching(identifier: "Navigate forward").element(boundBy: 1).tap() |
| 69 | + |
| 70 | + XCTAssert(app.staticTexts["This is FR4"].exists) |
| 71 | + app.buttons.matching(identifier: "Navigate backward").element(boundBy: 2).tap() |
| 72 | + |
| 73 | + XCTAssert(app.staticTexts["This is FR3"].exists) |
| 74 | + app.buttons.matching(identifier: "Navigate backward").element(boundBy: 1).tap() |
| 75 | + |
| 76 | + XCTAssert(app.staticTexts["This is FR2"].exists) |
| 77 | + app.buttons.matching(identifier: "Navigate backward").firstMatch.tap() |
| 78 | + |
| 79 | + XCTAssert(app.staticTexts["This is FR1"].exists) |
| 80 | + } |
| 81 | + |
| 82 | + func testBackingUpWithNavigationLinks() throws { |
| 83 | + // UI tests must launch the application that they test. |
| 84 | + let app = XCUIApplication() |
| 85 | + app.launch( |
| 86 | + .xcuiTest(true), |
| 87 | + .embedInNavStack(true), |
| 88 | + .testingView(.fourItemWorkflow), |
| 89 | + .presentationType(.FR1, .navigationLink), |
| 90 | + .presentationType(.FR2, .navigationLink), |
| 91 | + .presentationType(.FR3, .navigationLink) |
| 92 | + ) |
| 93 | + |
| 94 | + XCTAssert(app.staticTexts["This is FR1"].exists) |
| 95 | + app.buttons["Navigate forward"].tap() |
| 96 | + |
| 97 | + XCTAssert(app.staticTexts["This is FR2"].exists) |
| 98 | + app.buttons["Navigate forward"].tap() |
| 99 | + |
| 100 | + XCTAssert(app.staticTexts["This is FR3"].exists) |
| 101 | + app.buttons["Navigate forward"].tap() |
| 102 | + |
| 103 | + XCTAssert(app.staticTexts["This is FR4"].exists) |
| 104 | + app.buttons["Navigate backward"].tap() |
| 105 | + |
| 106 | + XCTAssert(app.staticTexts["This is FR3"].exists) |
| 107 | + app.buttons["Navigate backward"].tap() |
| 108 | + |
| 109 | + XCTAssert(app.staticTexts["This is FR2"].exists) |
| 110 | + app.buttons["Navigate backward"].tap() |
| 111 | + |
| 112 | + XCTAssert(app.staticTexts["This is FR1"].exists) |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +extension XCUIApplication { |
| 117 | + func launch(_ environment: Environment...) { |
| 118 | + var launchEnvironment = [String: String]() |
| 119 | + environment.forEach { launchEnvironment = launchEnvironment + $0.dictionaryValue } |
| 120 | + self.launchEnvironment = launchEnvironment |
| 121 | + launch() |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +public extension Dictionary { |
| 126 | + static func + (lhs: [Key: Value], rhs: [Key: Value]) -> [Key: Value] { |
| 127 | + return lhs.merging(rhs, uniquingKeysWith: { $1 }) |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +extension XCUIElementQuery { |
| 132 | + var lastMatch: XCUIElement { return self.element(boundBy: self.count - 1) } |
| 133 | +} |
0 commit comments