实现我的 Tab、对齐 Android 流程并接入 OSS 上传
This commit is contained in:
52
suixinkanTests/ProfileViewModelTests.swift
Normal file
52
suixinkanTests/ProfileViewModelTests.swift
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// ProfileViewModelTests.swift
|
||||
// suixinkanTests
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import suixinkan
|
||||
|
||||
@MainActor
|
||||
/// 个人信息页 ViewModel 测试。
|
||||
final class ProfileViewModelTests: XCTestCase {
|
||||
func testDisplayNicknameUsesFallbackWhenEmpty() {
|
||||
let viewModel = ProfileViewModel()
|
||||
XCTAssertEqual(viewModel.displayNickname, "未设置昵称")
|
||||
}
|
||||
|
||||
func testShowPhotographerFieldsWhenRoleCodeIsPhotographer() {
|
||||
AppStore.shared.roleCode = AppRoleCode.photographer.rawValue
|
||||
let viewModel = ProfileViewModel()
|
||||
XCTAssertTrue(viewModel.showPhotographerFields)
|
||||
AppStore.shared.roleCode = ""
|
||||
}
|
||||
|
||||
func testMaskCardNumberShowsLastFourDigits() {
|
||||
XCTAssertEqual(
|
||||
ProfileViewModel.maskCardNumber("6222021234567890"),
|
||||
"**** **** **** 7890"
|
||||
)
|
||||
}
|
||||
|
||||
func testUpdatePasswordRejectsShortPassword() async {
|
||||
let session = MockURLSession(responses: [])
|
||||
let api = ProfileAPI(client: APIClient(environment: .testing, session: session))
|
||||
let viewModel = ProfileViewModel()
|
||||
|
||||
do {
|
||||
try await viewModel.updatePassword("12345", api: api)
|
||||
XCTFail("短密码应抛出校验错误")
|
||||
} catch {
|
||||
guard let validationError = error as? ProfileValidationError else {
|
||||
return XCTFail("期望 ProfileValidationError,实际为 \(error)")
|
||||
}
|
||||
XCTAssertEqual(validationError, .shortPassword)
|
||||
}
|
||||
}
|
||||
|
||||
func testBeginEditingPrefillsNickname() {
|
||||
let viewModel = ProfileViewModel()
|
||||
viewModel.beginEditing()
|
||||
XCTAssertTrue(viewModel.isEditingProfile)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user