新增 SplashView、SplashCoordinator 与 Launch Screen 资源,移除冷启动 Lottie;LoginView 加载 App 配置。同时将 token 存储迁移至 UserDefaults,并更新相关测试与文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
69 lines
2.2 KiB
Swift
69 lines
2.2 KiB
Swift
//
|
||
// SplashCoordinatorTests.swift
|
||
// suixinkanTests
|
||
//
|
||
// Created by Codex on 2026/6/29.
|
||
//
|
||
|
||
import XCTest
|
||
@testable import suixinkan
|
||
|
||
@MainActor
|
||
/// 启动页协调器测试,覆盖最短展示时长、bootstrap 并行和 UI Test 跳过策略。
|
||
final class SplashCoordinatorTests: XCTestCase {
|
||
/// 测试 bootstrap 完成后仍需等待最短展示时长。
|
||
func testStartWaitsForMinimumDisplayDuration() async {
|
||
let coordinator = SplashCoordinator(minimumDisplayDuration: 0.2, skipsMinimumDuration: false)
|
||
let startedAt = Date()
|
||
|
||
await coordinator.start {
|
||
try? await Task.sleep(nanoseconds: 10_000_000)
|
||
}
|
||
|
||
XCTAssertTrue(coordinator.isFinished)
|
||
XCTAssertGreaterThanOrEqual(Date().timeIntervalSince(startedAt), 0.19)
|
||
}
|
||
|
||
/// 测试 bootstrap 耗时超过最短展示时长时,以 bootstrap 完成时间为准。
|
||
func testStartWaitsForSlowBootstrap() async {
|
||
let coordinator = SplashCoordinator(minimumDisplayDuration: 0.05, skipsMinimumDuration: false)
|
||
let startedAt = Date()
|
||
|
||
await coordinator.start {
|
||
try? await Task.sleep(nanoseconds: 150_000_000)
|
||
}
|
||
|
||
XCTAssertTrue(coordinator.isFinished)
|
||
XCTAssertGreaterThanOrEqual(Date().timeIntervalSince(startedAt), 0.14)
|
||
}
|
||
|
||
/// 测试 UI Test 模式会跳过最短展示时长。
|
||
func testStartSkipsMinimumDurationWhenRequested() async {
|
||
let coordinator = SplashCoordinator(minimumDisplayDuration: 1.0, skipsMinimumDuration: true)
|
||
let startedAt = Date()
|
||
|
||
await coordinator.start {
|
||
try? await Task.sleep(nanoseconds: 10_000_000)
|
||
}
|
||
|
||
XCTAssertTrue(coordinator.isFinished)
|
||
XCTAssertLessThan(Date().timeIntervalSince(startedAt), 0.2)
|
||
}
|
||
|
||
/// 测试重复调用 start 不会重置已完成状态。
|
||
func testStartIsIdempotentAfterFinished() async {
|
||
let coordinator = SplashCoordinator(minimumDisplayDuration: 0, skipsMinimumDuration: true)
|
||
var bootstrapCount = 0
|
||
|
||
await coordinator.start {
|
||
bootstrapCount += 1
|
||
}
|
||
await coordinator.start {
|
||
bootstrapCount += 1
|
||
}
|
||
|
||
XCTAssertTrue(coordinator.isFinished)
|
||
XCTAssertEqual(bootstrapCount, 1)
|
||
}
|
||
}
|