feat: 完善机巢图传、拍摄阶段与任务交互
- 完善双路 RTC 接收、首帧切换及拍摄结束后的本地播放释放 - 对齐无人机状态枚举与正常拍完返航标记,新增到达后本地倒计时 - 补充准备页电量与前往回执,进入任务时移除准备页路由 - 对齐拍摄中和拍摄完成原型布局,移除详情按钮 - 补充隔离测试、接口记录与项目约定 验证:最近 157 项相关模拟器隔离测试通过,Release 无签名编译通过;未调用真实飞控或图传。
This commit is contained in:
@@ -114,9 +114,23 @@ final class DroneDockRTCPlaybackTests: XCTestCase {
|
||||
event(.firstFrame)
|
||||
view.apply(model)
|
||||
XCTAssertEqual(model.state, .playing)
|
||||
XCTAssertEqual(view.accessibilityLabel, "无人机摄像头 · 实时图传")
|
||||
view.layoutIfNeeded()
|
||||
XCTAssertEqual(view.accessibilityLabel, "实时图传")
|
||||
XCTAssertNil(model.actionTitle, "已有实时画面时不提供刷新图传按钮")
|
||||
let badge = try XCTUnwrap(descendants(view).first { $0.accessibilityIdentifier == "drone.task.remote.live.badge" })
|
||||
let source = try XCTUnwrap(descendants(view).first { $0.accessibilityIdentifier == "drone.task.remote.live.source" } as? UILabel)
|
||||
let dot = try XCTUnwrap(descendants(view).first { $0.accessibilityIdentifier == "drone.task.remote.live.dot" })
|
||||
let button = try XCTUnwrap(descendants(view).first { $0.accessibilityIdentifier == "drone.task.remote.live.request" } as? UIButton)
|
||||
XCTAssertFalse(badge.isHidden)
|
||||
XCTAssertFalse(dot.isHidden)
|
||||
XCTAssertEqual(source.text, "实时图传")
|
||||
XCTAssertEqual(dot.backgroundColor, DroneDockStyle.success)
|
||||
XCTAssertLessThan(badge.bounds.width, 100, "标识按内容宽度排版,不再占用固定 200 点")
|
||||
XCTAssertTrue(button.isHidden)
|
||||
event(.failed("测试中断"))
|
||||
view.apply(model)
|
||||
XCTAssertTrue(badge.isHidden, "失败后不能继续显示绿色实时标识")
|
||||
XCTAssertFalse(button.isHidden, "无画面时仍可主动重试")
|
||||
XCTAssertEqual(player.stops, 1)
|
||||
XCTAssertEqual(view.bounds.size, CGSize(width: 390, height: 219.375))
|
||||
event(.firstFrame)
|
||||
@@ -269,7 +283,7 @@ final class DroneDockRTCPlaybackTests: XCTestCase {
|
||||
view.apply(model)
|
||||
XCTAssertEqual(model.state, .playing)
|
||||
XCTAssertEqual(model.message, expected)
|
||||
XCTAssertEqual(view.accessibilityLabel, expected + " · 实时图传")
|
||||
XCTAssertEqual(view.accessibilityLabel, "实时图传", "切换来源后仍使用简洁实时标识")
|
||||
}
|
||||
selection.setReady(false, role: "airport")
|
||||
player.event?(.sourceChanged(selection.selectedRole)); view.apply(model)
|
||||
@@ -418,6 +432,222 @@ final class DroneDockRTCPlaybackTests: XCTestCase {
|
||||
XCTAssertNil(model.activeRole)
|
||||
}
|
||||
|
||||
/// 实测 live 补取会轮换 user_id;机巢凭证未临期时不重建已有房间。
|
||||
func testDiscoveryKeepsExistingViewerWhenBackendRotatesUserID() async throws {
|
||||
let (model, service) = try makeModel(response: dualResponse(droneAvailable: false))
|
||||
await model.refresh()
|
||||
let airport = try XCTUnwrap(model.rtcConfigurations.first)
|
||||
let session = model.playbackSessionID
|
||||
var replacement = stream(role: "airport")
|
||||
replacement["url"] = "app_id=test-app&room_id=TEST-airport&user_id=NEW-VIEWER&token=NEW-TOKEN"
|
||||
service.response = try DroneDockRTCFixture.response(root: ["airport": replacement, "drone": stream(role: "drone")])
|
||||
await model.refresh(keepingPlayback: true)
|
||||
XCTAssertEqual(model.rtcConfigurations.first, airport)
|
||||
XCTAssertEqual(model.rtcConfigurations.count, 2)
|
||||
XCTAssertEqual(model.playbackSessionID, session)
|
||||
}
|
||||
|
||||
/// 原用户凭证临期时采用新用户凭证,不能因保留健康房间而错过续期。
|
||||
func testDiscoveryReplacesViewerAtExpiryWindow() async throws {
|
||||
var airport = stream(role: "airport")
|
||||
airport["expire_ts"] = 2_000_000_020
|
||||
let (model, service) = try makeModel(response: DroneDockRTCFixture.response(root: ["airport": airport, "drone": ["available": false, "role": "drone"]]))
|
||||
await model.refresh()
|
||||
airport["expire_ts"] = 2_000_000_600
|
||||
airport["url"] = "app_id=test-app&room_id=TEST-airport&user_id=RENEWED-VIEWER&token=NEW-TOKEN"
|
||||
service.response = try DroneDockRTCFixture.response(root: ["airport": airport, "drone": stream(role: "drone")])
|
||||
await model.refresh(keepingPlayback: true)
|
||||
XCTAssertEqual(model.rtcConfigurations.first?.userID, "RENEWED-VIEWER")
|
||||
}
|
||||
|
||||
/// 录制结束时仍在途的 live 回包作废,不能在完成封面上偷偷开始接收。
|
||||
func testRecordingCompletionDiscardsPendingLiveResponse() async throws {
|
||||
let (live, service) = try makeModel()
|
||||
service.suspend = true
|
||||
let player = RTCPlayerProbe()
|
||||
let context = DroneDockShootingTaskTestData.context()
|
||||
let read = DroneDockShootingTaskTestService(result: .success(try DroneDockShootingTaskTestData.response()))
|
||||
let model = try DroneDockShootingTaskViewModel(context: context, taskID: 501,
|
||||
order: DroneDockShootingTaskTestData.order(), service: read, currentContext: { context })
|
||||
let controller = DroneDockShootingTaskViewController(viewModel: model, liveViewModel: live, livePlayer: player,
|
||||
shootingPollDelay: { _ in try await Task.sleep(for: .milliseconds(30)) })
|
||||
let scene = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.first
|
||||
let window = scene.map { UIWindow(windowScene: $0) } ?? UIWindow(frame: UIScreen.main.bounds)
|
||||
window.rootViewController = UINavigationController(rootViewController: controller)
|
||||
window.makeKeyAndVisible()
|
||||
defer { service.finish(); controller.viewWillDisappear(false); window.isHidden = true; window.rootViewController = nil }
|
||||
try await wait { service.count == 1 }
|
||||
read.result = .success(try shootDoneReturningResponse())
|
||||
try await wait { model.isRecordingFinished }
|
||||
service.finish()
|
||||
try await Task.sleep(for: .milliseconds(50))
|
||||
XCTAssertEqual(player.starts, 0)
|
||||
XCTAssertNil(live.playbackSessionID)
|
||||
XCTAssertEqual(service.count, 1)
|
||||
}
|
||||
|
||||
/// 录制完成即停止接收并弹出入口;上传仍为 20,旧帧、前后台、重复包均不能重新启动。
|
||||
func testRecordingCompletionStopsVideoAndOpensMaterialsOnce() async throws {
|
||||
let (live, service) = try makeModel()
|
||||
let player = RTCPlayerProbe()
|
||||
let context = DroneDockShootingTaskTestData.context()
|
||||
let read = DroneDockShootingTaskTestService(result: .success(try DroneDockShootingTaskTestData.response()))
|
||||
let model = try DroneDockShootingTaskViewModel(context: context, taskID: 501,
|
||||
order: DroneDockShootingTaskTestData.order(), service: read, currentContext: { context })
|
||||
let destination = UIViewController()
|
||||
var navigations = 0
|
||||
let controller = DroneDockShootingTaskViewController(viewModel: model, liveViewModel: live, livePlayer: player,
|
||||
materialsControllerFactory: { order, scope in
|
||||
XCTAssertEqual(order.orderNumber, "TEST-TASK-PAGE-001")
|
||||
XCTAssertEqual(scope.scenicID, 128)
|
||||
navigations += 1
|
||||
return destination
|
||||
}, shootingPollDelay: { _ in try await Task.sleep(for: .milliseconds(40)) })
|
||||
let scene = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.first
|
||||
let previous = scene?.windows.first { $0.isKeyWindow }
|
||||
let window = scene.map { UIWindow(windowScene: $0) } ?? UIWindow(frame: UIScreen.main.bounds)
|
||||
window.rootViewController = UINavigationController(rootViewController: controller)
|
||||
window.makeKeyAndVisible()
|
||||
defer { window.isHidden = true; window.rootViewController = nil; previous?.makeKeyAndVisible() }
|
||||
try await wait { player.starts == 1 }
|
||||
let lateFrame = try XCTUnwrap(player.event)
|
||||
lateFrame(.firstFrame)
|
||||
read.result = .success(try shootDoneReturningResponse())
|
||||
try await wait { model.isRecordingFinished }
|
||||
XCTAssertEqual(player.stops, 1)
|
||||
XCTAssertNil(live.playbackSessionID)
|
||||
XCTAssertEqual(model.response?.orderFlightTask?.status, 20)
|
||||
XCTAssertEqual(model.response?.task?.waylineStatus, 24)
|
||||
XCTAssertTrue(model.isShootCompleteReturning)
|
||||
XCTAssertTrue(model.presentation.message.contains("无人机正在返航"))
|
||||
let cover = try XCTUnwrap(descendants(controller.view).first { $0.accessibilityIdentifier == "drone.task.remote.live.cover" })
|
||||
XCTAssertFalse(cover.isHidden)
|
||||
try await Task.sleep(for: .milliseconds(300))
|
||||
let attachment = XCTAttachment(image: UIGraphicsImageRenderer(bounds: window.bounds).image { _ in
|
||||
window.drawHierarchy(in: window.bounds, afterScreenUpdates: true)
|
||||
})
|
||||
attachment.name = "录制完成弹窗与静态封面(隔离替身)"
|
||||
attachment.lifetime = .keepAlways
|
||||
add(attachment)
|
||||
let later = try XCTUnwrap(descendants(window).first { $0.accessibilityIdentifier == "drone.task.recordingCompletion.later" } as? UIButton)
|
||||
later.sendActions(for: .touchUpInside)
|
||||
window.layoutIfNeeded()
|
||||
let pageAttachment = XCTAttachment(image: UIGraphicsImageRenderer(bounds: window.bounds).image { _ in
|
||||
window.drawHierarchy(in: window.bounds, afterScreenUpdates: true)
|
||||
})
|
||||
pageAttachment.name = "拍摄完成页面-原型对齐(隔离替身)"
|
||||
pageAttachment.lifetime = .keepAlways
|
||||
add(pageAttachment)
|
||||
var uploading = RealtimeTestData.mediaStagePayload(wayline: 30, version: 2)
|
||||
uploading["shoot_complete_returning"] = false
|
||||
read.result = .success(try DroneDockShootingTaskTestData.decode(uploading))
|
||||
try await wait { model.response?.stateVersion == 2 }
|
||||
XCTAssertFalse(model.isShootCompleteReturning)
|
||||
XCTAssertTrue(model.presentation.message.contains("素材上传中"))
|
||||
XCTAssertFalse(model.presentation.message.contains("无人机正在返航"))
|
||||
XCTAssertNil(descendants(window).first { $0.accessibilityIdentifier == "drone.task.recordingCompletion" })
|
||||
lateFrame(.firstFrame)
|
||||
NotificationCenter.default.post(name: UIApplication.willResignActiveNotification, object: nil)
|
||||
NotificationCenter.default.post(name: UIApplication.didBecomeActiveNotification, object: nil)
|
||||
read.result = .success(try DroneDockShootingTaskTestData.decode(RealtimeTestData.mediaStagePayload(wayline: 50, version: 3)))
|
||||
try await wait { model.presentation.phase == .completed }
|
||||
XCTAssertEqual(player.starts, 1)
|
||||
XCTAssertEqual(service.count, 1)
|
||||
XCTAssertNil(descendants(window).first { $0.accessibilityIdentifier == "drone.task.recordingCompletion" })
|
||||
let primary = try XCTUnwrap(descendants(controller.view).first { $0.accessibilityIdentifier == "drone.task.remote.primary" } as? UIButton)
|
||||
primary.sendActions(for: .touchUpInside)
|
||||
primary.sendActions(for: .touchUpInside)
|
||||
try await wait { controller.navigationController?.topViewController === destination }
|
||||
XCTAssertEqual(navigations, 1)
|
||||
}
|
||||
|
||||
/// 已结束任务重新进入时先读状态,不能短暂启动 live;弹窗按钮直达素材库。
|
||||
func testEnteringRecordedTaskSkipsLiveAndPopupOpensMaterials() async throws {
|
||||
let (live, service) = try makeModel()
|
||||
let context = DroneDockShootingTaskTestData.context()
|
||||
let read = DroneDockShootingTaskTestService(result: .success(try DroneDockShootingTaskTestData.decode(
|
||||
RealtimeTestData.mediaStagePayload(wayline: 30, version: 1))))
|
||||
let model = try DroneDockShootingTaskViewModel(context: context, taskID: 501,
|
||||
order: DroneDockShootingTaskTestData.order(), service: read, currentContext: { context })
|
||||
let destination = UIViewController()
|
||||
let controller = DroneDockShootingTaskViewController(viewModel: model, liveViewModel: live, livePlayer: RTCPlayerProbe(),
|
||||
materialsControllerFactory: { _, _ in destination })
|
||||
let scene = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.first
|
||||
let window = scene.map { UIWindow(windowScene: $0) } ?? UIWindow(frame: UIScreen.main.bounds)
|
||||
window.rootViewController = UINavigationController(rootViewController: controller)
|
||||
window.makeKeyAndVisible()
|
||||
defer { window.isHidden = true; window.rootViewController = nil }
|
||||
try await wait { model.isRecordingFinished }
|
||||
XCTAssertEqual(service.count, 0)
|
||||
let button = try XCTUnwrap(descendants(window).first { $0.accessibilityIdentifier == "drone.task.recordingCompletion.materials" } as? UIButton)
|
||||
button.sendActions(for: .touchUpInside)
|
||||
try await wait { controller.navigationController?.topViewController === destination }
|
||||
}
|
||||
|
||||
/// 直接收到素材上传失败也停止图传、保留素材入口,不能弹成功或因重进页面重新启动 live。
|
||||
func testMediaUploadFailureStopsVideoWithoutSuccessPopup() async throws {
|
||||
let (live, service) = try makeModel()
|
||||
let player = RTCPlayerProbe()
|
||||
let context = DroneDockShootingTaskTestData.context()
|
||||
let read = DroneDockShootingTaskTestService(result: .success(try DroneDockShootingTaskTestData.response()))
|
||||
let model = try DroneDockShootingTaskViewModel(context: context, taskID: 501,
|
||||
order: DroneDockShootingTaskTestData.order(), service: read, currentContext: { context })
|
||||
let controller = DroneDockShootingTaskViewController(viewModel: model, liveViewModel: live, livePlayer: player,
|
||||
shootingPollDelay: { _ in try await Task.sleep(for: .milliseconds(40)) })
|
||||
let scene = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.first
|
||||
let previous = scene?.windows.first { $0.isKeyWindow }
|
||||
let window = scene.map { UIWindow(windowScene: $0) } ?? UIWindow(frame: UIScreen.main.bounds)
|
||||
window.rootViewController = UINavigationController(rootViewController: controller)
|
||||
window.makeKeyAndVisible()
|
||||
defer { window.isHidden = true; window.rootViewController = nil; previous?.makeKeyAndVisible() }
|
||||
try await wait { player.starts == 1 }
|
||||
let oldFrame = try XCTUnwrap(player.event)
|
||||
oldFrame(.firstFrame)
|
||||
read.result = .success(try DroneDockShootingTaskTestData.response(changes: [
|
||||
"task": ["id": 501, "status": 40, "wayline_status": 39],
|
||||
"order_flight_task": ["id": 501, "status": 40, "result_message": "本地模拟:上传媒体资源出错"],
|
||||
"ui": ["phase": "post_shoot_upload_failed", "title": "素材上传失败", "commands": []]
|
||||
]))
|
||||
try await wait { model.presentation.phase == .postShootUploadFailed }
|
||||
window.layoutIfNeeded()
|
||||
XCTAssertEqual(player.stops, 1)
|
||||
XCTAssertEqual(service.count, 1)
|
||||
XCTAssertNil(live.playbackSessionID)
|
||||
XCTAssertNil(descendants(window).first { $0.accessibilityIdentifier == "drone.task.recordingCompletion" })
|
||||
let primary = try XCTUnwrap(descendants(controller.view).first { $0.accessibilityIdentifier == "drone.task.remote.primary" } as? UIButton)
|
||||
XCTAssertEqual(primary.title(for: .normal), "查看素材")
|
||||
XCTAssertTrue(primary.isEnabled)
|
||||
oldFrame(.firstFrame)
|
||||
controller.viewWillDisappear(false)
|
||||
controller.viewDidAppear(false)
|
||||
try await Task.sleep(for: .milliseconds(100))
|
||||
XCTAssertEqual(player.starts, 1)
|
||||
XCTAssertEqual(service.count, 1)
|
||||
XCTAssertFalse(model.shouldPresentRecordingCompletion)
|
||||
XCTAssertNil(descendants(window).first { $0.accessibilityIdentifier == "drone.task.recordingCompletion" })
|
||||
try await Task.sleep(for: .milliseconds(300))
|
||||
window.layoutIfNeeded()
|
||||
XCTAssertEqual(primary.titleLabel?.text, "查看素材", "实际显示文本与素材动作一致")
|
||||
let attachment = XCTAttachment(image: UIGraphicsImageRenderer(bounds: window.bounds).image { _ in
|
||||
window.drawHierarchy(in: window.bounds, afterScreenUpdates: true)
|
||||
})
|
||||
attachment.name = "素材上传失败(隔离替身,无成功弹窗)"
|
||||
attachment.lifetime = .keepAlways
|
||||
add(attachment)
|
||||
}
|
||||
|
||||
private func shootDoneReturningResponse() throws -> DroneDockShootingResponse {
|
||||
var value = RealtimeTestData.mediaStagePayload(wayline: 24, version: 1)
|
||||
value["shoot_complete_returning"] = true
|
||||
var task = try XCTUnwrap(value["order_flight_task"] as? [String: Any])
|
||||
task["finished_at"] = NSNull()
|
||||
value["order_flight_task"] = task
|
||||
value["ui"] = ["phase": "post_shoot_uploading", "title": "拍摄已完成",
|
||||
"message": "无人机正在返航,请留意现场", "wayline_stage": "shoot_done_returning",
|
||||
"shoot_complete_returning": true, "commands": []]
|
||||
return try DroneDockShootingTaskTestData.decode(value)
|
||||
}
|
||||
|
||||
private func stream(role: String, token: String = "TEST-TOKEN") -> [String: Any] {
|
||||
["available": true, "role": role, "url_type": "volc", "expire_ts": 2_000_000_600,
|
||||
"url": "app_id=test-app&room_id=TEST-\(role)&user_id=TEST-USER&token=\(token)"]
|
||||
|
||||
Reference in New Issue
Block a user