feat: 完善机巢图传、拍摄阶段与任务交互

- 完善双路 RTC 接收、首帧切换及拍摄结束后的本地播放释放
- 对齐无人机状态枚举与正常拍完返航标记,新增到达后本地倒计时
- 补充准备页电量与前往回执,进入任务时移除准备页路由
- 对齐拍摄中和拍摄完成原型布局,移除详情按钮
- 补充隔离测试、接口记录与项目约定

验证:最近 157 项相关模拟器隔离测试通过,Release 无签名编译通过;未调用真实飞控或图传。
This commit is contained in:
2026-11-03 16:43:23 +08:00
parent 0ed0077ec4
commit 54210925f0
33 changed files with 3242 additions and 205 deletions
@@ -7,6 +7,52 @@ import XCTest
final class DroneDockShootingTaskViewTests: XCTestCase {
private weak var previousKeyWindow: UIWindow?
/// 正常拍摄对齐原型且没有详情/中央刷新动作;导航栏仍能读取同一任务。
func testShootingMatchesPrototypeAndKeepsNavigationRefresh() async throws {
let clock = TaskViewPollClock()
let service = try TaskViewReadService(response: realtimeViewSnapshot(version: 1, phase: "shooting", title: "后端旧拍摄标题"))
let controller = try makeController(service: service, pollDelay: { try await clock.wait($0) })
let window = makeWindow(root: controller)
defer { close(window) }
try await settle(window) { controller.viewModel.presentation.phase == .shooting && clock.pendingCount == 1 }
XCTAssertNil(find(in: controller.view, id: "drone.task.remote.details"))
XCTAssertNil(find(in: controller.view, id: "drone.task.remote.refresh"))
let title = try XCTUnwrap(find(in: controller.view, id: "drone.task.remote.statusTitle") as? UILabel)
let message = try XCTUnwrap(find(in: controller.view, id: "drone.task.remote.statusMessage") as? UILabel)
let indicator = try XCTUnwrap(find(in: controller.view, id: "drone.task.remote.shootingIndicator") as? UIButton)
XCTAssertEqual(title.text, "无人机正在拍摄中")
XCTAssertEqual(message.text, "请关注现场及实时画面。\n请勿关闭本页或息屏。")
XCTAssertFalse(indicator.isEnabled)
XCTAssertFalse(hidden(indicator))
let regions = fixedFrames(in: controller.view)
indicator.sendActions(for: .touchUpInside)
XCTAssertEqual(service.requests, [501], "禁用的拍摄中展示不产生操作")
try tapNavigationRefresh(controller)
try await settle(window) { service.requests.count == 2 && !controller.viewModel.isLoading }
XCTAssertEqual(service.requests, [501, 501])
XCTAssertEqual(fixedFrames(in: controller.view), regions)
XCTAssertEqual(controller.viewModel.presentation.phase, .shooting)
try await Task.sleep(for: .milliseconds(300))
window.layoutIfNeeded()
capture(window, name: "拍摄中-对齐体验网页(隔离替身)")
}
/// 首份 shooting 挂起期间保留召唤回执的前往提示,页面加载占位不能覆盖它。
func testInitialReadKeepsAcceptedTravelReceiptVisible() async throws {
let receipt = DroneDockShootResponse(dataJSON: #"{"accepted":true,"task_id":9001,"order_flight_task":{"id":501,"order_number":"TEST-TASK-501","scenic_id":128},"ui":{"phase":"going_to_spot"}}"#)
let service = try TaskViewReadService(response: realtimeViewSnapshot(version: 1, phase: "arrived_pending_start", title: "本地模拟:无人机已到达"))
service.suspendNext = true
let controller = try makeController(service: service, initialSummonReceipt: receipt)
let window = makeWindow(root: controller)
defer { service.cancelAll(); close(window) }
try await settle(window) { controller.viewModel.isLoading }
XCTAssertTrue(visibleTexts(in: controller.view).contains("无人机正在赶来"))
XCTAssertFalse(visibleTexts(in: controller.view).contains("正在获取任务状态"))
service.finish()
try await settle(window) { controller.viewModel.presentation.phase == .ready }
XCTAssertTrue(visibleTexts(in: controller.view).contains("本地模拟:无人机已到达"))
}
/// 使用模拟 WebSocket 推进任务阶段,断线立即 HTTP 兜底,恢复后停轮询;固定布局不变。
func testRealtimeUpdatesPageAndAutomaticallyFallsBackThenRecovers() async throws {
let harness = RealtimeHarness()
@@ -41,10 +87,11 @@ final class DroneDockShootingTaskViewTests: XCTestCase {
harness.sockets[1].emit(try RealtimeTestData.push(RealtimeTestData.mediaStagePayload(wayline: 30, version: 4, orderNumber: "TEST-TASK-501")))
try await settle(window) { controller.viewModel.response?.stateVersion == 4 && clock.pendingCount == 0 }
XCTAssertEqual(controller.viewModel.presentation.phase, .postShootUploading)
XCTAssertTrue(visibleTexts(in: controller.view).contains("拍摄完毕上传中"))
XCTAssertFalse(visibleTexts(in: controller.view).contains("查看素材"))
try await settle(window) { self.visibleTexts(in: controller.view).contains("查看素材") }
XCTAssertTrue(visibleTexts(in: controller.view).contains("拍摄已完成"))
XCTAssertTrue(visibleTexts(in: controller.view).contains("查看素材"))
XCTAssertEqual(fixedFrames(in: controller.view), fixedBefore)
capture(window, name: "WebSocket 本地模拟:拍摄完毕上传中(未连接无人机)")
capture(window, name: "WebSocket 本地模拟:拍摄完成提示(未连接无人机)")
harness.sockets[1].emit(try RealtimeTestData.push(RealtimeTestData.mediaStagePayload(wayline: 50, version: 5, orderNumber: "TEST-TASK-501")))
try await settle(window) { controller.viewModel.response?.stateVersion == 5 && clock.pendingCount == 0 }
XCTAssertEqual(controller.viewModel.presentation.phase, .completed)
@@ -397,9 +444,11 @@ final class DroneDockShootingTaskViewTests: XCTestCase {
XCTAssertEqual(find(in: controller.view, id: "drone.task.remote.metric.battery")?.accessibilityValue, "81%")
XCTAssertEqual(find(in: controller.view, id: "drone.task.remote.metric.satellite")?.accessibilityValue, "30颗")
XCTAssertTrue(visibleTexts(in: controller.view).contains("更新后的点位与航线"))
XCTAssertTrue(visibleTexts(in: controller.view).contains("正在拍摄"))
XCTAssertTrue(visibleTexts(in: controller.view).contains("无人机正在拍摄中"))
XCTAssertFalse(visibleTexts(in: controller.view).contains("空闲 · 电量93%"))
XCTAssertTrue(refreshButton.isEnabled)
XCTAssertTrue(hidden(refreshButton))
let indicator = try XCTUnwrap(find(in: controller.view, id: "drone.task.remote.shootingIndicator") as? UIButton)
XCTAssertFalse(indicator.isEnabled)
}
/// 后台取消后迟到回执不重新展示当前设备或遥测。
@@ -457,12 +506,8 @@ final class DroneDockShootingTaskViewTests: XCTestCase {
XCTAssertFalse(visibleTexts(in: controller.view).contains("任务状态读取失败"))
XCTAssertTrue(visibleTexts(in: controller.view).contains { $0.contains("刷新失败,当前显示上次数据") })
XCTAssertEqual(find(in: controller.view, id: "drone.task.remote.metric.battery")?.accessibilityValue, "93%")
let details = try XCTUnwrap(find(in: controller.view, id: "drone.task.remote.details") as? UIButton)
details.sendActions(for: .touchUpInside)
try await settle(window) { controller.presentedViewController is UIAlertController }
let alert = try XCTUnwrap(controller.presentedViewController as? UIAlertController)
XCTAssertTrue(alert.message?.contains("测试刷新断网") == true)
controller.dismiss(animated: false)
XCTAssertNil(find(in: controller.view, id: "drone.task.remote.details"))
XCTAssertNotNil(controller.viewModel.errorMessage)
try button(in: controller.view).sendActions(for: .touchUpInside)
try await settle(window) { service.requests.count == 3 && controller.viewModel.errorMessage == nil }
XCTAssertNotNil(controller.viewModel.response)
@@ -524,8 +569,8 @@ final class DroneDockShootingTaskViewTests: XCTestCase {
XCTAssertEqual(service.requests, [501, 501])
}
/// 详情展示完整文案,展开本身不会发起任何读取或控制请求。
func testDetailsKeepFullServerMessageWithoutRequestingAgain() async throws {
/// 移除详情按钮后仍保留原始完整说明,页面不新增读取或控制请求。
func testFullServerMessageIsPreservedWithoutDetailsButton() async throws {
let message = String(repeating: "测试任务等待后端处理,完整原因应在详情保留。", count: 20)
var payload = TaskViewData.payload()
payload["ui"] = ["phase": "blocked", "title": "任务暂不可执行", "message": message]
@@ -535,13 +580,12 @@ final class DroneDockShootingTaskViewTests: XCTestCase {
let window = makeWindow(root: controller)
defer { close(window) }
try await settle(window) { controller.viewModel.response != nil }
let details = try XCTUnwrap(find(in: controller.view, id: "drone.task.remote.details") as? UIButton)
details.sendActions(for: .touchUpInside)
try await settle(window) { controller.presentedViewController is UIAlertController }
let alert = try XCTUnwrap(controller.presentedViewController as? UIAlertController)
XCTAssertTrue(alert.message?.contains(message) == true)
XCTAssertNil(find(in: controller.view, id: "drone.task.remote.details"))
XCTAssertNil(controller.presentedViewController)
let label = try XCTUnwrap(find(in: controller.view, id: "drone.task.remote.statusMessage") as? UILabel)
XCTAssertEqual(label.text, message)
XCTAssertTrue(controller.viewModel.dataJSON?.contains(message) == true)
XCTAssertEqual(service.requests, [501])
controller.dismiss(animated: false)
}
/// 明确完成后素材入口沿用当前订单和景区,只跳转一次,不再次创建或召唤。
@@ -564,7 +608,8 @@ final class DroneDockShootingTaskViewTests: XCTestCase {
try await settle(window) { controller.viewModel.presentation.phase == .completed }
let primary = try XCTUnwrap(find(in: controller.view, id: "drone.task.remote.primary") as? UIButton)
XCTAssertTrue(primary.isEnabled)
XCTAssertEqual(primary.title(for: .normal), "查看素材")
XCTAssertEqual(primary.configuration?.title, "查看素材")
XCTAssertTrue(visibleTexts(in: primary).contains("查看素材"))
primary.sendActions(for: .touchUpInside)
primary.sendActions(for: .touchUpInside)
try await settle(window) { controller.navigationController?.topViewController === destination }
@@ -573,13 +618,14 @@ final class DroneDockShootingTaskViewTests: XCTestCase {
}
private func makeController(service: any DroneDockShootingServing, scope: TaskViewScope? = nil,
initialSummonReceipt: DroneDockShootResponse? = nil,
pollDelay: @escaping @Sendable (UInt64) async throws -> Void = { try await Task.sleep(nanoseconds: $0) },
realtime: DroneDockShootingRealtimeSession? = nil,
materialsFactory: (@MainActor (DroneDockHomeOrder, DroneDockHomeContext) -> UIViewController)? = nil) throws -> DroneDockShootingTaskViewController {
let scope = scope ?? TaskViewScope()
let order = try JSONDecoder().decode(DroneDockHomeOrder.self, from: Data(#"{"order_number":"TEST-TASK-501","project_id":101,"project_name":"入口五次套餐","user_phone":"130****0501"}"#.utf8))
let model = DroneDockShootingTaskViewModel(context: scope.value, taskID: 501, order: order,
service: service, currentContext: { scope.value })
service: service, initialSummonReceipt: initialSummonReceipt, currentContext: { scope.value })
return DroneDockShootingTaskViewController(viewModel: model, realtimeSession: realtime, materialsControllerFactory: materialsFactory,
shootingPollDelay: pollDelay)
}