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.
Add UI tests for generic views, fix unit tests
- Loading branch information
Showing
12 changed files
with
301 additions
and
53 deletions.
There are no files selected for viewing
45 changes: 0 additions & 45 deletions
45
Sources/SpeziDevicesUI/Measurements/CloseButtonLayer.swift
This file was deleted.
Oops, something went wrong.
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
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
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,55 @@ | ||
// | ||
// 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 | ||
// | ||
|
||
@_spi(TestingSupport) import SpeziDevices | ||
import SpeziDevicesUI | ||
import SwiftUI | ||
|
||
|
||
struct BluetoothViewsTest: View { | ||
@State private var device = MockDevice.createMockDevice() | ||
@State private var presentDeviceDetails = false | ||
|
||
var body: some View { | ||
NavigationStack { | ||
List { | ||
BluetoothUnavailableSection() | ||
|
||
Section { | ||
NearbyDeviceRow(peripheral: device, primaryAction: tapAction) { | ||
presentDeviceDetails = true | ||
} | ||
} header: { | ||
LoadingSectionHeader("Devices", loading: true) | ||
} | ||
} | ||
.navigationTitle("Views") | ||
.navigationDestination(isPresented: $presentDeviceDetails) { | ||
MockDeviceDetailsView(device) | ||
} | ||
} | ||
} | ||
|
||
|
||
@MainActor | ||
private func tapAction() { | ||
Task { | ||
switch device.state { | ||
case .disconnected, .disconnecting: | ||
await device.connect() | ||
case .connecting, .connected: | ||
await device.disconnect() | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
#Preview { | ||
BluetoothViewsTest() | ||
} |
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
42 changes: 42 additions & 0 deletions
42
Tests/UITests/TestApp/Views/BluetoothUnavailableSection.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,42 @@ | ||
// | ||
// 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 SpeziDevicesUI | ||
import SwiftUI | ||
|
||
|
||
struct BluetoothUnavailableSection: View { | ||
var body: some View { | ||
Section("Bluetooth Unavailable") { | ||
NavigationLink("Bluetooth Powered Off") { | ||
BluetoothUnavailableView(.poweredOff) | ||
} | ||
NavigationLink("Bluetooth Powered On") { | ||
BluetoothUnavailableView(.poweredOn) | ||
} | ||
NavigationLink("Bluetooth Unauthorized") { | ||
BluetoothUnavailableView(.unauthorized) | ||
} | ||
NavigationLink("Bluetooth Unsupported") { | ||
BluetoothUnavailableView(.unsupported) | ||
} | ||
NavigationLink("Bluetooth Unknown") { | ||
BluetoothUnavailableView(.unknown) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
#Preview { | ||
NavigationStack { | ||
List { | ||
BluetoothUnavailableSection() | ||
} | ||
} | ||
} |
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,54 @@ | ||
// | ||
// 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 | ||
// | ||
|
||
@_spi(TestingSupport) import SpeziDevices | ||
import SpeziDevicesUI | ||
import SpeziViews | ||
import SwiftUI | ||
|
||
|
||
struct MockDeviceDetailsView: View { | ||
private let device: MockDevice | ||
|
||
var body: some View { | ||
List { | ||
ListRow("Name") { | ||
Text(device.label) | ||
} | ||
if let model = device.deviceInformation.modelNumber { | ||
ListRow("Model") { | ||
Text(model) | ||
} | ||
} | ||
if let firmwareVersion = device.deviceInformation.firmwareRevision { | ||
ListRow("Firmware Version") { | ||
Text(firmwareVersion) | ||
} | ||
} | ||
if let battery = device.battery.batteryLevel { | ||
ListRow("Battery") { | ||
BatteryIcon(percentage: Int(battery)) | ||
.labelStyle(.reverse) | ||
} | ||
} | ||
} | ||
.navigationTitle(device.label) | ||
.navigationBarTitleDisplayMode(.inline) | ||
} | ||
|
||
init(_ device: MockDevice) { | ||
self.device = device | ||
} | ||
} | ||
|
||
|
||
#Preview { | ||
NavigationStack { | ||
MockDeviceDetailsView(MockDevice.createMockDevice()) | ||
} | ||
} |
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,75 @@ | ||
// | ||
// 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 BluetoothViewsTests: XCTestCase { | ||
override func setUpWithError() throws { | ||
try super.setUpWithError() | ||
|
||
continueAfterFailure = false | ||
} | ||
|
||
@MainActor | ||
func testBluetoothUnavailableViews() { | ||
let app = XCUIApplication() | ||
app.launch() | ||
|
||
XCTAssert(app.buttons["Views"].waitForExistence(timeout: 2.0)) | ||
app.buttons["Views"].tap() | ||
|
||
func navigateUnavailableView(name: String, expected: String?, back: Bool = true) { | ||
XCTAssert(app.buttons[name].waitForExistence(timeout: 2.0)) | ||
app.buttons[name].tap() | ||
if let expected { | ||
XCTAssert(app.staticTexts[expected].waitForExistence(timeout: 2.0)) | ||
} | ||
if back { | ||
XCTAssert(app.navigationBars.buttons["Views"].exists) | ||
app.navigationBars.buttons["Views"].tap() | ||
} | ||
} | ||
|
||
navigateUnavailableView(name: "Bluetooth Powered On", expected: nil) | ||
navigateUnavailableView(name: "Bluetooth Unauthorized", expected: "Bluetooth Prohibited") | ||
navigateUnavailableView(name: "Bluetooth Unsupported", expected: "Bluetooth Unsupported") | ||
navigateUnavailableView(name: "Bluetooth Unknown", expected: "Bluetooth Failure") | ||
navigateUnavailableView(name: "Bluetooth Powered Off", expected: "Bluetooth Off", back: false) | ||
|
||
XCTAssert(app.buttons["Open Settings"].exists) | ||
app.buttons["Open Settings"].tap() | ||
|
||
let settingsApp = XCUIApplication(bundleIdentifier: "com.apple.Preferences") | ||
XCTAssertEqual(settingsApp.state, .runningForeground) | ||
} | ||
|
||
@MainActor | ||
func testNearbyDeviceRow() { | ||
let app = XCUIApplication() | ||
app.launch() | ||
|
||
XCTAssert(app.buttons["Views"].waitForExistence(timeout: 2.0)) | ||
app.buttons["Views"].tap() | ||
|
||
XCTAssert(app.staticTexts["DEVICES"].exists) | ||
|
||
XCTAssert(app.buttons["Mock Device"].exists) | ||
app.buttons["Mock Device"].tap() | ||
|
||
XCTAssert(app.buttons["Mock Device, Connected"].waitForExistence(timeout: 5.0)) | ||
XCTAssert(app.buttons["Device Details"].exists) | ||
app.buttons["Device Details"].tap() | ||
|
||
XCTAssert(app.navigationBars.staticTexts["Mock Device"].waitForExistence(timeout: 2.0)) | ||
XCTAssert(app.staticTexts["Name, Mock Device"].exists) | ||
XCTAssert(app.staticTexts["Model, MD1"].exists) | ||
XCTAssert(app.staticTexts["Firmware Version, 1.0"].exists) | ||
XCTAssert(app.staticTexts["Battery, 85 %"].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
Oops, something went wrong.