feat: 统一机巢加载体验并对齐到达态界面
工作台、准备页、任务首次读取和景区空境库复用应用通用 Loading;到达态按 Web 展示,保留倒计时及手动开拍权限。新增图传几何诊断,不改变 Fit 渲染或设备连接行为。 验证:App 与测试包无签名 build-for-testing 编译通过,git diff --check 通过。iPhone 11 当前 unavailable,真机回归待设备重连后执行。
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
import UIKit
|
||||
import XCTest
|
||||
@testable import suixinkan
|
||||
|
||||
/// 页面通用 Loading 必须跟随可见性,并与其它页面或请求的令牌相互独立。
|
||||
@MainActor
|
||||
final class GlobalPageLoadingTests: XCTestCase {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
GlobalLoadingManager.shared.hideAll()
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
GlobalLoadingManager.shared.hideAll()
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
/// 页面首次读取可以提前标记,但只有完整出现后才使用通用遮罩。
|
||||
func testLoadingWaitsForVisiblePageAndFinishesWithoutLeaking() {
|
||||
let controller = makeController()
|
||||
controller.setPageLoading(true)
|
||||
XCTAssertFalse(GlobalLoadingManager.shared.isShowing)
|
||||
controller.viewDidAppear(false)
|
||||
XCTAssertTrue(GlobalLoadingManager.shared.isShowing)
|
||||
controller.setPageLoading(false)
|
||||
XCTAssertFalse(GlobalLoadingManager.shared.isShowing)
|
||||
controller.viewWillDisappear(false)
|
||||
}
|
||||
|
||||
/// 同步重复刷新展示不会重复持有令牌,成功或错误结束都只需一次释放。
|
||||
func testRepeatedLoadingUpdatesOwnOnlyOneToken() {
|
||||
let controller = makeController()
|
||||
controller.viewDidAppear(false)
|
||||
controller.setPageLoading(true)
|
||||
controller.setPageLoading(true)
|
||||
controller.setPageLoading(true)
|
||||
controller.setPageLoading(false)
|
||||
XCTAssertFalse(GlobalLoadingManager.shared.isShowing)
|
||||
controller.viewWillDisappear(false)
|
||||
}
|
||||
|
||||
/// 离页时释放本页;迟到的结束不能关闭另一请求,迟到开始也不能覆盖新页面。
|
||||
func testLeavingAndLateUpdatesCannotHideOrCoverAnotherPage() {
|
||||
let controller = makeController()
|
||||
controller.viewDidAppear(false)
|
||||
controller.setPageLoading(true)
|
||||
let other = GlobalLoadingManager.shared.beginRequest()
|
||||
controller.viewWillDisappear(false)
|
||||
XCTAssertTrue(GlobalLoadingManager.shared.isShowing)
|
||||
controller.setPageLoading(false)
|
||||
XCTAssertTrue(GlobalLoadingManager.shared.isShowing)
|
||||
GlobalLoadingManager.shared.endRequest(other)
|
||||
controller.setPageLoading(true)
|
||||
XCTAssertFalse(GlobalLoadingManager.shared.isShowing)
|
||||
}
|
||||
|
||||
/// 后台关闭通用遮罩,返回前台只恢复仍可见且读取未结束的页面。
|
||||
func testBackgroundAndForegroundRespectPendingReadAndVisibility() {
|
||||
let controller = makeController()
|
||||
controller.viewDidAppear(false)
|
||||
controller.setPageLoading(true)
|
||||
NotificationCenter.default.post(name: UIApplication.willResignActiveNotification, object: nil)
|
||||
XCTAssertFalse(GlobalLoadingManager.shared.isShowing)
|
||||
GlobalLoadingManager.shared.hideAll()
|
||||
NotificationCenter.default.post(name: UIApplication.didBecomeActiveNotification, object: nil)
|
||||
XCTAssertTrue(GlobalLoadingManager.shared.isShowing)
|
||||
controller.viewWillDisappear(false)
|
||||
NotificationCenter.default.post(name: UIApplication.didBecomeActiveNotification, object: nil)
|
||||
XCTAssertFalse(GlobalLoadingManager.shared.isShowing)
|
||||
}
|
||||
|
||||
/// 请求已在后台完成时,不因页面回到前台而重新展示过期遮罩。
|
||||
func testReadFinishingInBackgroundDoesNotRestoreLoading() {
|
||||
let controller = makeController()
|
||||
controller.viewDidAppear(false)
|
||||
controller.setPageLoading(true)
|
||||
NotificationCenter.default.post(name: UIApplication.willResignActiveNotification, object: nil)
|
||||
controller.setPageLoading(false)
|
||||
NotificationCenter.default.post(name: UIApplication.didBecomeActiveNotification, object: nil)
|
||||
XCTAssertFalse(GlobalLoadingManager.shared.isShowing)
|
||||
controller.viewWillDisappear(false)
|
||||
}
|
||||
|
||||
private func makeController() -> GlobalLoadingPageViewController {
|
||||
let controller = GlobalLoadingPageViewController()
|
||||
controller.loadViewIfNeeded()
|
||||
NotificationCenter.default.post(name: UIApplication.didBecomeActiveNotification, object: nil)
|
||||
return controller
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user