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

262 lines
9.0 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 SwiftUI
import ComposableArchitecture
// MARK: - UI
/*
/// UI
public struct TestUIComponents {
/// COSView
public static func testCOSView() {
debugInfoSync("🧪 COSView ...")
//
let testState = COSFeature.State(
tokenState: TokenState(
currentToken: createTestToken(),
isLoading: false,
statusMessage: "Token ",
error: nil
),
uploadState: UploadState(
currentTask: createTestUploadTask(),
progress: 0.75,
result: nil,
error: nil,
isUploading: true
),
configurationState: ConfigurationState(
serviceStatus: .initialized(
configuration: COSConfiguration(
region: "ap-hongkong",
bucket: "test-bucket"
)
),
currentConfiguration: COSConfiguration(
region: "ap-hongkong",
bucket: "test-bucket"
),
error: nil
)
)
debugInfoSync(" COSView ")
debugInfoSync(" - Token : \(testState.tokenState?.currentToken?.bucket ?? "")")
debugInfoSync(" - : \(testState.uploadState?.progress ?? 0)")
debugInfoSync(" - : \(testState.configurationState?.serviceStatus.description ?? "")")
}
/// COSUploadView
public static func testCOSUploadView() {
debugInfoSync("🧪 COSUploadView ...")
//
let uploadingState = createUploadState(isUploading: true, progress: 0.5)
let successState = createUploadState(isUploading: false, result: "https://example.com/image.jpg")
let errorState = createUploadState(isUploading: false, error: "")
debugInfoSync(" COSUploadView ")
debugInfoSync(" - : \(uploadingState.isUploading)")
debugInfoSync(" - : \(successState.result != nil)")
debugInfoSync(" - : \(errorState.error != nil)")
}
/// COSErrorView
public static func testCOSErrorView() {
debugInfoSync("🧪 COSErrorView ...")
//
let tokenErrorState = createErrorState(
tokenError: "Token ",
uploadError: nil,
configError: nil
)
let uploadErrorState = createErrorState(
tokenError: nil,
uploadError: "",
configError: nil
)
let configErrorState = createErrorState(
tokenError: nil,
uploadError: nil,
configError: ""
)
debugInfoSync(" COSErrorView ")
debugInfoSync(" - Token : \(tokenErrorState.tokenState?.error != nil)")
debugInfoSync(" - : \(uploadErrorState.uploadState?.error != nil)")
debugInfoSync(" - : \(configErrorState.configurationState?.error != nil)")
}
/// UI
public static func testUIComponentsIntegration() {
debugInfoSync("🧪 UI ...")
// COS
let completeState = createCompleteState()
debugInfoSync(" UI ")
debugInfoSync(" - : ")
debugInfoSync(" - : ")
debugInfoSync(" - : ")
}
/// UI
public static func testUIComponentsResponsiveness() {
debugInfoSync("🧪 UI ...")
//
let initialState = COSFeature.State()
let loadingState = COSFeature.State(
tokenState: TokenState(isLoading: true),
uploadState: UploadState(isUploading: true, progress: 0.3),
configurationState: ConfigurationState(serviceStatus: .initializing)
)
let successState = COSFeature.State(
tokenState: TokenState(
currentToken: createTestToken(),
isLoading: false
),
uploadState: UploadState(
result: "https://example.com/success.jpg",
isUploading: false
),
configurationState: ConfigurationState(
serviceStatus: .initialized(
configuration: COSConfiguration(
region: "ap-hongkong",
bucket: "test-bucket"
)
)
)
)
debugInfoSync(" UI ")
debugInfoSync(" - : ")
debugInfoSync(" - : ")
debugInfoSync(" - : ")
}
/// UI
public static func runAllUITests() {
debugInfoSync("🚀 UI ...")
testCOSView()
testCOSUploadView()
testCOSErrorView()
testUIComponentsIntegration()
testUIComponentsResponsiveness()
debugInfoSync("🎉 UI ")
}
// MARK: -
/// Token
private static func createTestToken() -> TcTokenData {
return TcTokenData(
bucket: "test-bucket-1234567890",
sessionToken: "test-session-token",
region: "ap-hongkong",
customDomain: "",
accelerate: false,
appId: "1234567890",
secretKey: "test-secret-key",
expireTime: Int64(Date().timeIntervalSince1970) + 3600, // 1
startTime: Int64(Date().timeIntervalSince1970),
secretId: "test-secret-id"
)
}
///
private static func createTestUploadTask() -> UploadTask {
return UploadTask(
imageData: Data(repeating: 0, count: 1024 * 1024), // 1MB
fileName: "test_image_\(Date().timeIntervalSince1970).jpg",
status: .uploading(progress: 0.75)
)
}
///
private static func createUploadState(
isUploading: Bool,
progress: Double = 0.0,
result: String? = nil,
error: String? = nil
) -> UploadState {
return UploadState(
currentTask: isUploading ? createTestUploadTask() : nil,
progress: progress,
result: result,
error: error,
isUploading: isUploading
)
}
///
private static func createErrorState(
tokenError: String?,
uploadError: String?,
configError: String?
) -> COSFeature.State {
return COSFeature.State(
tokenState: TokenState(error: tokenError),
uploadState: UploadState(error: uploadError),
configurationState: ConfigurationState(error: configError)
)
}
///
private static func createCompleteState() -> COSFeature.State {
return COSFeature.State(
tokenState: TokenState(
currentToken: createTestToken(),
isLoading: false,
statusMessage: "Token ",
error: nil
),
uploadState: UploadState(
currentTask: createTestUploadTask(),
progress: 0.8,
result: "https://example.com/uploaded_image.jpg",
error: nil,
isUploading: false
),
configurationState: ConfigurationState(
serviceStatus: .initialized(
configuration: COSConfiguration(
region: "ap-hongkong",
bucket: "test-bucket-1234567890"
)
),
currentConfiguration: COSConfiguration(
region: "ap-hongkong",
bucket: "test-bucket-1234567890"
),
error: nil
)
)
}
}
// MARK: -
extension COSServiceStatus: CustomStringConvertible {
public var description: String {
switch self {
case .notInitialized:
return ""
case .initializing:
return ""
case .initialized(let config):
return " (\(config.bucket))"
case .failed(let error):
return " (\(error))"
}
}
}
*/