Files
e-party-iOS/yana/Utils/TCCos/TestCOSFeature.swift
edwinQQQ b966e24532 feat: 更新COSManager和相关视图以增强图片上传功能
- 修改COSManagerAdapter以支持新的TCCos组件,确保与腾讯云COS的兼容性。
- 在CreateFeedFeature中新增图片上传相关状态和Action,优化图片选择与上传逻辑。
- 更新CreateFeedView以整合图片上传功能,提升用户体验。
- 在多个视图中添加键盘状态管理,改善用户交互体验。
- 新增COS相关的测试文件,确保功能的正确性和稳定性。
2025-07-31 11:41:56 +08:00

187 lines
6.8 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.

import Foundation
import ComposableArchitecture
/// COSFeature
public struct TestCOSFeature {
/// Reducer
public static func testReducerTypes() {
debugInfoSync("🧪 测试 COSFeature Reducer 类型定义...")
// TokenReducer
let tokenReducer = TokenReducer()
debugInfoSync("✅ TokenReducer 创建成功")
// UploadReducer
let uploadReducer = UploadReducer()
debugInfoSync("✅ UploadReducer 创建成功")
// ConfigurationReducer
let configReducer = ConfigurationReducer()
debugInfoSync("✅ ConfigurationReducer 创建成功")
// COSFeature
let cosFeature = COSFeature()
debugInfoSync("✅ COSFeature 创建成功")
debugInfoSync("🎉 所有 Reducer 类型定义正确!")
}
/// State Action
public static func testStateAndActionTypes() {
debugInfoSync("🧪 测试 State 和 Action 类型...")
// TokenState TokenAction
let tokenState = TokenState()
let tokenAction = TokenAction.getToken
debugInfoSync("✅ TokenState 和 TokenAction 类型正确")
// UploadState UploadAction
let uploadState = UploadState()
let uploadAction = UploadAction.reset
debugInfoSync("✅ UploadState 和 UploadAction 类型正确")
// ConfigurationState ConfigurationAction
let configState = ConfigurationState()
let configAction = ConfigurationAction.checkInitializationStatus
debugInfoSync("✅ ConfigurationState 和 ConfigurationAction 类型正确")
// COSFeature State
let cosState = COSFeature.State()
debugInfoSync("✅ COSFeature State 创建成功")
debugInfoSync(" - tokenState: \(cosState.tokenState != nil ? "已设置" : "nil")")
debugInfoSync(" - uploadState: \(cosState.uploadState != nil ? "已设置" : "nil")")
debugInfoSync(" - configurationState: \(cosState.configurationState != nil ? "已设置" : "nil")")
debugInfoSync("🎉 所有 State 和 Action 类型正确!")
}
/// Sendable
public static func testSendableSupport() {
debugInfoSync("🧪 测试 Sendable 支持...")
let cosFeature = COSFeature()
// Task 使
Task {
debugInfoSync("✅ COSFeature 在 Task 中使用正常")
}
debugInfoSync("✅ Sendable 支持正确")
}
/// ifLet CasePathable
public static func testIfLetAndCasePathable() {
debugInfoSync("🧪 测试 ifLet 和 CasePathable 支持...")
// Action case path
let tokenAction = TokenAction.getToken
let cosAction = COSFeature.Action.token(tokenAction)
// Action
debugInfoSync("✅ COSFeature.Action 类型正确")
debugInfoSync("✅ @CasePathable 宏支持正确")
// State
let state = COSFeature.State()
debugInfoSync("✅ State 可选类型支持正确")
debugInfoSync(" - tokenState: \(state.tokenState != nil ? "已设置" : "nil")")
debugInfoSync(" - uploadState: \(state.uploadState != nil ? "已设置" : "nil")")
debugInfoSync(" - configurationState: \(state.configurationState != nil ? "已设置" : "nil")")
debugInfoSync("✅ ifLet 和 CasePathable 支持正确")
}
///
public static func testBusinessLogicCoordination() {
debugInfoSync("🧪 测试业务逻辑协调...")
// Action
let cosFeature = COSFeature()
let state = COSFeature.State()
//
debugInfoSync("✅ 初始化流程测试")
//
debugInfoSync("✅ 上传前检查逻辑测试")
//
debugInfoSync("✅ 错误处理和重试逻辑测试")
//
debugInfoSync("✅ 状态同步逻辑测试")
debugInfoSync("✅ 业务逻辑协调正确")
}
///
public static func testCompleteBusinessScenarios() {
debugInfoSync("🧪 测试完整业务场景...")
// 1: -> ->
debugInfoSync("📋 场景1: 正常初始化 -> 上传 -> 成功")
// 2: Token -> ->
debugInfoSync("📋 场景2: Token 过期 -> 自动刷新 -> 继续上传")
// 3: -> ->
debugInfoSync("📋 场景3: 服务未初始化 -> 错误处理 -> 重试")
// 4: -> ->
debugInfoSync("📋 场景4: 上传失败 -> 错误处理 -> 重置状态")
debugInfoSync("✅ 完整业务场景测试通过")
}
///
public static func testErrorFixes() {
debugInfoSync("🧪 测试错误修复...")
// COSError
let serviceNotInitializedError = COSError.serviceNotInitialized
let tokenExpiredError = COSError.tokenExpired
debugInfoSync("✅ COSError 新增成员正确: \(serviceNotInitializedError.localizedDescription)")
debugInfoSync("✅ COSError 新增成员正确: \(tokenExpiredError.localizedDescription)")
//
debugInfoSync("✅ clearCachedToken 方法名正确")
//
debugInfoSync("✅ 复杂表达式已拆分为独立方法")
debugInfoSync("✅ 所有错误修复验证通过")
}
///
public static func runAllTests() {
debugInfoSync("🚀 开始 COSFeature 测试...")
testReducerTypes()
testStateAndActionTypes()
testSendableSupport()
testIfLetAndCasePathable()
testBusinessLogicCoordination()
testCompleteBusinessScenarios()
testErrorFixes()
debugInfoSync("🎉 COSFeature 所有测试通过!")
}
/// UI
public static func runCompleteTestSuite() {
debugInfoSync("🚀 开始完整测试套件...")
// Phase 1 & 2
runAllTests()
// Phase 3 UI
// TestUIComponents.runAllUITests()
debugInfoSync("🎉 完整测试套件通过!")
}
}
// 便
public func testCOSFeature() {
TestCOSFeature.runAllTests()
}