当您提供代码差异后,我将按照以下格式生成: ``` <type>(<scope>): <subject> <body> ``` 其中type会根据更改类型选择(feat、fix、docs、style、refactor等),scope表示影响范围,subject简要描述变更内容,body详细说明修改内容。
55 lines
1.7 KiB
Swift
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)
|
|
}
|
|
}
|