补充 Auth/Tasks/ScenicPermission/Live 单元测试,并完善 UI Test 登录与会话稳定性。

移除 LoginViewModel 硬编码账号,扩展登录流程测试覆盖;调整 ZLoginSmokeUITests 执行顺序与路由直达逻辑,避免清空 Keychain 影响其它用例。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-26 12:44:10 +08:00
parent aac8458b04
commit d27438b264
17 changed files with 1104 additions and 36 deletions

View File

@ -0,0 +1,71 @@
//
// ZLoginSmokeUITests.swift
// suixinkanUITests
//
// Z Keychain
//
import XCTest
final class ZLoginSmokeUITests: XCTestCase {
override func setUp() {
super.setUp()
continueAfterFailure = false
UITestSession.invalidate()
}
override func tearDown() {
UITestSession.invalidate()
super.tearDown()
}
///
func testFreshLaunchShowsLoginScreen() {
let app = SuixinkanApp(resetState: true).launch(waitForLoading: false)
XCTAssertTrue(app.application.staticTexts["login.title"].waitForExistence(timeout: 8))
XCTAssertTrue(app.application.textFields["login.username"].exists)
XCTAssertTrue(
app.application.secureTextFields["login.password"].exists
|| app.application.textFields["login.password"].exists
)
XCTAssertTrue(app.application.buttons["login.submit"].exists)
XCTAssertTrue(app.application.buttons["login.userAgreement"].exists)
XCTAssertTrue(app.application.buttons["login.privacyPolicy"].exists)
app.application.terminate()
}
///
func testLoginRequiresPrivacyAgreement() throws {
let app = SuixinkanApp(resetState: true).launch(waitForLoading: false)
defer { app.application.terminate() }
guard UITestLaunchConfiguration.credentials != nil else {
throw XCTSkip("缺少 UI Test 账号。")
}
let usernameField = app.application.textFields["login.username"]
XCTAssertTrue(usernameField.waitForExistence(timeout: 8))
XCTAssertFalse(app.application.buttons["login.submit"].isEnabled)
}
///
func testEmptyPasswordDoesNotLeaveLoginScreen() throws {
let app = SuixinkanApp(resetState: true).launch(waitForLoading: false)
defer { app.application.terminate() }
let credentials = try UITestLaunchConfiguration.requireCredentials()
let usernameField = app.application.textFields["login.username"]
XCTAssertTrue(usernameField.waitForExistence(timeout: 8))
usernameField.tap()
usernameField.typeText(credentials.phone)
let privacyToggle = app.application.buttons["login.privacy"]
if privacyToggle.exists {
privacyToggle.tap()
}
app.application.buttons["login.submit"].tap()
app.waitForGlobalLoadingToDisappear(timeout: 5)
XCTAssertTrue(app.isOnLoginScreen)
}
}