feat: 完善机巢图传、拍摄阶段与任务交互
- 完善双路 RTC 接收、首帧切换及拍摄结束后的本地播放释放 - 对齐无人机状态枚举与正常拍完返航标记,新增到达后本地倒计时 - 补充准备页电量与前往回执,进入任务时移除准备页路由 - 对齐拍摄中和拍摄完成原型布局,移除详情按钮 - 补充隔离测试、接口记录与项目约定 验证:最近 157 项相关模拟器隔离测试通过,Release 无签名编译通过;未调用真实飞控或图传。
This commit is contained in:
@@ -0,0 +1,230 @@
|
||||
import Foundation
|
||||
import XCTest
|
||||
@testable import suixinkan
|
||||
|
||||
/// 验证 9.9.1 设备、订单任务、航线和页面阶段的职责边界;所有响应均为内存快照。
|
||||
@MainActor
|
||||
final class DroneDockStatusContractTests: XCTestCase {
|
||||
/// 录制后的上传失败单独显示,即使订单任务已失败,也不变成重新飞行入口。
|
||||
func testExplicitMediaFailureStopsRecordingWithoutSuccessNoticeOrResummon() async throws {
|
||||
for status in [20, 40] {
|
||||
let fixture = try makeFixture(payload(phase: "post_shoot_upload_failed", status: status, wayline: 39))
|
||||
await fixture.model.refresh()
|
||||
XCTAssertEqual(fixture.model.presentation.phase, .postShootUploadFailed)
|
||||
XCTAssertTrue(fixture.model.presentation.title.contains("失败"))
|
||||
XCTAssertEqual(fixture.model.presentation.message, "本地模拟:素材处理失败")
|
||||
XCTAssertEqual(fixture.model.presentation.action, .materials)
|
||||
XCTAssertTrue(fixture.model.presentation.isActionEnabled)
|
||||
XCTAssertTrue(fixture.model.isRecordingFinished)
|
||||
XCTAssertFalse(fixture.model.shouldPresentRecordingCompletion)
|
||||
XCTAssertFalse(fixture.model.canResummon)
|
||||
XCTAssertFalse(fixture.model.canStartShooting)
|
||||
await fixture.model.resummon()
|
||||
await fixture.model.startShooting()
|
||||
XCTAssertEqual(fixture.actions.resummonCount, 0)
|
||||
XCTAssertEqual(fixture.actions.startCount, 0)
|
||||
}
|
||||
}
|
||||
|
||||
/// 航线上传和渲染失败可补足缺少 UI 阶段的快照,不从订单“执行中”误报正在拍摄。
|
||||
func testUploadAndRenderFailureFallbackRemainRecordedAndDoNotEnableResummon() async throws {
|
||||
for wayline in [39, 49] {
|
||||
for phase: String? in [nil, "blocked"] {
|
||||
let fixture = try makeFixture(payload(phase: phase, status: 20, wayline: wayline))
|
||||
await fixture.model.refresh()
|
||||
XCTAssertEqual(fixture.model.presentation.phase, .postShootUploadFailed)
|
||||
XCTAssertTrue(fixture.model.isRecordingFinished)
|
||||
XCTAssertFalse(fixture.model.shouldPresentRecordingCompletion)
|
||||
XCTAssertEqual(fixture.model.presentation.action, .materials)
|
||||
XCTAssertFalse(fixture.model.canResummon)
|
||||
XCTAssertEqual(fixture.model.response?.orderFlightTask?.status, 20, "不得改写后端订单任务状态")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 后端明确返回旧的可重召阶段时保持既有流程,不把新上传失败规则覆盖到它。
|
||||
func testExplicitRestartableFailureKeepsExistingResummonFlow() async throws {
|
||||
let fixture = try makeFixture(payload(phase: "failed_restartable", status: 40, wayline: 39))
|
||||
await fixture.model.refresh()
|
||||
XCTAssertEqual(fixture.model.presentation.phase, .failed)
|
||||
XCTAssertEqual(fixture.model.presentation.action, .retry)
|
||||
XCTAssertTrue(fixture.model.canResummon)
|
||||
XCTAssertFalse(fixture.model.shouldPresentRecordingCompletion)
|
||||
}
|
||||
|
||||
/// 拍摄与执行失败优先于乐观的拍摄阶段,不能弹出录制完成提示。
|
||||
func testShootingAndExecutionFailureOverrideOptimisticShootingPhase() async throws {
|
||||
for wayline in [29, 91] {
|
||||
let fixture = try makeFixture(payload(phase: "shooting", status: 20, wayline: wayline))
|
||||
await fixture.model.refresh()
|
||||
XCTAssertEqual(fixture.model.presentation.phase, .failed)
|
||||
XCTAssertFalse(fixture.model.isRecordingFinished)
|
||||
XCTAssertFalse(fixture.model.shouldPresentRecordingCompletion)
|
||||
XCTAssertFalse(fixture.model.canStartShooting)
|
||||
}
|
||||
}
|
||||
|
||||
/// 航线取消不因订单摘要仍“执行中”或开拍门禁残留而开放拍摄。
|
||||
func testWaylineCancellationBlocksStartAndResummon() async throws {
|
||||
let fixture = try makeFixture(payload(phase: "arrived_pending_start", status: 20, wayline: 90))
|
||||
await fixture.model.refresh()
|
||||
XCTAssertEqual(fixture.model.presentation.phase, .blocked)
|
||||
XCTAssertFalse(fixture.model.canStartShooting)
|
||||
XCTAssertFalse(fixture.model.canResummon)
|
||||
XCTAssertFalse(fixture.model.isRecordingFinished)
|
||||
XCTAssertFalse(fixture.model.shouldPresentRecordingCompletion)
|
||||
}
|
||||
|
||||
/// 待确认任务不能借旧的开拍门禁或安全指令列表继续操作。
|
||||
func testUnconfirmedTaskBlocksFlightActionsDespiteOptimisticUI() async throws {
|
||||
for phase in ["arrived_pending_start", "shooting", "completed"] {
|
||||
var value = payload(phase: phase, status: 60, wayline: 20)
|
||||
value["ui"] = ["phase": phase, "title": "本地模拟:旧阶段", "commands": [["command": "flighttask_pause"]]]
|
||||
let fixture = try makeFixture(value)
|
||||
await fixture.model.refresh()
|
||||
XCTAssertEqual(fixture.model.presentation.phase, .blocked)
|
||||
XCTAssertTrue(fixture.model.presentation.title.contains("待确认"))
|
||||
XCTAssertFalse(fixture.model.canStartShooting)
|
||||
XCTAssertFalse(fixture.model.canResummon)
|
||||
XCTAssertFalse(fixture.model.canSendCommand(.pause))
|
||||
XCTAssertFalse(fixture.model.shouldPresentRecordingCompletion)
|
||||
await fixture.model.startShooting()
|
||||
await fixture.model.resummon()
|
||||
await fixture.model.sendCommand(.pause)
|
||||
XCTAssertEqual(fixture.actions.startCount, 0)
|
||||
XCTAssertEqual(fixture.actions.resummonCount, 0)
|
||||
XCTAssertEqual(fixture.actions.commandCount, 0)
|
||||
}
|
||||
}
|
||||
|
||||
/// 当前工作态为空闲时,不让历史在线字段 0/2 错误覆盖它。
|
||||
func testIdleWorkStatusTakesPrecedenceOverHistoricalOfflineFlags() async throws {
|
||||
for online in [0, 2] {
|
||||
let fixture = try makeFixture(payload(phase: "failed_restartable", status: 40, wayline: 29,
|
||||
plane: ["id": 58, "work_status": 1, "online_status": online]))
|
||||
await fixture.model.refresh()
|
||||
XCTAssertTrue(fixture.model.canResummon)
|
||||
XCTAssertFalse(fixture.model.presentation.actionNote?.contains("离线") == true)
|
||||
}
|
||||
}
|
||||
|
||||
/// 工作态拍摄中属于忙碌,历史在线字段不能将其显示为离线或空闲。
|
||||
func testBusyWorkStatusBlocksResummonWithBusyReason() async throws {
|
||||
for online in [0, 1, 2] {
|
||||
let fixture = try makeFixture(payload(phase: "failed_restartable", status: 40, wayline: 29,
|
||||
plane: ["id": 58, "work_status": 2, "online_status": online]))
|
||||
await fixture.model.refresh()
|
||||
XCTAssertFalse(fixture.model.canResummon)
|
||||
XCTAssertEqual(fixture.model.presentation.actionNote, "无人机忙碌,暂不可召唤")
|
||||
await fixture.model.resummon()
|
||||
XCTAssertEqual(fixture.actions.resummonCount, 0)
|
||||
}
|
||||
}
|
||||
|
||||
/// 工作态明确离线时,即使表字段仍在线也不能重召唤。
|
||||
func testOfflineWorkStatusWinsOverOnlineFlag() async throws {
|
||||
let fixture = try makeFixture(payload(phase: "failed_restartable", status: 40, wayline: 29,
|
||||
plane: ["id": 58, "work_status": 0, "online_status": 1]))
|
||||
await fixture.model.refresh()
|
||||
XCTAssertFalse(fixture.model.canResummon)
|
||||
XCTAssertEqual(fixture.model.presentation.actionNote, "无人机离线,暂不可召唤")
|
||||
}
|
||||
|
||||
/// 没有可信工作态时,所有明确非 1 在线标记均保守视为离线,而非仅处理历史值 2。
|
||||
func testUnknownWorkStatusUsesNonOnlineFlagAsOfflineFallback() async throws {
|
||||
for online in [0, 2, 99, -1] {
|
||||
for work: Int? in [nil, 99] {
|
||||
var plane: [String: Any] = ["id": 58, "online_status": online]
|
||||
if let work { plane["work_status"] = work }
|
||||
let fixture = try makeFixture(payload(phase: "failed_restartable", status: 40, wayline: 29, plane: plane))
|
||||
await fixture.model.refresh()
|
||||
XCTAssertFalse(fixture.model.canResummon)
|
||||
XCTAssertEqual(fixture.model.presentation.actionNote, "无人机离线,暂不可召唤")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 同一个完整快照从 HTTP 或 WS 进入时得到相同的素材失败展示与动作许可。
|
||||
func testMediaFailureMatchesAcrossHTTPAndWebSocket() async throws {
|
||||
var value = payload(phase: "post_shoot_upload_failed", status: 40, wayline: 39)
|
||||
value["order_flight_task_id"] = 501
|
||||
value["execution_batch"] = 100
|
||||
value["state_version"] = 12
|
||||
value["snapshot_kind"] = "full"
|
||||
let http = try makeFixture(value)
|
||||
await http.model.refresh()
|
||||
guard case .snapshot(let snapshot) = try DroneDockShootingSocketMessage.decode(RealtimeTestData.push(value)) else {
|
||||
return XCTFail("完整 WS 快照必须可解析")
|
||||
}
|
||||
let socket = try makeFixture(payload(phase: "shooting", status: 20, wayline: 20))
|
||||
XCTAssertEqual(socket.model.applyTaskSnapshot(snapshot), .applied)
|
||||
XCTAssertEqual(socket.model.presentation, http.model.presentation)
|
||||
XCTAssertTrue(socket.model.isRecordingFinished)
|
||||
XCTAssertFalse(socket.model.shouldPresentRecordingCompletion)
|
||||
XCTAssertFalse(socket.model.canResummon)
|
||||
XCTAssertTrue(http.service.requests.allSatisfy { !$0.liveBattery })
|
||||
XCTAssertTrue(socket.service.requests.isEmpty)
|
||||
}
|
||||
|
||||
/// 成功提示只保留给录制完成和素材就绪,不因新增素材失败阶段扩大弹窗范围。
|
||||
func testRecordingSuccessNoticeOnlyAllowsSuccessfulRecordingPhases() async throws {
|
||||
for (phase, status, wayline) in [("post_shoot_uploading", 20, 30), ("completed", 30, 50)] {
|
||||
let fixture = try makeFixture(payload(phase: phase, status: status, wayline: wayline))
|
||||
await fixture.model.refresh()
|
||||
XCTAssertTrue(fixture.model.isRecordingFinished)
|
||||
XCTAssertTrue(fixture.model.shouldPresentRecordingCompletion)
|
||||
}
|
||||
}
|
||||
|
||||
private func payload(phase: String?, status: Int, wayline: Int,
|
||||
plane: [String: Any] = ["id": 58, "work_status": 1, "online_status": 1]) -> [String: Any] {
|
||||
var value = DroneDockShootingTaskTestData.payload()
|
||||
value["task"] = ["id": 501, "status": status, "wayline_status": wayline]
|
||||
value["order_flight_task"] = ["id": 501, "status": status, "result_message": "本地模拟:素材处理失败"]
|
||||
value["current_plane"] = plane
|
||||
value["execute_gate"] = ["can_execute": true, "primary_action": "start_shoot"]
|
||||
if let phase {
|
||||
value["ui"] = ["phase": phase, "title": "本地模拟:素材处理失败", "message": "本地模拟:素材处理失败", "commands": []]
|
||||
} else {
|
||||
value["ui"] = NSNull()
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
private func makeFixture(_ payload: [String: Any]) throws -> (model: DroneDockShootingTaskViewModel,
|
||||
service: DroneDockShootingTaskTestService, actions: StatusContractActions) {
|
||||
let context = DroneDockShootingTaskTestData.context()
|
||||
let service = DroneDockShootingTaskTestService(result: .success(try DroneDockShootingTaskTestData.decode(payload)))
|
||||
let actions = StatusContractActions()
|
||||
let model = DroneDockShootingTaskViewModel(context: context, taskID: 501,
|
||||
order: try DroneDockShootingTaskTestData.order(), service: service, startService: actions,
|
||||
commandService: actions, resummonService: actions, currentContext: { context })
|
||||
return (model, service, actions)
|
||||
}
|
||||
}
|
||||
|
||||
/// 只记录被调用次数并返回本地错误,绝无网络或设备传输能力。
|
||||
@MainActor
|
||||
private final class StatusContractActions: DroneDockStartShooting, DroneDockCommandSending, DroneDockResummonServing {
|
||||
private(set) var startCount = 0
|
||||
private(set) var commandCount = 0
|
||||
private(set) var resummonCount = 0
|
||||
|
||||
/// 任何意外的开拍调用都会留下计数,便于检查门禁。
|
||||
func startShooting(taskID: Int) async throws -> DroneDockStartShootResponse {
|
||||
startCount += 1
|
||||
throw APIError.networkFailed("本地模拟,无真实设备")
|
||||
}
|
||||
|
||||
/// 任何意外的安全指令调用都会留下计数,便于检查门禁。
|
||||
func sendCommand(taskID: Int, command: DroneDockSafetyCommand) async throws -> DroneDockCommandResponse {
|
||||
commandCount += 1
|
||||
throw APIError.networkFailed("本地模拟,无真实设备")
|
||||
}
|
||||
|
||||
/// 任何意外的重召唤调用都会留下计数,便于检查门禁。
|
||||
func resummon(taskID: Int) async throws -> DroneDockShootResponse {
|
||||
resummonCount += 1
|
||||
throw APIError.networkFailed("本地模拟,无真实设备")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user