Files
kangkang/康康Tests/HealthProfileImportTests.swift
link2026 77a4ee1c37 缺少代码差异信息,无法生成具体的commit message。请提供code differences内容以便分析并生成符合Angular规范的提交信息。
当您提供代码差异后,我将按照以下格式生成:

```
<type>(<scope>): <subject>

<body>
```

其中type会根据更改类型选择(feat、fix、docs、style、refactor等),scope表示影响范围,subject简要描述变更内容,body详细说明修改内容。
2026-06-07 14:17:18 +08:00

55 lines
1.7 KiB
Swift

import Foundation
import Testing
@testable import
struct HealthProfileImportTests {
@Test func previewKeepsExistingValuesWhenHealthKitValueIsMissing() {
let existing = UserProfile(
birthYear: 1988,
biologicalSexRaw: "female",
heightCM: 162,
bloodTypeRaw: "A"
)
let draft = HealthProfileImportDraft(heightCM: 175)
let preview = HealthProfileImportPreview(draft: draft, current: existing)
#expect(preview.birthYear.current == "1988")
#expect(preview.birthYear.imported == nil)
#expect(preview.birthYear.willUpdate == false)
#expect(preview.sex.imported == nil)
#expect(preview.height.imported == "175cm")
#expect(preview.height.willUpdate == true)
#expect(preview.bloodType.imported == nil)
}
@Test func applyOnlyOverwritesFieldsPresentInDraft() {
let profile = UserProfile(
birthYear: 1988,
biologicalSexRaw: "female",
heightCM: 162,
bloodTypeRaw: "A"
)
let draft = HealthProfileImportDraft(
birthYear: 1990,
biologicalSexRaw: "male",
heightCM: nil,
bloodTypeRaw: "O"
)
draft.apply(to: profile, now: Date(timeIntervalSince1970: 123))
#expect(profile.birthYear == 1990)
#expect(profile.biologicalSexRaw == "male")
#expect(profile.heightCM == 162)
#expect(profile.bloodTypeRaw == "O")
#expect(profile.updatedAt == Date(timeIntervalSince1970: 123))
}
@Test func emptyDraftReportsNoImportableFields() {
let draft = HealthProfileImportDraft()
#expect(draft.hasAnyImportableField == false)
}
}