generated from StanfordBDHG/SwiftPackageTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
357 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
Tests/UITests/TestAppUITests/HealthMeasurementsTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import XCTest | ||
|
||
|
||
class HealthMeasurementsTests: XCTestCase { | ||
override func setUpWithError() throws { | ||
try super.setUpWithError() | ||
|
||
continueAfterFailure = false | ||
} | ||
|
||
|
||
@MainActor | ||
func testNoMeasurements() { | ||
let app = XCUIApplication() | ||
app.launch() | ||
|
||
XCTAssert(app.buttons["Measurements"].waitForExistence(timeout: 2.0)) | ||
app.buttons["Measurements"].tap() | ||
|
||
XCTAssert(app.staticTexts["No Samples"].waitForExistence(timeout: 0.5)) | ||
app.staticTexts["No Samples"].tap() | ||
|
||
XCTAssert(app.navigationBars.buttons["Add Measurement"].exists) | ||
app.navigationBars.buttons["Add Measurement"].tap() | ||
|
||
XCTAssert(app.staticTexts["No Pending Measurements"].waitForExistence(timeout: 2.0)) | ||
XCTAssert(app.navigationBars.buttons["Dismiss"].exists) | ||
app.navigationBars.buttons["Dismiss"].tap() | ||
} | ||
|
||
@MainActor | ||
func testWeightMeasurement() { | ||
let app = XCUIApplication() | ||
app.launch() | ||
|
||
XCTAssert(app.buttons["Measurements"].waitForExistence(timeout: 2.0)) | ||
app.buttons["Measurements"].tap() | ||
|
||
XCTAssert(app.navigationBars.buttons["More"].exists) | ||
app.navigationBars.buttons["More"].tap() | ||
XCTAssert(app.buttons["Simulate Weight"].waitForExistence(timeout: 0.5)) | ||
app.buttons["Simulate Weight"].tap() | ||
|
||
XCTAssert(app.staticTexts["Measurement Recorded"].waitForExistence(timeout: 2.0)) | ||
XCTAssert(app.staticTexts["42 kg"].exists) | ||
XCTAssert(app.staticTexts["179 cm, 23 BMI"].exists) | ||
XCTAssert(app.buttons["Save"].exists) | ||
XCTAssert(app.buttons["Discard"].exists) | ||
|
||
app.buttons["Save"].tap() | ||
|
||
XCTAssert(app.staticTexts["42 kg"].waitForExistence(timeout: 0.5)) | ||
XCTAssert(app.staticTexts["23 count"].exists) | ||
XCTAssert(app.staticTexts["1.79 m"].exists) | ||
XCTAssert(app.staticTexts["Mock Device"].exists) | ||
} | ||
|
||
@MainActor | ||
func testBloodPressureMeasurement() { | ||
let app = XCUIApplication() | ||
app.launch() | ||
|
||
XCTAssert(app.buttons["Measurements"].waitForExistence(timeout: 2.0)) | ||
app.buttons["Measurements"].tap() | ||
|
||
XCTAssert(app.navigationBars.buttons["More"].exists) | ||
app.navigationBars.buttons["More"].tap() | ||
XCTAssert(app.buttons["Simulate Blood Pressure"].waitForExistence(timeout: 0.5)) | ||
app.buttons["Simulate Blood Pressure"].tap() | ||
|
||
XCTAssert(app.staticTexts["Measurement Recorded"].waitForExistence(timeout: 2.0)) | ||
XCTAssert(app.staticTexts["103/64 mmHg"].exists) | ||
XCTAssert(app.staticTexts["62 BPM"].exists) | ||
XCTAssert(app.buttons["Save"].exists) | ||
XCTAssert(app.buttons["Discard"].exists) | ||
|
||
app.buttons["Save"].tap() | ||
|
||
XCTAssert(app.staticTexts["103 mmHg"].waitForExistence(timeout: 0.5)) | ||
XCTAssert(app.staticTexts["64 mmHg"].exists) | ||
XCTAssert(app.staticTexts["62 count/min"].exists) | ||
XCTAssert(app.staticTexts["Mock Device"].exists) | ||
} | ||
|
||
@MainActor | ||
func testMultiMeasurementsAndDiscarding() throws { | ||
let app = XCUIApplication() | ||
app.launch() | ||
|
||
XCTAssert(app.buttons["Measurements"].waitForExistence(timeout: 2.0)) | ||
app.buttons["Measurements"].tap() | ||
|
||
XCTAssert(app.navigationBars.buttons["More"].exists) | ||
app.navigationBars.buttons["More"].tap() | ||
XCTAssert(app.buttons["Simulate Weight"].waitForExistence(timeout: 0.5)) | ||
app.buttons["Simulate Weight"].tap() | ||
|
||
XCTAssert(app.navigationBars.buttons["Dismiss"].waitForExistence(timeout: 0.5)) | ||
app.navigationBars.buttons["Dismiss"].tap() | ||
|
||
XCTAssert(app.navigationBars.buttons["More"].exists) | ||
app.navigationBars.buttons["More"].tap() | ||
XCTAssert(app.buttons["Simulate Blood Pressure"].waitForExistence(timeout: 0.5)) | ||
app.buttons["Simulate Blood Pressure"].tap() | ||
|
||
XCTAssert(app.staticTexts["Measurement Recorded"].waitForExistence(timeout: 2.0)) | ||
XCTAssert(app.staticTexts["103/64 mmHg"].exists) | ||
XCTAssert(app.staticTexts["62 BPM"].exists) | ||
XCTAssert(app.buttons["Save"].exists) | ||
XCTAssert(app.buttons["Discard"].exists) | ||
|
||
XCTAssert(app.steppers["Page"].exists) | ||
let page1Value = try XCTUnwrap(app.steppers["Page"].value as? String, "Unexpected value \(String(describing: app.steppers["Page"].value))") | ||
XCTAssertEqual(page1Value, "Page 1 of 2") | ||
app.steppers["Page"].coordinate(withNormalizedOffset: .init(dx: 0.8, dy: 0.5)).tap() | ||
let page2Value = try XCTUnwrap(app.steppers["Page"].value as? String, "Unexpected value \(String(describing: app.steppers["Page"].value))") | ||
XCTAssertEqual(page2Value, "Page 2 of 2") | ||
|
||
XCTAssert(app.staticTexts["Measurement Recorded"].waitForExistence(timeout: 2.0)) | ||
XCTAssert(app.staticTexts["42 kg"].exists) | ||
XCTAssert(app.staticTexts["179 cm, 23 BMI"].exists) | ||
XCTAssert(app.buttons["Save"].exists) | ||
XCTAssert(app.buttons["Discard"].exists) | ||
|
||
XCTAssert(app.navigationBars.buttons["Dismiss"].exists) | ||
app.navigationBars.buttons["Dismiss"].tap() | ||
|
||
XCTAssert(app.navigationBars.buttons["Add Measurement"].waitForExistence(timeout: 0.5)) | ||
app.navigationBars.buttons["Add Measurement"].tap() | ||
|
||
XCTAssert(app.buttons["Discard"].waitForExistence(timeout: 0.5)) | ||
app.buttons["Discard"].tap() | ||
|
||
XCTAssert(app.staticTexts["42 kg"].waitForExistence(timeout: 2.0)) | ||
XCTAssert(app.staticTexts["179 cm, 23 BMI"].exists) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import XCTest | ||
import XCTestExtensions | ||
|
||
|
||
class PairedDevicesTests: XCTestCase { | ||
override func setUpWithError() throws { | ||
try super.setUpWithError() | ||
|
||
continueAfterFailure = false | ||
} | ||
|
||
|
||
@MainActor | ||
func testTipsView() throws { | ||
let app = XCUIApplication() | ||
app.launchArguments = ["--testTips"] | ||
app.launch() | ||
|
||
XCTAssert(app.buttons["Devices"].waitForExistence(timeout: 2.0)) | ||
app.buttons["Devices"].tap() | ||
|
||
|
||
XCTAssert(app.staticTexts["Fully Unpair Device"].waitForExistence(timeout: 0.5)) | ||
XCTAssert(app.buttons["Open Settings"].exists) | ||
app.buttons["Open Settings"].tap() | ||
|
||
let settingsApp = XCUIApplication(bundleIdentifier: "com.apple.Preferences") | ||
XCTAssertEqual(settingsApp.state, .runningForeground) | ||
} | ||
|
||
@MainActor | ||
func testDiscoveringView() throws { | ||
let app = XCUIApplication() | ||
app.launch() | ||
|
||
XCTAssert(app.buttons["Devices"].waitForExistence(timeout: 2.0)) | ||
app.buttons["Devices"].tap() | ||
|
||
|
||
XCTAssert(app.staticTexts["No Devices"].exists) | ||
XCTAssert(app.buttons["Pair New Device"].exists) | ||
app.buttons["Pair New Device"].tap() | ||
|
||
XCTAssert(app.staticTexts["Discovering"].waitForExistence(timeout: 0.5)) | ||
XCTAssert(app.navigationBars.buttons["Dismiss"].exists) | ||
app.navigationBars.buttons["Dismiss"].tap() | ||
|
||
XCTAssert(app.staticTexts["No Devices"].waitForExistence(timeout: 0.5)) | ||
// TODO: customize the pairing hint! | ||
} | ||
|
||
@MainActor | ||
func testPairDevice() throws { | ||
Check failure on line 61 in Tests/UITests/TestAppUITests/PairedDevicesTests.swift GitHub Actions / SwiftLint / SwiftLint
|
||
let app = XCUIApplication() | ||
app.launch() | ||
|
||
XCTAssert(app.buttons["Devices"].waitForExistence(timeout: 2.0)) | ||
app.buttons["Devices"].tap() | ||
|
||
XCTAssert(app.navigationBars.buttons["More"].exists) | ||
app.navigationBars.buttons["More"].tap() | ||
|
||
XCTAssert(app.buttons["Discover Device"].waitForExistence(timeout: 0.5)) | ||
app.buttons["Discover Device"].tap() | ||
|
||
XCTAssert(app.staticTexts["Pair Accessory"].waitForExistence(timeout: 2.0)) | ||
XCTAssert(app.staticTexts["Do you want to pair \"Mock Device\" with the TestApp app?"].exists) | ||
XCTAssert(app.buttons["Pair"].exists) | ||
app.buttons["Pair"].tap() | ||
|
||
XCTAssert(app.staticTexts["Accessory Paired"].waitForExistence(timeout: 5.0)) | ||
XCTAssert(app.staticTexts["\"Mock Device\" was successfully paired with the TestApp app."].exists) | ||
XCTAssert(app.buttons["Done"].exists) | ||
app.buttons["Done"].tap() | ||
|
||
XCTAssert(app.buttons["Mock Device, 85 %"].waitForExistence(timeout: 0.5)) | ||
app.buttons["Mock Device, 85 %"].tap() | ||
|
||
XCTAssert(app.navigationBars.staticTexts["Device Details"].waitForExistence(timeout: 2.0)) | ||
XCTAssert(app.buttons["Name, Mock Device"].exists) | ||
XCTAssert(app.staticTexts["Model, MD1"].exists) | ||
XCTAssert(app.staticTexts["Battery, 85 %"].exists) | ||
XCTAssert(app.buttons["Forget This Device"].exists) | ||
XCTAssert(app.staticTexts["Synchronizing ..."].exists) // assert device currently connected | ||
|
||
app.buttons["Name, Mock Device"].tap() | ||
|
||
XCTAssert(app.textFields["enter device name"].exists) | ||
app.textFields["enter device name"].tap() | ||
app.typeText("2") | ||
|
||
app.dismissKeyboard() | ||
|
||
XCTAssert(app.navigationBars.buttons["Done"].waitForExistence(timeout: 0.5)) | ||
app.navigationBars.buttons["Done"].tap() | ||
|
||
XCTAssert(app.staticTexts["Name, Mock Device2"].waitForExistence(timeout: 0.5)) | ||
XCTAssert(app.navigationBars.buttons["Devices"].exists) | ||
app.navigationBars.buttons["Devices"].tap() | ||
|
||
XCTAssert(app.buttons["Mock Device2, 85 %"].waitForExistence(timeout: 2.0)) | ||
|
||
XCTAssert(app.navigationBars.buttons["More"].exists) | ||
app.navigationBars.buttons["More"].tap() | ||
XCTAssert(app.buttons["Disconnect"].waitForExistence(timeout: 0.5)) | ||
app.buttons["Disconnect"].tap() | ||
sleep(1) | ||
|
||
app.buttons["Mock Device2, 85 %"].tap() | ||
XCTAssert(app.navigationBars.buttons["Devices"].waitForExistence(timeout: 2.0)) | ||
app.navigationBars.buttons["Devices"].tap() | ||
|
||
XCTAssert(app.navigationBars.buttons["More"].exists) | ||
app.navigationBars.buttons["More"].tap() | ||
XCTAssert(app.buttons["Connect"].waitForExistence(timeout: 0.5)) | ||
app.buttons["Connect"].tap() | ||
sleep(3) | ||
|
||
|
||
XCTAssert(app.buttons["Mock Device2, 85 %"].waitForExistence(timeout: 0.5)) | ||
app.buttons["Mock Device2, 85 %"].tap() | ||
|
||
XCTAssert(app.buttons["Forget This Device"].waitForExistence(timeout: 2.0)) | ||
app.buttons["Forget This Device"].tap() | ||
|
||
XCTAssert(app.buttons["Forget Device"].waitForExistence(timeout: 2.0)) | ||
app.buttons["Forget Device"].tap() | ||
|
||
|
||
XCTAssert(app.staticTexts["Fully Unpair Device"].waitForExistence(timeout: 2.0)) | ||
} | ||
|
||
@MainActor | ||
func testPlusButton() { | ||
let app = XCUIApplication() | ||
app.launch() | ||
|
||
XCTAssert(app.buttons["Devices"].waitForExistence(timeout: 2.0)) | ||
app.buttons["Devices"].tap() | ||
|
||
XCTAssert(app.navigationBars.buttons["More"].exists) | ||
app.navigationBars.buttons["More"].tap() | ||
|
||
XCTAssert(app.buttons["Discover Device"].waitForExistence(timeout: 0.5)) | ||
app.buttons["Discover Device"].tap() | ||
|
||
XCTAssert(app.staticTexts["Pair Accessory"].waitForExistence(timeout: 2.0)) | ||
XCTAssert(app.buttons["Dismiss"].exists) | ||
app.buttons["Dismiss"].tap() | ||
|
||
XCTAssert(app.navigationBars.buttons["Add Device"].exists) | ||
app.navigationBars.buttons["Add Device"].tap() | ||
|
||
XCTAssert(app.staticTexts["Pair Accessory"].waitForExistence(timeout: 2.0)) | ||
} | ||
|
||
// TODO: forget devices test | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.