新增启动参数直达首页与个人中心页面,引入 AppUITestRouteDriver 与 UITestSession 共享登录,并重构各模块用例的导航断言逻辑。 Co-authored-by: Cursor <cursoragent@cursor.com>
56 lines
2.0 KiB
Swift
56 lines
2.0 KiB
Swift
//
|
||
// AppUITestLaunchState.swift
|
||
// suixinkan
|
||
//
|
||
// Created by Codex on 2026/6/26.
|
||
//
|
||
|
||
import Foundation
|
||
|
||
/// UI 测试启动状态,仅在测试进程显式传入启动参数时生效。
|
||
enum AppUITestLaunchState {
|
||
/// UI Test 主开关,测试进程统一传入。
|
||
static let uiTestsArgument = "-suixinkan-ui-tests"
|
||
/// 冷启动前清理本地登录缓存。
|
||
static let resetArgument = "-suixinkan-ui-tests-reset-state"
|
||
/// 登录后直达首页调试菜单项(下一参数为菜单标题)。
|
||
static let openMenuArgument = "-suixinkan-ui-tests-open-menu"
|
||
/// 登录后直达个人中心二级页(下一参数为路由名)。
|
||
static let openProfileArgument = "-suixinkan-ui-tests-open-profile"
|
||
|
||
/// 当前进程是否由 XCUITest 启动。
|
||
static var isRunningUITests: Bool {
|
||
ProcessInfo.processInfo.arguments.contains(uiTestsArgument)
|
||
}
|
||
|
||
/// 待打开的首页调试菜单标题。
|
||
static var pendingMenuTitle: String? {
|
||
argumentValue(following: openMenuArgument)
|
||
}
|
||
|
||
/// 待打开的个人中心路由标识。
|
||
static var pendingProfileRouteRawValue: String? {
|
||
argumentValue(following: openProfileArgument)
|
||
}
|
||
|
||
/// 读取启动参数中紧跟在指定 flag 后的值。
|
||
private static func argumentValue(following flag: String) -> String? {
|
||
let arguments = ProcessInfo.processInfo.arguments
|
||
guard let index = arguments.firstIndex(of: flag), index + 1 < arguments.count else {
|
||
return nil
|
||
}
|
||
let value = arguments[index + 1].trimmingCharacters(in: .whitespacesAndNewlines)
|
||
return value.isEmpty ? nil : value
|
||
}
|
||
|
||
/// 按需在冷启动时清理 token、账号快照和偏好设置。
|
||
static func resetIfNeeded(arguments: [String] = ProcessInfo.processInfo.arguments) {
|
||
guard arguments.contains(resetArgument) else { return }
|
||
|
||
try? SessionTokenStore().clear()
|
||
AccountSnapshotStore().clear()
|
||
let preferences = AppPreferencesStore()
|
||
preferences.clear()
|
||
}
|
||
}
|