QLPreviewController only renders its share, print and open-in actions when it is inside a navigation controller, so diagram and report previews were dead ends. Wrap it in one, add an explicit Done button and assert both in a UI test.
116 lines
4.0 KiB
Swift
116 lines
4.0 KiB
Swift
import XCTest
|
|
|
|
/// Verifies that the Overview export/share menu is only available once the
|
|
/// system actually contains something worth exporting.
|
|
final class SystemExportButtonUITests: XCTestCase {
|
|
|
|
override func setUpWithError() throws {
|
|
try super.setUpWithError()
|
|
continueAfterFailure = false
|
|
XCUIDevice.shared.orientation = .portrait
|
|
}
|
|
|
|
@MainActor
|
|
func testExportIsDisabledForSystemWithoutComponents() throws {
|
|
let app = launch(arguments: ["--uitest-reset-data"])
|
|
|
|
let createSystemButton = app.buttons["create-system-button"]
|
|
XCTAssertTrue(createSystemButton.waitForExistence(timeout: 15))
|
|
createSystemButton.tap()
|
|
|
|
let shareButton = app.buttons["system-overview-share-button"]
|
|
XCTAssertTrue(shareButton.waitForExistence(timeout: 15))
|
|
XCTAssertFalse(
|
|
shareButton.isEnabled,
|
|
"Export must stay disabled while the system has no loads, batteries or chargers"
|
|
)
|
|
}
|
|
|
|
@MainActor
|
|
func testExportIsEnabledOnceComponentsExist() throws {
|
|
let app = launch(arguments: ["--uitest-reset-data", "--uitest-sample-data"])
|
|
|
|
openFirstSystem(in: app)
|
|
|
|
let shareButton = app.buttons["system-overview-share-button"]
|
|
XCTAssertTrue(shareButton.waitForExistence(timeout: 15))
|
|
XCTAssertTrue(
|
|
shareButton.isEnabled,
|
|
"Export must be available for a system that has components"
|
|
)
|
|
}
|
|
|
|
@MainActor
|
|
func testReportPreviewOffersActionButtons() throws {
|
|
let app = launch(arguments: ["--uitest-reset-data", "--uitest-sample-data"])
|
|
|
|
openFirstSystem(in: app)
|
|
|
|
let shareButton = app.buttons["system-overview-share-button"]
|
|
XCTAssertTrue(shareButton.waitForExistence(timeout: 15))
|
|
shareButton.tap()
|
|
|
|
let reportItem = app.buttons.matching(
|
|
NSPredicate(format: "label CONTAINS[c] 'PDF'")
|
|
).firstMatch
|
|
XCTAssertTrue(reportItem.waitForExistence(timeout: 10))
|
|
reportItem.tap()
|
|
|
|
// Quick Look lives in its own navigation stack; the Done button proves
|
|
// the navigation bar exists, the share item proves the file can leave
|
|
// the preview.
|
|
let doneButton = app.buttons["quick-look-done-button"]
|
|
XCTAssertTrue(
|
|
doneButton.waitForExistence(timeout: 60),
|
|
"Quick Look preview must be embedded in a navigation bar"
|
|
)
|
|
|
|
// Scope the action lookup to the preview's own navigation bar so the
|
|
// Overview share button underneath can never satisfy it.
|
|
let previewBar = app.navigationBars.containing(
|
|
.button,
|
|
identifier: "quick-look-done-button"
|
|
).firstMatch
|
|
XCTAssertTrue(previewBar.waitForExistence(timeout: 10))
|
|
|
|
let actionButtons = previewBar.buttons.allElementsBoundByIndex
|
|
.filter { $0.identifier != "quick-look-done-button" }
|
|
XCTAssertFalse(
|
|
actionButtons.isEmpty,
|
|
"Quick Look preview must offer an action button to share or open the file"
|
|
)
|
|
|
|
doneButton.tap()
|
|
XCTAssertTrue(shareButton.waitForExistence(timeout: 10))
|
|
}
|
|
|
|
// MARK: - Helpers
|
|
|
|
private func launch(arguments: [String]) -> XCUIApplication {
|
|
let app = XCUIApplication()
|
|
app.launchArguments = arguments
|
|
app.launch()
|
|
return app
|
|
}
|
|
|
|
private func openFirstSystem(in app: XCUIApplication) {
|
|
let list: XCUIElement
|
|
if app.collectionViews["systems-list"].waitForExistence(timeout: 15) {
|
|
list = app.collectionViews["systems-list"]
|
|
} else {
|
|
list = app.collectionViews.firstMatch
|
|
}
|
|
XCTAssertTrue(list.waitForExistence(timeout: 15))
|
|
|
|
let firstCell = list.cells.element(boundBy: 0)
|
|
XCTAssertTrue(firstCell.waitForExistence(timeout: 10))
|
|
|
|
let cellButton = firstCell.buttons.firstMatch
|
|
if cellButton.exists {
|
|
cellButton.tap()
|
|
} else {
|
|
firstCell.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
|
|
}
|
|
}
|
|
}
|