// // SessionExpiredDialogViewControllerTests.swift // suixinkanTests // import UIKit import XCTest @testable import suixinkan /// 登录失效弹窗测试,覆盖强制展示配置、Android 对齐文案与确认防重。 @MainActor final class SessionExpiredDialogViewControllerTests: XCTestCase { func testDialogUsesForcedPresentationAndAndroidCopy() throws { let dialog = SessionExpiredDialogViewController(onConfirm: {}) dialog.loadViewIfNeeded() XCTAssertEqual(dialog.modalPresentationStyle, .overFullScreen) XCTAssertEqual(dialog.modalTransitionStyle, .crossDissolve) XCTAssertTrue(dialog.isModalInPresentation) XCTAssertTrue(dialog.view.accessibilityViewIsModal) let labels = dialog.view.allSubviews(of: UILabel.self) XCTAssertTrue(labels.contains { $0.text == "登录提醒" }) XCTAssertTrue(labels.contains { $0.text == "当前用户已在其他设备登录,\n请重新登录" }) let button = try XCTUnwrap( dialog.view.allSubviews(of: UIButton.self).first { $0.accessibilityIdentifier == "sessionExpired.confirmButton" } ) XCTAssertEqual(button.title(for: .normal), "确认并退出登录") } func testConfirmCallbackOnlyRunsOnce() throws { var confirmationCount = 0 let dialog = SessionExpiredDialogViewController { confirmationCount += 1 } dialog.loadViewIfNeeded() let button = try XCTUnwrap( dialog.view.allSubviews(of: UIButton.self).first { $0.accessibilityIdentifier == "sessionExpired.confirmButton" } ) button.sendActions(for: .touchUpInside) button.sendActions(for: .touchUpInside) XCTAssertEqual(confirmationCount, 1) XCTAssertFalse(button.isEnabled) } } private extension UIView { func allSubviews(of type: View.Type) -> [View] { subviews.flatMap { subview -> [View] in let current = (subview as? View).map { [$0] } ?? [] return current + subview.allSubviews(of: type) } } }