Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaskollmer committed Jan 22, 2025
1 parent 3fc64ea commit fb4df52
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
9 changes: 9 additions & 0 deletions Tests/SpeziHealthKitTests/QueryTimeRangeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import SpeziHealthKit
import XCTest
import HealthKit



Expand All @@ -19,4 +20,12 @@ final class QueryTimeRangeTests: XCTestCase {
XCTAssertEqual(HealthKitQueryTimeRange.last(months: 1), .currentMonth)
XCTAssertEqual(HealthKitQueryTimeRange.last(years: 1), .currentYear)
}


@MainActor
func testHealthDataAvailability() async throws {
XCTAssertTrue(HKHealthStore.isHealthDataAvailable())
let healthStore = HKHealthStore()
try await healthStore.requestAuthorization(toShare: [], read: [HKQuantityType(.heartRate)])

Check failure on line 29 in Tests/SpeziHealthKitTests/QueryTimeRangeTests.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package / Test using xcodebuild or run fastlane

testHealthDataAvailability, failed: caught error: "Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo={NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.}"
}
}
8 changes: 8 additions & 0 deletions Tests/UITests/TestApp.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
}
],
"defaultOptions" : {
"commandLineArgumentEntries" : [
{
"argument" : "-AppleLocale"
},
{
"argument" : "en_US"
}
],
"targetForVariableExpansion" : {
"containerPath" : "container:UITests.xcodeproj",
"identifier" : "2F6D139128F5F384007C25D6",
Expand Down
2 changes: 2 additions & 0 deletions Tests/UITests/TestApp/HealthKitTestsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ struct HealthKitTestsView: View {
let unit: HKUnit

init(date: Date, duration: TimeInterval = 0, value: Double, unit: HKUnit) {
fatalError()
self.date = date

Check warning on line 160 in Tests/UITests/TestApp/HealthKitTestsView.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests / Test using xcodebuild or run fastlane

will never be executed
self.duration = duration
self.value = value
self.unit = unit
}

init(date components: DateComponents, duration: TimeInterval = 0, value: Double, unit: HKUnit) {
fatalError()
self.date = Calendar.current.date(from: components)!

Check warning on line 168 in Tests/UITests/TestApp/HealthKitTestsView.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests / Test using xcodebuild or run fastlane

will never be executed
self.duration = duration
self.value = value
Expand Down
30 changes: 15 additions & 15 deletions Tests/UITests/TestAppUITests/SpeziHealthKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ final class HealthKitTests: XCTestCase {
// datePickers[1].enterDate(DateComponents(year: 2024, month: 6, day: 2), assumingDatePickerStyle: .compact, in: app)
// datePickers[2].enterTime(DateComponents(hour: 20, minute: 15), assumingDatePickerStyle: .compact, in: app)

try launchHealthAppAndAddSomeSamples([
try launchAndAddSamples(healthApp: .healthApp(), [
// .init(sampleType: .steps, date: nil, enterSampleValueHandler: .enterSimpleNumericValue(520, inTextField: "Steps")),
.init(sampleType: .steps, date: .init(year: 1998, month: 06, day: 02, hour: 20, minute: 15), enterSampleValueHandler: .enterSimpleNumericValue(1, inTextField: "Steps")),
.steps(value: 1, date: .init(year: 1998, month: 06, day: 02, hour: 20, minute: 15))
])

app.activate()
Expand All @@ -43,11 +43,11 @@ final class HealthKitTests: XCTestCase {
// .init(sampleType: .steps, date: nil, enterSampleValueHandler: .enterSimpleNumericValue(520, inTextField: "Steps"))
// ])

try exitAppAndOpenHealth(.electrocardiograms)
try exitAppAndOpenHealth(.steps)
try exitAppAndOpenHealth(.pushes)
try exitAppAndOpenHealth(.restingHeartRate)
try exitAppAndOpenHealth(.activeEnergy)
try launchAndAddSample(healthApp: .healthApp(), .electrocardiogram())
try launchAndAddSample(healthApp: .healthApp(), .steps())
try launchAndAddSample(healthApp: .healthApp(), .pushes())
try launchAndAddSample(healthApp: .healthApp(), .restingHeartRate())
try launchAndAddSample(healthApp: .healthApp(), .activeEnergy())

app.activate()
XCTAssert(app.buttons["Ask for authorization"].waitForExistence(timeout: 2))
Expand Down Expand Up @@ -180,6 +180,7 @@ final class HealthKitTests: XCTestCase {
)
}

@MainActor
func testRepeatedHealthKitAuthorization() throws {
throw XCTSkip()
let app = XCUIApplication()

Check warning on line 186 in Tests/UITests/TestAppUITests/SpeziHealthKitTests.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests / Test using xcodebuild or run fastlane

code after 'throw' will never be executed
Expand Down Expand Up @@ -211,13 +212,13 @@ extension XCUIApplication {
XCTAssert(wait(for: .runningForeground, timeout: 10.0))
sleep(5)
//
// guard numberOfHKTypeIdentifiers() != hkTypeIdentifiers else {
// return
// }
//
// print("Wait 5 more seconds for HealthAppDataType to appear on screen ...")
// sleep(5)
//
guard numberOfHKTypeIdentifiers() != hkTypeIdentifiers else {
return
}

print("Wait 5 more seconds for HealthAppDataType to appear on screen ...")
sleep(5)

// guard numberOfHKTypeIdentifiers() != hkTypeIdentifiers else {
// return
// }
Expand Down Expand Up @@ -245,7 +246,6 @@ extension XCUIApplication {
observations[sampleType] = numberOfHKTypeNames
}
}
fatalError()
return observations
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
Expand Down

0 comments on commit fb4df52

Please sign in to comment.