Files
suixinkan_ios_new/suixinkan/App/AppUITestRouteDriver.swift
汉秋 d27438b264 补充 Auth/Tasks/ScenicPermission/Live 单元测试,并完善 UI Test 登录与会话稳定性。
移除 LoginViewModel 硬编码账号,扩展登录流程测试覆盖;调整 ZLoginSmokeUITests 执行顺序与路由直达逻辑,避免清空 Keychain 影响其它用例。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-26 12:44:10 +08:00

100 lines
3.4 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.

//
// AppUITestRouteDriver.swift
// suixinkan
//
// Created by Codex on 2026/6/26.
//
#if DEBUG
import SwiftUI
/// UI Test TabBar XCUITest push
@MainActor
enum AppUITestRouteDriver {
private static var didApply = false
///
static func applyIfNeeded(appRouter: AppRouter) async {
guard AppUITestLaunchState.isRunningUITests, !didApply else { return }
guard AppUITestLaunchState.pendingMenuTitle != nil
|| AppUITestLaunchState.pendingProfileRouteRawValue != nil else { return }
didApply = true
try? await Task.sleep(nanoseconds: 1_200_000_000)
if let menuTitle = AppUITestLaunchState.pendingMenuTitle {
openHomeMenu(title: menuTitle, appRouter: appRouter)
return
}
if let rawValue = AppUITestLaunchState.pendingProfileRouteRawValue {
openProfileRoute(rawValue: rawValue, appRouter: appRouter)
}
}
///
private static func openHomeMenu(title: String, appRouter: AppRouter) {
let resolvedTitle = resolveMenuTitle(title)
guard let item = HomeMenuRouter.debugAllMenuItems().first(where: { $0.title == resolvedTitle }) else {
return
}
appRouter.reset()
let resolved = HomeMenuRouter.resolve(uri: item.uri, title: item.title)
switch resolved {
case .tab(let tab):
appRouter.select(tab)
case .orders(let entry):
appRouter.selectOrders(entry: entry)
case .destination(let homeRoute):
appRouter.select(.home)
appRouter.router(for: .home).navigate(to: .home(homeRoute))
case .unsupported(let uri, let title, _):
appRouter.select(.home)
appRouter.router(for: .home).navigate(to: .home(.modulePlaceholder(uri: uri, title: title)))
case .placeholder(let uri, let title):
appRouter.select(.home)
appRouter.router(for: .home).navigate(to: .home(.modulePlaceholder(uri: uri, title: title)))
}
}
///
private static func openProfileRoute(rawValue: String, appRouter: AppRouter) {
let route: ProfileRoute?
switch rawValue {
case "settings":
route = .settings
case "realNameAuth":
route = .realNameAuth
case "accountSwitch":
route = .accountSwitch
case "debugHomeMenus":
route = .debugHomeMenus
case "agreement.about":
route = .agreement(.about)
case "agreement.userAgreement":
route = .agreement(.userAgreement)
case "agreement.privacyPolicy":
route = .agreement(.privacyPolicy)
default:
route = nil
}
guard let route else { return }
appRouter.reset()
appRouter.select(.profile)
appRouter.router(for: .profile).navigate(to: .profile(route))
}
/// UI Test
private static func resolveMenuTitle(_ title: String) -> String {
switch title {
case "系统设置":
return "设置中心"
default:
return title
}
}
}
#endif