Skip to content

Commit

Permalink
Allow to customize the measurements loaded with testing support (#14)
Browse files Browse the repository at this point in the history
# Allow to customize the measurements loaded with testing support

## ♻️ Current situation & Problem
Previously, we used a fixed, default timestamp when creating the current
measurement values for Omron Mock devices (we didn't even specify a
timestamp with the weight scale). This PR improves this mechanism by
allowing to specify a custom time and allowing to specify a time for the
weight scale at all.

## ⚙️ Release Notes 
* Added new `timeStamp` parameter when creating Omron mock devices.


## 📚 Documentation
Updated.

## ✅ Testing
--

## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
Supereg authored Sep 17, 2024
1 parent dc8dcd5 commit 85aee3d
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 92 deletions.
31 changes: 0 additions & 31 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ jobs:
scheme: SpeziDevices-Package
resultBundle: SpeziDevices-iOS.xcresult
artifactname: SpeziDevices-iOS.xcresult
packageios_latest:
name: Build and Test Swift Package iOS Latest
uses: StanfordSpezi/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
with:
runsonlabels: '["macOS", "self-hosted"]'
scheme: SpeziDevices-Package
xcodeversion: latest
swiftVersion: 6
resultBundle: SpeziDevices-iOS-Latest.xcresult
artifactname: SpeziDevices-iOS-Latest.xcresult
ios:
name: Build and Test iOS
uses: StanfordSpezi/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
Expand All @@ -43,27 +33,6 @@ jobs:
scheme: TestApp
resultBundle: TestApp-iOS.xcresult
artifactname: TestApp-iOS.xcresult
ios_latest:
name: Build and Test iOS Latest
uses: StanfordSpezi/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
with:
runsonlabels: '["macOS", "self-hosted"]'
path: 'Tests/UITests'
scheme: TestApp
xcodeversion: latest
swiftVersion: 6
resultBundle: TestApp-iOS-Latest.xcresult
artifactname: TestApp-iOS-Latest.xcresult
codeql:
name: CodeQL
uses: StanfordSpezi/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
with:
codeql: true
test: false
scheme: SpeziDevices-Package
permissions:
security-events: write
actions: read
uploadcoveragereport:
name: Upload Coverage Report
needs: [packageios, ios]
Expand Down
43 changes: 8 additions & 35 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.9
// swift-tools-version:6.0

//
// This source file is part of the Stanford SpeziDevices open source project
Expand All @@ -12,13 +12,6 @@ import class Foundation.ProcessInfo
import PackageDescription


#if swift(<6)
let swiftConcurrency: SwiftSetting = .enableExperimentalFeature("StrictConcurrency")
#else
let swiftConcurrency: SwiftSetting = .enableUpcomingFeature("StrictConcurrency")
#endif


let package = Package(
name: "SpeziDevices",
defaultLocalization: "en",
Expand All @@ -32,13 +25,13 @@ let package = Package(
.library(name: "SpeziOmron", targets: ["SpeziOmron"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-collections", from: "1.1.1"),
.package(url: "https://github.com/StanfordSpezi/SpeziFoundation", from: "2.0.0-beta.1"),
.package(url: "https://github.com/StanfordSpezi/Spezi", from: "1.7.1"),
.package(url: "https://github.com/StanfordSpezi/SpeziViews", from: "1.5.0"),
.package(url: "https://github.com/StanfordSpezi/SpeziBluetooth", from: "3.0.1"),
.package(url: "https://github.com/StanfordSpezi/SpeziNetworking", from: "2.1.1"),
.package(url: "https://github.com/StanfordBDHG/XCTestExtensions", from: "1.0.0")
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.1"),
.package(url: "https://github.com/StanfordSpezi/SpeziFoundation.git", from: "2.0.0-beta.1"),
.package(url: "https://github.com/StanfordSpezi/Spezi.git", from: "1.7.1"),
.package(url: "https://github.com/StanfordSpezi/SpeziViews.git", from: "1.5.0"),
.package(url: "https://github.com/StanfordSpezi/SpeziBluetooth.git", from: "3.0.1"),
.package(url: "https://github.com/StanfordSpezi/SpeziNetworking.git", from: "2.1.1"),
.package(url: "https://github.com/StanfordBDHG/XCTestExtensions.git", from: "1.0.0")
] + swiftLintPackage(),
targets: [
.target(
Expand All @@ -51,10 +44,6 @@ let package = Package(
.product(name: "SpeziViews", package: "SpeziViews"),
.product(name: "Spezi", package: "Spezi")
],
swiftSettings: [
swiftConcurrency,
.enableUpcomingFeature("InferSendableFromCaptures")
],
plugins: [] + swiftLintPlugin()
),
.target(
Expand All @@ -68,10 +57,6 @@ let package = Package(
resources: [
.process("Resources")
],
swiftSettings: [
swiftConcurrency,
.enableUpcomingFeature("InferSendableFromCaptures")
],
plugins: [] + swiftLintPlugin()
),
.target(
Expand All @@ -84,10 +69,6 @@ let package = Package(
resources: [
.process("Resources")
],
swiftSettings: [
swiftConcurrency,
.enableUpcomingFeature("InferSendableFromCaptures")
],
plugins: [] + swiftLintPlugin()
),
.testTarget(
Expand All @@ -100,10 +81,6 @@ let package = Package(
.product(name: "SpeziBluetoothServices", package: "SpeziBluetooth"),
.product(name: "XCTestExtensions", package: "XCTestExtensions")
],
swiftSettings: [
swiftConcurrency,
.enableUpcomingFeature("InferSendableFromCaptures")
],
plugins: [] + swiftLintPlugin()
),
.testTarget(
Expand All @@ -114,10 +91,6 @@ let package = Package(
.product(name: "XCTByteCoding", package: "SpeziNetworking"),
.product(name: "XCTestExtensions", package: "XCTestExtensions")
],
swiftSettings: [
swiftConcurrency,
.enableUpcomingFeature("InferSendableFromCaptures")
],
plugins: [] + swiftLintPlugin()
)
]
Expand Down
21 changes: 17 additions & 4 deletions Sources/SpeziDevices/HealthMeasurements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,22 @@ extension HealthMeasurements {
/// Call in preview simulator wrappers.
///
/// Loads a mock measurement to display in preview.
/// - Parameters:
/// - weightMeasurement: The weight measurement that should be loaded.
/// - weightResolution: The weight resolution to use.
/// - heightResolution: The height resolution to use.
@_spi(TestingSupport)
@MainActor
public func loadMockWeightMeasurement() {
let device = MockDevice.createMockDevice()
public func loadMockWeightMeasurement(
weightMeasurement: WeightMeasurement = .mock(),
weightResolution: WeightScaleFeature.WeightResolution = .resolution5g,
heightResolution: WeightScaleFeature.HeightResolution = .resolution1mm
) {
let device = MockDevice.createMockDevice(
weightMeasurement: weightMeasurement,
weightResolution: weightResolution,
heightResolution: heightResolution
)

guard let measurement = device.weightScale.weightMeasurement else {
preconditionFailure("Mock Weight Measurement was never injected!")
Expand All @@ -349,10 +361,11 @@ extension HealthMeasurements {
/// Call in preview simulator wrappers.
///
/// Loads a mock measurement to display in preview.
/// - Parameter bloodPressureMeasurement: The blood pressure measurement that should be loaded.
@_spi(TestingSupport)
@MainActor
public func loadMockBloodPressureMeasurement() {
let device = MockDevice.createMockDevice()
public func loadMockBloodPressureMeasurement(bloodPressureMeasurement: BloodPressureMeasurement = .mock()) {
let device = MockDevice.createMockDevice(bloodPressureMeasurement: bloodPressureMeasurement)

guard let measurement = device.bloodPressure.bloodPressureMeasurement else {
preconditionFailure("Mock Blood Pressure Measurement was never injected!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public struct MeasurementsRecordedSheet: View {

#if DEBUG
#Preview {
@State var isPresented = true
@State @Previewable var isPresented = true
return Text(verbatim: "")
.sheet(isPresented: $isPresented) {
MeasurementsRecordedSheet { samples in
Expand All @@ -196,7 +196,7 @@ public struct MeasurementsRecordedSheet: View {
}

#Preview {
@State var isPresented = true
@State @Previewable var isPresented = true
return Text(verbatim: "")
.sheet(isPresented: $isPresented) {
MeasurementsRecordedSheet { samples in
Expand All @@ -209,7 +209,7 @@ public struct MeasurementsRecordedSheet: View {
}

#Preview {
@State var isPresented = true
@State @Previewable var isPresented = true
return Text(verbatim: "")
.sheet(isPresented: $isPresented) {
MeasurementsRecordedSheet { samples in
Expand All @@ -222,7 +222,7 @@ public struct MeasurementsRecordedSheet: View {
}

#Preview {
@State var isPresented = true
@State @Previewable var isPresented = true
return Text(verbatim: "")
.sheet(isPresented: $isPresented) {
MeasurementsRecordedSheet { samples in
Expand All @@ -239,7 +239,7 @@ public struct MeasurementsRecordedSheet: View {
}

#Preview {
@State var isPresented = true
@State @Previewable var isPresented = true
return Text(verbatim: "")
.sheet(isPresented: $isPresented) {
MeasurementsRecordedSheet { samples in
Expand Down
4 changes: 3 additions & 1 deletion Sources/SpeziOmron/Devices/OmronBloodPressureCuff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ extension OmronBloodPressureCuff {
/// - state: The initial state.
/// - nearby: The nearby state.
/// - manufacturerData: The initial manufacturer data.
/// - timeStamp: The timestamp of the latest measurement.
/// - simulateRealDevice: If `true`, the real onChange handlers with be set up with the mock device.
/// - Returns: Returns the mock device instance.
public static func createMockDevice( // swiftlint:disable:this function_body_length
Expand All @@ -141,6 +142,7 @@ extension OmronBloodPressureCuff {
manufacturerData: OmronManufacturerData = OmronManufacturerData(pairingMode: .pairingMode, users: [
.init(id: 1, sequenceNumber: 2, recordsNumber: 1)
]),
timeStamp: DateTime = DateTime(year: 2024, month: .june, day: 5, hours: 12, minutes: 33, seconds: 11),
simulateRealDevice: Bool = false
) -> OmronBloodPressureCuff {
let device = OmronBloodPressureCuff()
Expand All @@ -167,7 +169,7 @@ extension OmronBloodPressureCuff {
diastolic: diastolic,
meanArterialPressure: 77,
unit: .mmHg,
timeStamp: DateTime(year: 2024, month: .june, day: 5, hours: 12, minutes: 33, seconds: 11),
timeStamp: timeStamp,
pulseRate: pulseRate,
userId: 1,
measurementStatus: []
Expand Down
5 changes: 4 additions & 1 deletion Sources/SpeziOmron/Devices/OmronWeightScale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ extension OmronWeightScale {
/// - state: The initial state.
/// - nearby: The nearby state.
/// - manufacturerData: The initial manufacturer data.
/// - timeStamp: The timestamp of the latest measurement.
/// - simulateRealDevice: If `true`, the real onChange handlers with be set up with the mock device.
/// - Returns: Returns the mock device instance.
public static func createMockDevice( // swiftlint:disable:this function_body_length
Expand All @@ -117,6 +118,7 @@ extension OmronWeightScale {
manufacturerData: OmronManufacturerData = OmronManufacturerData(pairingMode: .pairingMode, users: [
.init(id: 1, sequenceNumber: 2, recordsNumber: 1)
]),
timeStamp: DateTime = DateTime(year: 2024, month: .june, day: 5, hours: 12, minutes: 33, seconds: 11),
simulateRealDevice: Bool = false
) -> OmronWeightScale {
let device = OmronWeightScale()
Expand All @@ -140,7 +142,8 @@ extension OmronWeightScale {

let measurement = WeightMeasurement(
weight: weight,
unit: .si
unit: .si,
timeStamp: timeStamp
)

device.weightScale.$features.inject(features)
Expand Down
6 changes: 1 addition & 5 deletions Tests/SpeziOmronTests/SpeziOmronTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,4 @@ final class SpeziOmronTests: XCTestCase {
}


#if compiler(<6)
extension SpeziDevices.MockDevice: SpeziOmron.OmronHealthDevice {}
#else
extension MockDevice: @retroactive OmronHealthDevice {}
#endif
extension MockDevice: OmronHealthDevice {}
15 changes: 6 additions & 9 deletions Tests/UITests/UITests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 56;
objectVersion = 77;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -220,7 +220,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1500;
LastUpgradeCheck = 1540;
LastUpgradeCheck = 1600;
TargetAttributes = {
2F6D139128F5F384007C25D6 = {
CreatedOnToolsVersion = 14.1;
Expand All @@ -232,7 +232,6 @@
};
};
buildConfigurationList = 2F6D138D28F5F384007C25D6 /* Build configuration list for PBXProject "UITests" */;
compatibilityVersion = "Xcode 14.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
Expand All @@ -243,6 +242,7 @@
packageReferences = (
A959B7F12C2D646500ACA775 /* XCRemoteSwiftPackageReference "XCTestExtensions" */,
);
preferredProjectObjectVersion = 77;
productRefGroup = 2F6D139328F5F384007C25D6 /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -371,6 +371,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 6.0;
TVOS_DEPLOYMENT_TARGET = 17.0;
WATCHOS_DEPLOYMENT_TARGET = 10.0;
XROS_DEPLOYMENT_TARGET = 1.0;
Expand Down Expand Up @@ -431,6 +432,7 @@
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 6.0;
TVOS_DEPLOYMENT_TARGET = 17.0;
VALIDATE_PRODUCT = YES;
WATCHOS_DEPLOYMENT_TARGET = 10.0;
Expand All @@ -441,7 +443,6 @@
2F6D13B728F5F386007C25D6 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
Expand Down Expand Up @@ -477,7 +478,6 @@
2F6D13B828F5F386007C25D6 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
Expand Down Expand Up @@ -513,7 +513,6 @@
2F6D13BD28F5F386007C25D6 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 637867499T;
Expand All @@ -536,7 +535,6 @@
2F6D13BE28F5F386007C25D6 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 637867499T;
Expand Down Expand Up @@ -617,6 +615,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = TEST;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 6.0;
TVOS_DEPLOYMENT_TARGET = 17.0;
WATCHOS_DEPLOYMENT_TARGET = 10.0;
XROS_DEPLOYMENT_TARGET = 1.0;
Expand All @@ -626,7 +625,6 @@
2FB07588299DDB6000C0B37F /* Test */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
Expand Down Expand Up @@ -662,7 +660,6 @@
2FB07589299DDB6000C0B37F /* Test */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 637867499T;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down

0 comments on commit 85aee3d

Please sign in to comment.