Files
suixinkan_uikit/suixinkanTests/ProfileViewModelTests.swift
汉秋 3c4ca7eefb Add submit-task flow aligned with Android and extract profile edit page.
Implement task creation with cloud/local media, order linking, and OSS upload; wire home entry and move profile nickname/avatar editing to ProfileEditViewController.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-07 10:12:20 +08:00

61 lines
1.9 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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 testApplyLocalProfileUpdateSyncsNicknameAndAvatar() {
AppStore.shared.userName = "全局昵称"
AppStore.shared.avatar = "https://cdn.example.com/new.jpg"
let viewModel = ProfileViewModel()
viewModel.applyLocalProfileUpdate()
XCTAssertEqual(viewModel.displayNickname, "全局昵称")
XCTAssertEqual(viewModel.displayAvatarURL, "https://cdn.example.com/new.jpg")
AppStore.shared.userName = ""
AppStore.shared.avatar = ""
}
}