feat: 完善机巢任务安全控制与状态诊断
同步新版飞控与 WebSocket 回执合同,完善独立指令等待、暂停继续和返航状态;增加真机诊断并优化倒计时与素材库展示。
This commit is contained in:
@@ -6,33 +6,37 @@ import XCTest
|
||||
@MainActor
|
||||
final class DroneDockArrivalCountdownViewTests: XCTestCase {
|
||||
/// 每秒只更新显示,到零不额外读取或开拍;后端明确拍摄中后才切换阶段。
|
||||
func testCountdownOnlyUpdatesLabelAndWaitsForBackendShooting() async throws {
|
||||
func testCountdownOnlyUpdatesStartButtonAndWaitsForBackendShooting() async throws {
|
||||
let fixture = try makeFixture()
|
||||
defer { fixture.close() }
|
||||
try await settle(fixture.window) { fixture.pulse.pendingCount == 1 }
|
||||
let label = try countdownLabel(in: fixture.controller.view)
|
||||
XCTAssertEqual(label.text, "自动开拍倒计时:30 秒")
|
||||
let action = try XCTUnwrap(find(in: fixture.controller.view, id: "drone.task.remote.primary") as? UIButton)
|
||||
XCTAssertNil(find(in: fixture.controller.view, id: "drone.task.remote.countdown"))
|
||||
XCTAssertEqual(action.title(for: .normal), "开始拍摄(30s)")
|
||||
XCTAssertTrue(action.isEnabled)
|
||||
let initialFrame = action.convert(action.bounds, to: fixture.controller.view)
|
||||
try await capture(fixture.window, action: action, name: "App本地到达倒计时30秒(隔离替身)")
|
||||
try await capture(fixture.window, action: action, expectedTitle: "开始拍摄(30s)", name: "App本地到达倒计时30秒(隔离替身)")
|
||||
fixture.clock.advance(seconds: 1)
|
||||
fixture.pulse.fire()
|
||||
try await settle(fixture.window) { label.text == "自动开拍倒计时:29 秒" && fixture.pulse.pendingCount == 1 }
|
||||
try await settle(fixture.window) { action.title(for: .normal) == "开始拍摄(29s)" && fixture.pulse.pendingCount == 1 }
|
||||
XCTAssertTrue(find(in: fixture.controller.view, id: "drone.task.remote.primary") === action)
|
||||
XCTAssertEqual(action.convert(action.bounds, to: fixture.controller.view), initialFrame)
|
||||
fixture.clock.advance(seconds: 29.5)
|
||||
fixture.pulse.fire()
|
||||
try await settle(fixture.window) { label.text == "自动开拍倒计时:0 秒" && fixture.pulse.pendingCount == 0 }
|
||||
try await settle(fixture.window) { action.title(for: .normal) == "开始拍摄(0s)" && fixture.pulse.pendingCount == 0 }
|
||||
XCTAssertTrue(find(in: fixture.controller.view, id: "drone.task.remote.primary") === action)
|
||||
XCTAssertEqual(action.convert(action.bounds, to: fixture.controller.view), initialFrame)
|
||||
XCTAssertEqual(fixture.model.presentation.phase, .ready)
|
||||
XCTAssertEqual(fixture.service.requests.count, 1)
|
||||
XCTAssertEqual(fixture.start.count, 0, "本地倒数到零不能下发开拍")
|
||||
XCTAssertTrue(action.isEnabled, "秒数不会改变后端开拍门禁")
|
||||
try await capture(fixture.window, action: action, name: "App本地倒计时0秒仍等待后端(隔离替身)")
|
||||
try await capture(fixture.window, action: action, expectedTitle: "开始拍摄(0s)", name: "App本地倒计时0秒仍等待后端(隔离替身)")
|
||||
fixture.service.result = .success(try snapshot(phase: "shooting", version: 2))
|
||||
let item = try XCTUnwrap(fixture.controller.navigationItem.rightBarButtonItem)
|
||||
_ = UIApplication.shared.sendAction(try XCTUnwrap(item.action), to: item.target, from: item, for: nil)
|
||||
try await settle(fixture.window) { fixture.model.presentation.phase == .shooting && label.isHidden }
|
||||
XCTAssertNil(label.text)
|
||||
try await settle(fixture.window) { fixture.model.presentation.phase == .shooting }
|
||||
XCTAssertNil(find(in: fixture.controller.view, id: "drone.task.remote.countdown"))
|
||||
XCTAssertFalse(action.currentTitle?.contains("s)") == true, "后端拍摄中必须清除旧倒计时文案")
|
||||
XCTAssertNil(fixture.model.countdownRemainingSeconds)
|
||||
XCTAssertEqual(fixture.service.requests.count, 2)
|
||||
XCTAssertEqual(fixture.start.count, 0)
|
||||
@@ -45,15 +49,18 @@ final class DroneDockArrivalCountdownViewTests: XCTestCase {
|
||||
let fixture = try makeFixture()
|
||||
defer { fixture.close() }
|
||||
try await settle(fixture.window) { fixture.pulse.pendingCount == 1 }
|
||||
let label = try countdownLabel(in: fixture.controller.view)
|
||||
let action = try XCTUnwrap(find(in: fixture.controller.view, id: "drone.task.remote.primary") as? UIButton)
|
||||
if elapsed > 0 {
|
||||
fixture.clock.advance(seconds: elapsed)
|
||||
fixture.pulse.fire()
|
||||
try await settle(fixture.window) { label.text == "自动开拍倒计时:\(30 - Int(elapsed)) 秒" }
|
||||
try await settle(fixture.window) { action.title(for: .normal) == "开始拍摄(\(30 - Int(elapsed))s)" }
|
||||
}
|
||||
let action = try XCTUnwrap(find(in: fixture.controller.view, id: "drone.task.remote.primary") as? UIButton)
|
||||
XCTAssertEqual(action.title(for: .normal), "开始拍摄")
|
||||
XCTAssertEqual(action.title(for: .normal), "开始拍摄(\(30 - Int(elapsed))s)")
|
||||
XCTAssertNil(find(in: fixture.controller.view, id: "drone.task.remote.countdown"))
|
||||
XCTAssertTrue(action.isEnabled)
|
||||
let center = action.convert(CGPoint(x: action.bounds.midX, y: action.bounds.midY), to: fixture.controller.view)
|
||||
let hit = fixture.controller.view.hitTest(center, with: nil)
|
||||
XCTAssertTrue(hit === action || hit?.isDescendant(of: action) == true)
|
||||
XCTAssertEqual(fixture.start.count, 0)
|
||||
action.sendActions(for: .touchUpInside)
|
||||
action.sendActions(for: .touchUpInside)
|
||||
@@ -69,19 +76,23 @@ final class DroneDockArrivalCountdownViewTests: XCTestCase {
|
||||
let fixture = try makeFixture()
|
||||
defer { fixture.close() }
|
||||
try await settle(fixture.window) { fixture.pulse.pendingCount == 1 }
|
||||
let label = try countdownLabel(in: fixture.controller.view)
|
||||
let action = try XCTUnwrap(find(in: fixture.controller.view, id: "drone.task.remote.primary") as? UIButton)
|
||||
let initialFrame = action.convert(action.bounds, to: fixture.controller.view)
|
||||
fixture.clock.advance(seconds: 8)
|
||||
NotificationCenter.default.post(name: UIApplication.willResignActiveNotification, object: nil)
|
||||
try await settle(fixture.window) { fixture.pulse.pendingCount == 0 }
|
||||
XCTAssertEqual(fixture.model.countdownRemainingSeconds, 22)
|
||||
fixture.clock.advance(seconds: 12)
|
||||
NotificationCenter.default.post(name: UIApplication.didBecomeActiveNotification, object: nil)
|
||||
try await settle(fixture.window) { fixture.service.requests.count == 2 && label.text == "自动开拍倒计时:10 秒" && fixture.pulse.pendingCount == 1 }
|
||||
try await settle(fixture.window) { fixture.service.requests.count == 2 && action.title(for: .normal) == "开始拍摄(10s)" && fixture.pulse.pendingCount == 1 }
|
||||
fixture.controller.viewWillDisappear(false)
|
||||
try await settle(fixture.window) { fixture.pulse.pendingCount == 0 }
|
||||
fixture.clock.advance(seconds: 15)
|
||||
fixture.controller.viewDidAppear(false)
|
||||
try await settle(fixture.window) { fixture.service.requests.count == 3 && label.text == "自动开拍倒计时:0 秒" }
|
||||
try await settle(fixture.window) { fixture.service.requests.count == 3 && action.title(for: .normal) == "开始拍摄(0s)" }
|
||||
XCTAssertTrue(find(in: fixture.controller.view, id: "drone.task.remote.primary") === action)
|
||||
XCTAssertEqual(action.convert(action.bounds, to: fixture.controller.view), initialFrame)
|
||||
XCTAssertNil(find(in: fixture.controller.view, id: "drone.task.remote.countdown"))
|
||||
XCTAssertEqual(fixture.pulse.pendingCount, 0)
|
||||
XCTAssertEqual(fixture.start.count, 0)
|
||||
XCTAssertEqual(fixture.model.presentation.phase, .ready)
|
||||
@@ -111,16 +122,14 @@ final class DroneDockArrivalCountdownViewTests: XCTestCase {
|
||||
try DroneDockShootingTaskTestData.response(changes: [
|
||||
"task": ["id": 501, "status": 20], "order_flight_task": ["id": 501, "status": 20],
|
||||
"execution_batch": 100, "state_version": version, "snapshot_kind": "full",
|
||||
"flight_control": DroneDockShootingTaskTestData.flightControl(batch: 100, resumePhase: phase,
|
||||
pauseReason: phase == "arrived_pending_start" ? "arrival_wait" : nil),
|
||||
"ui": ["phase": phase, "title": phase == "shooting" ? "正在拍摄" : "无人机已到达",
|
||||
"message": "本地模拟:未连接真实设备"],
|
||||
"execute_gate": ["can_execute": phase == "arrived_pending_start", "primary_action": "start_shoot"]
|
||||
])
|
||||
}
|
||||
|
||||
private func countdownLabel(in root: UIView) throws -> UILabel {
|
||||
try XCTUnwrap(find(in: root, id: "drone.task.remote.countdown") as? UILabel)
|
||||
}
|
||||
|
||||
private func find(in root: UIView, id: String) -> UIView? {
|
||||
if root.accessibilityIdentifier == id { return root }
|
||||
return root.subviews.lazy.compactMap { self.find(in: $0, id: id) }.first
|
||||
@@ -137,10 +146,14 @@ final class DroneDockArrivalCountdownViewTests: XCTestCase {
|
||||
throw NSError(domain: "CountdownPage", code: 1)
|
||||
}
|
||||
|
||||
private func capture(_ window: UIWindow, action: UIButton, name: String) async throws {
|
||||
private func capture(_ window: UIWindow, action: UIButton, expectedTitle: String, name: String) async throws {
|
||||
try await Task.sleep(for: .milliseconds(300))
|
||||
window.layoutIfNeeded()
|
||||
XCTAssertEqual(action.titleLabel?.text, "开始拍摄", "数字变化后按钮实际文字仍保持手动开拍")
|
||||
let label = try XCTUnwrap(action.titleLabel)
|
||||
XCTAssertEqual(label.text, expectedTitle, "按钮实际渲染文字包含完整剩余秒数")
|
||||
let textSize = (expectedTitle as NSString).size(withAttributes: [.font: label.font as Any])
|
||||
XCTAssertGreaterThanOrEqual(label.bounds.width + 1, ceil(textSize.width), "按钮标题不能裁切秒数")
|
||||
XCTAssertGreaterThanOrEqual(action.bounds.height, 44)
|
||||
let attachment = XCTAttachment(image: UIGraphicsImageRenderer(bounds: window.bounds).image { _ in
|
||||
window.drawHierarchy(in: window.bounds, afterScreenUpdates: true)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user