feat: 完善机巢图传、拍摄阶段与任务交互
- 完善双路 RTC 接收、首帧切换及拍摄结束后的本地播放释放 - 对齐无人机状态枚举与正常拍完返航标记,新增到达后本地倒计时 - 补充准备页电量与前往回执,进入任务时移除准备页路由 - 对齐拍摄中和拍摄完成原型布局,移除详情按钮 - 补充隔离测试、接口记录与项目约定 验证:最近 157 项相关模拟器隔离测试通过,Release 无签名编译通过;未调用真实飞控或图传。
This commit is contained in:
@@ -8,7 +8,7 @@ final class DroneDockTaskFixedLayoutTests: XCTestCase {
|
||||
private let compactSize = CGSize(width: 375, height: 146)
|
||||
private let regularSize = CGSize(width: 402, height: 220)
|
||||
private let phases: [DroneDockTaskDisplayPhase] = [
|
||||
.loading, .navigating, .ready, .shooting, .postShootUploading, .paused, .returning,
|
||||
.loading, .navigating, .ready, .shooting, .postShootUploading, .postShootUploadFailed, .paused, .returning,
|
||||
.completed, .failed, .blocked, .unknown, .readError
|
||||
]
|
||||
|
||||
@@ -36,6 +36,8 @@ final class DroneDockTaskFixedLayoutTests: XCTestCase {
|
||||
let note = try XCTUnwrap(find(in: status, suffix: "failureNote") as? UILabel)
|
||||
XCTAssertFalse(isHidden(note))
|
||||
XCTAssertEqual(note.text, "无人机离线,暂不可召唤")
|
||||
} else if [.shooting, .postShootUploading, .completed].contains(phase) {
|
||||
XCTAssertTrue(isHidden(device))
|
||||
} else {
|
||||
XCTAssertFalse(isHidden(device))
|
||||
XCTAssertEqual(device.text, "空闲 · 电量 93%")
|
||||
@@ -64,25 +66,230 @@ final class DroneDockTaskFixedLayoutTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/// 长文案可通过至少 44 点高的详情入口查看,截断不影响命中与回调。
|
||||
func testCompactLongErrorDetailsRemainTappable() throws {
|
||||
/// 移除通用详情后,长错误保留完整文本与可点击的整行刷新入口。
|
||||
func testCompactLongErrorHasNoDetailsAndKeepsFullWidthRefresh() throws {
|
||||
let status = makeStatus(size: compactSize)
|
||||
apply(presentation(.readError, longCopy: true), to: status)
|
||||
let value = presentation(.readError, longCopy: true)
|
||||
apply(value, to: status)
|
||||
var actionCalls = 0
|
||||
var detailsCalls = 0
|
||||
status.onPrimaryAction = { actionCalls += 1 }
|
||||
status.onDetails = { detailsCalls += 1 }
|
||||
let details = try XCTUnwrap(find(in: status, suffix: "details") as? UIButton)
|
||||
XCTAssertTrue(details.isEnabled)
|
||||
XCTAssertFalse(isHidden(details))
|
||||
XCTAssertGreaterThanOrEqual(details.bounds.height, 44)
|
||||
XCTAssertGreaterThanOrEqual(details.bounds.width, 44)
|
||||
let center = details.convert(CGPoint(x: details.bounds.midX, y: details.bounds.midY), to: status)
|
||||
XCTAssertNil(find(in: status, suffix: "details"))
|
||||
XCTAssertEqual((find(in: status, suffix: "statusMessage") as? UILabel)?.text, value.message)
|
||||
let refresh = try XCTUnwrap(find(in: status, suffix: "refresh") as? UIButton)
|
||||
XCTAssertTrue(refresh.isEnabled)
|
||||
XCTAssertFalse(isHidden(refresh))
|
||||
XCTAssertGreaterThanOrEqual(refresh.bounds.height, 44)
|
||||
XCTAssertEqual(refresh.bounds.width, compactSize.width - 32, accuracy: 0.5)
|
||||
let center = refresh.convert(CGPoint(x: refresh.bounds.midX, y: refresh.bounds.midY), to: status)
|
||||
let hit = status.hitTest(center, with: nil)
|
||||
XCTAssertTrue(hit === details || hit?.isDescendant(of: details) == true)
|
||||
details.sendActions(for: .touchUpInside)
|
||||
XCTAssertEqual(detailsCalls, 1)
|
||||
XCTAssertTrue(hit === refresh || hit?.isDescendant(of: refresh) == true)
|
||||
refresh.sendActions(for: .touchUpInside)
|
||||
XCTAssertEqual(actionCalls, 1)
|
||||
XCTAssertEqual(detailsCalls, 0)
|
||||
try assertReadableContainedContent(in: status)
|
||||
}
|
||||
|
||||
/// 拍摄中按原型显示左侧视频状态、右侧两行说明与整行禁用指示,不提供详情或刷新动作。
|
||||
func testShootingPanelMatchesPrototypeAndCannotTriggerActions() async throws {
|
||||
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)
|
||||
let host = UIViewController()
|
||||
window.rootViewController = host
|
||||
window.makeKeyAndVisible()
|
||||
defer { window.isHidden = true; window.rootViewController = nil; previous?.makeKeyAndVisible() }
|
||||
for size in [compactSize, regularSize, CGSize(width: 375, height: 95)] {
|
||||
let status = makeStatus(size: size)
|
||||
host.view.addSubview(status)
|
||||
defer { status.removeFromSuperview() }
|
||||
var actionCalls = 0
|
||||
var detailsCalls = 0
|
||||
status.onPrimaryAction = { actionCalls += 1 }
|
||||
status.onDetails = { detailsCalls += 1 }
|
||||
apply(presentation(.shooting), to: status)
|
||||
window.layoutIfNeeded()
|
||||
try await Task.sleep(for: .milliseconds(50))
|
||||
layoutHierarchy(status)
|
||||
let shooting = try XCTUnwrap(find(in: status, suffix: "shooting"))
|
||||
let title = try XCTUnwrap(find(in: status, suffix: "statusTitle") as? UILabel)
|
||||
let message = try XCTUnwrap(find(in: status, suffix: "statusMessage") as? UILabel)
|
||||
let indicator = try XCTUnwrap(find(in: status, suffix: "shootingIndicator") as? UIButton)
|
||||
XCTAssertFalse(isHidden(shooting))
|
||||
XCTAssertEqual(title.text, "无人机正在拍摄中")
|
||||
XCTAssertEqual(message.text, "请关注现场及实时画面。\n请勿关闭本页或息屏。")
|
||||
if size.height >= 120 {
|
||||
XCTAssertFalse(isHidden(message))
|
||||
XCTAssertEqual(title.convert(title.bounds, to: status).minX, message.convert(message.bounds, to: status).minX, accuracy: 0.5)
|
||||
}
|
||||
XCTAssertFalse(indicator.isEnabled)
|
||||
XCTAssertEqual(indicator.configuration?.title, "拍摄中")
|
||||
XCTAssertNotNil(indicator.configuration?.image)
|
||||
XCTAssertEqual(indicator.configuration?.background.backgroundColor, UIColor(hex: 0xD7E7FF))
|
||||
XCTAssertEqual(indicator.configuration?.baseForegroundColor, UIColor(hex: 0x4D91FF))
|
||||
XCTAssertEqual(indicator.bounds.width, size.width - 36, accuracy: 0.5)
|
||||
XCTAssertGreaterThanOrEqual(indicator.bounds.height, 44)
|
||||
XCTAssertTrue(isHidden(try XCTUnwrap(find(in: status, suffix: "deviceStatus"))))
|
||||
XCTAssertNil(find(in: status, suffix: "details"))
|
||||
if let refresh = find(in: status, suffix: "refresh") { XCTAssertTrue(isHidden(refresh)) }
|
||||
indicator.sendActions(for: .touchUpInside)
|
||||
XCTAssertEqual(actionCalls, 0)
|
||||
XCTAssertEqual(detailsCalls, 0)
|
||||
try assertReadableContainedContent(in: status)
|
||||
if size.height >= 120 { capture(status, name: "拍摄中-原型布局-\(Int(size.width))x\(Int(size.height))") }
|
||||
}
|
||||
}
|
||||
|
||||
/// 从到达到拍摄中再进入错误/完成状态时,独立面板和通用操作互不留下旧入口。
|
||||
func testShootingPanelTransitionsClearOldCountdownAndRestoreAllowedAction() throws {
|
||||
let status = makeStatus(size: regularSize)
|
||||
var actionCalls = 0
|
||||
status.onPrimaryAction = { actionCalls += 1 }
|
||||
apply(presentation(.ready, countdownSeconds: 12), to: status)
|
||||
let countdown = try XCTUnwrap(find(in: status, suffix: "countdown") as? UILabel)
|
||||
XCTAssertFalse(isHidden(countdown))
|
||||
apply(presentation(.shooting), to: status)
|
||||
let indicator = try XCTUnwrap(find(in: status, suffix: "shootingIndicator") as? UIButton)
|
||||
XCTAssertFalse(isHidden(indicator))
|
||||
XCTAssertTrue(isHidden(countdown))
|
||||
status.updateCountdown(seconds: 5)
|
||||
layoutHierarchy(status)
|
||||
XCTAssertTrue(isHidden(countdown))
|
||||
XCTAssertNil(countdown.text)
|
||||
indicator.sendActions(for: .touchUpInside)
|
||||
XCTAssertEqual(actionCalls, 0)
|
||||
apply(presentation(.readError), to: status)
|
||||
XCTAssertTrue(isHidden(indicator))
|
||||
let refresh = try XCTUnwrap(find(in: status, suffix: "refresh") as? UIButton)
|
||||
XCTAssertFalse(isHidden(refresh))
|
||||
XCTAssertTrue(refresh.isEnabled)
|
||||
XCTAssertEqual(refresh.bounds.width, regularSize.width - 32, accuracy: 0.5)
|
||||
refresh.sendActions(for: .touchUpInside)
|
||||
XCTAssertEqual(actionCalls, 1)
|
||||
apply(presentation(.completed), to: status)
|
||||
XCTAssertTrue(isHidden(indicator))
|
||||
let materials = try XCTUnwrap(find(in: status, suffix: "primary") as? UIButton)
|
||||
XCTAssertFalse(isHidden(materials))
|
||||
XCTAssertTrue(materials.isEnabled)
|
||||
materials.sendActions(for: .touchUpInside)
|
||||
XCTAssertEqual(actionCalls, 2)
|
||||
XCTAssertNil(find(in: status, suffix: "details"))
|
||||
try assertReadableContainedContent(in: status)
|
||||
}
|
||||
|
||||
/// 倒计时在固定小屏内保持可见,数字更新不重建按钮、不扩大现有动作许可。
|
||||
func testArrivalCountdownFitsFixedAreasAndUpdatesOnlyDisplay() throws {
|
||||
for size in [compactSize, regularSize] {
|
||||
for longCopy in [false, true] {
|
||||
let status = makeStatus(size: size)
|
||||
apply(presentation(.ready, longCopy: longCopy, countdownSeconds: 30), to: status)
|
||||
let countdown = try XCTUnwrap(find(in: status, suffix: "countdown") as? UILabel)
|
||||
let primary = try XCTUnwrap(find(in: status, suffix: "primary") as? UIButton)
|
||||
let title = try XCTUnwrap(find(in: status, suffix: "statusTitle") as? UILabel)
|
||||
let initialTitle = title.text
|
||||
let initialButtonTitle = primary.title(for: .normal)
|
||||
var actionCalls = 0
|
||||
status.onPrimaryAction = { actionCalls += 1 }
|
||||
XCTAssertEqual(countdown.text, "自动开拍倒计时:30 秒")
|
||||
XCTAssertFalse(isHidden(countdown))
|
||||
XCTAssertFalse(primary.isEnabled)
|
||||
try assertReadableContainedContent(in: status)
|
||||
if !longCopy { capture(status, name: "到达倒计时30秒-\(Int(size.width))x\(Int(size.height))") }
|
||||
|
||||
for seconds in [29, 12, 1, 0, -1] {
|
||||
status.updateCountdown(seconds: seconds)
|
||||
layoutHierarchy(status)
|
||||
XCTAssertEqual(countdown.text, "自动开拍倒计时:\(max(0, seconds)) 秒")
|
||||
XCTAssertFalse(isHidden(countdown))
|
||||
XCTAssertTrue(find(in: status, suffix: "primary") === primary)
|
||||
XCTAssertEqual(primary.title(for: .normal), initialButtonTitle)
|
||||
XCTAssertEqual(title.text, initialTitle)
|
||||
XCTAssertFalse(primary.isEnabled, "倒数到零也不能放开开拍动作")
|
||||
XCTAssertEqual(actionCalls, 0, "数字更新不能触发开拍或其他主动作")
|
||||
XCTAssertEqual(status.bounds.size, size)
|
||||
try assertReadableContainedContent(in: status)
|
||||
}
|
||||
if !longCopy { capture(status, name: "到达倒计时0秒-仍待接口更新-\(Int(size.width))x\(Int(size.height))") }
|
||||
status.updateCountdown(seconds: nil)
|
||||
layoutHierarchy(status)
|
||||
XCTAssertTrue(isHidden(countdown))
|
||||
XCTAssertNil(countdown.text)
|
||||
XCTAssertEqual(actionCalls, 0)
|
||||
try assertReadableContainedContent(in: status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 未到达及后端切换到其他阶段时清除数字,迟到的界面计时更新也不能重新显示。
|
||||
func testCountdownOnlyAppearsForReadyAndClearsAfterPhaseChange() throws {
|
||||
let status = makeStatus(size: compactSize)
|
||||
apply(presentation(.ready, countdownSeconds: 30), to: status)
|
||||
let countdown = try XCTUnwrap(find(in: status, suffix: "countdown") as? UILabel)
|
||||
XCTAssertFalse(isHidden(countdown))
|
||||
for phase in phases where phase != .ready {
|
||||
apply(presentation(phase, countdownSeconds: 30), to: status)
|
||||
XCTAssertTrue(isHidden(countdown), "\(phase)")
|
||||
XCTAssertNil(countdown.text)
|
||||
status.updateCountdown(seconds: 12)
|
||||
layoutHierarchy(status)
|
||||
XCTAssertTrue(isHidden(countdown), "迟到计时不得覆盖 \(phase)")
|
||||
XCTAssertNil(countdown.text)
|
||||
}
|
||||
apply(presentation(.ready), to: status)
|
||||
XCTAssertTrue(isHidden(countdown), "未提供倒计时时保留既有界面")
|
||||
XCTAssertNil(countdown.text)
|
||||
}
|
||||
|
||||
/// 完成态的说明与标题左对齐,素材按钮全宽;刷新或阶段变化不能绕过操作门禁。
|
||||
func testCompletionPanelMatchesPrototypeAndKeepsActionGate() async throws {
|
||||
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)
|
||||
let host = UIViewController()
|
||||
window.rootViewController = host
|
||||
window.makeKeyAndVisible()
|
||||
defer { window.isHidden = true; window.rootViewController = nil; previous?.makeKeyAndVisible() }
|
||||
for size in [compactSize, regularSize] {
|
||||
let status = makeStatus(size: size)
|
||||
host.view.addSubview(status)
|
||||
defer { status.removeFromSuperview() }
|
||||
let value = DroneDockTaskPresentation(phase: .postShootUploading, title: "拍摄已完成",
|
||||
message: "本次拍摄已结束,可前往查看素材。\n素材处理中,可在素材库查看进度。",
|
||||
deviceStatus: "拍摄中 · 电量 90%", action: .materials, actionTitle: "查看素材", isActionEnabled: true)
|
||||
apply(value, to: status)
|
||||
window.layoutIfNeeded()
|
||||
try await Task.sleep(for: .milliseconds(50))
|
||||
layoutHierarchy(status)
|
||||
let title = try XCTUnwrap(find(in: status, suffix: "statusTitle") as? UILabel)
|
||||
let message = try XCTUnwrap(find(in: status, suffix: "statusMessage") as? UILabel)
|
||||
let button = try XCTUnwrap(find(in: status, suffix: "primary") as? UIButton)
|
||||
XCTAssertEqual(title.convert(title.bounds, to: status).minX, message.convert(message.bounds, to: status).minX, accuracy: 0.5)
|
||||
XCTAssertEqual(button.bounds.width, size.width - 32, accuracy: 0.5)
|
||||
XCTAssertNotNil(button.configuration?.image)
|
||||
let text = try XCTUnwrap(button.titleLabel)
|
||||
let image = try XCTUnwrap(button.imageView)
|
||||
let contentFrame = text.convert(text.bounds, to: button).union(image.convert(image.bounds, to: button))
|
||||
XCTAssertEqual(contentFrame.midX, button.bounds.midX, accuracy: 1, "素材图标与文字整体居中")
|
||||
XCTAssertTrue(isHidden(try XCTUnwrap(find(in: status, suffix: "deviceStatus"))))
|
||||
var calls = 0
|
||||
status.onPrimaryAction = { calls += 1 }
|
||||
button.sendActions(for: .touchUpInside)
|
||||
XCTAssertEqual(calls, 1)
|
||||
capture(status, name: "拍摄完成-原型布局-\(Int(size.width))x\(Int(size.height))")
|
||||
status.apply(value, isRefreshing: true)
|
||||
button.sendActions(for: .touchUpInside)
|
||||
XCTAssertEqual(calls, 1)
|
||||
XCTAssertFalse(button.isEnabled)
|
||||
apply(presentation(.failed), to: status)
|
||||
XCTAssertTrue(isHidden(button), "上传失败必须显示失败状态,不能保留完成操作面板")
|
||||
button.sendActions(for: .touchUpInside)
|
||||
XCTAssertEqual(calls, 1)
|
||||
XCTAssertTrue(isHidden(try XCTUnwrap(find(in: status, suffix: "completed"))))
|
||||
try assertReadableContainedContent(in: status)
|
||||
}
|
||||
}
|
||||
|
||||
/// 失败长原因在固定小屏与真实剩余高度内可展开,主按钮保持全宽且不能触发召唤。
|
||||
func testFailureReasonDetailsAndDisabledRetryFitFixedAreas() throws {
|
||||
for size in [compactSize, regularSize, CGSize(width: 402, height: 207.875)] {
|
||||
@@ -110,7 +317,7 @@ final class DroneDockTaskFixedLayoutTests: XCTestCase {
|
||||
XCTAssertEqual(retry.bounds.width, details.bounds.width, accuracy: 0.5)
|
||||
retry.sendActions(for: .touchUpInside)
|
||||
XCTAssertEqual(actionCalls, 0)
|
||||
XCTAssertTrue(isHidden(try XCTUnwrap(find(in: status, suffix: "details"))))
|
||||
XCTAssertNil(find(in: status, suffix: "details"))
|
||||
try assertReadableContainedContent(in: status)
|
||||
}
|
||||
}
|
||||
@@ -227,7 +434,8 @@ final class DroneDockTaskFixedLayoutTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private func presentation(_ phase: DroneDockTaskDisplayPhase, longCopy: Bool = false) -> DroneDockTaskPresentation {
|
||||
private func presentation(_ phase: DroneDockTaskDisplayPhase, longCopy: Bool = false,
|
||||
countdownSeconds: Int? = nil) -> DroneDockTaskPresentation {
|
||||
let title: String
|
||||
let action: DroneDockTaskDisplayAction
|
||||
let actionTitle: String?
|
||||
@@ -236,8 +444,9 @@ final class DroneDockTaskFixedLayoutTests: XCTestCase {
|
||||
case .loading: (title, action, actionTitle, enabled) = ("正在获取任务状态", .none, nil, false)
|
||||
case .navigating: (title, action, actionTitle, enabled) = ("无人机正在前往点位", .refresh, "刷新任务状态", true)
|
||||
case .ready: (title, action, actionTitle, enabled) = ("无人机已到达", .start, "开始拍摄", false)
|
||||
case .shooting: (title, action, actionTitle, enabled) = ("正在拍摄", .refresh, "刷新任务状态", true)
|
||||
case .postShootUploading: (title, action, actionTitle, enabled) = ("拍摄完毕上传中", .refresh, "刷新任务状态", true)
|
||||
case .shooting: (title, action, actionTitle, enabled) = ("无人机正在拍摄中", .none, "拍摄中", false)
|
||||
case .postShootUploading: (title, action, actionTitle, enabled) = ("拍摄已完成", .materials, "查看素材", true)
|
||||
case .postShootUploadFailed: (title, action, actionTitle, enabled) = ("素材上传失败", .materials, "查看素材", true)
|
||||
case .paused: (title, action, actionTitle, enabled) = ("拍摄已暂停", .resume, "继续拍摄", false)
|
||||
case .returning: (title, action, actionTitle, enabled) = ("无人机正在返航", .refresh, "刷新任务状态", true)
|
||||
case .completed: (title, action, actionTitle, enabled) = ("本次拍摄已完成", .materials, "查看素材", true)
|
||||
@@ -249,9 +458,11 @@ final class DroneDockTaskFixedLayoutTests: XCTestCase {
|
||||
let longTitle = String(repeating: "航线任务状态需要确认,", count: 8)
|
||||
let longMessage = String(repeating: "服务端返回的完整错误说明需要保留供工作人员查看,请检查任务和设备状态。", count: 12)
|
||||
return DroneDockTaskPresentation(phase: phase, title: longCopy && phase != .failed ? longTitle : title,
|
||||
message: longCopy ? longMessage : phase == .failed ? "拍摄指令执行失败" : "请确认当前状态后继续操作。",
|
||||
message: longCopy ? longMessage : phase == .failed ? "拍摄指令执行失败"
|
||||
: phase == .shooting ? "请关注现场及实时画面。\n请勿关闭本页或息屏。" : "请确认当前状态后继续操作。",
|
||||
deviceStatus: "空闲 · 电量 93%", action: action, actionTitle: actionTitle, isActionEnabled: enabled,
|
||||
actionNote: phase == .failed ? "无人机离线,暂不可召唤" : nil)
|
||||
actionNote: phase == .failed ? "无人机离线,暂不可召唤" : nil,
|
||||
countdownSeconds: countdownSeconds)
|
||||
}
|
||||
|
||||
private func makeController(service: any DroneDockShootingServing, size: CGSize) throws -> DroneDockShootingTaskViewController {
|
||||
@@ -294,10 +505,12 @@ final class DroneDockTaskFixedLayoutTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
XCTAssertNil(find(in: status, suffix: "details"), file: file, line: line)
|
||||
let failure = try XCTUnwrap(find(in: status, suffix: "failure"), file: file, line: line)
|
||||
let detailsSuffix = isHidden(failure) ? "details" : "failureDetails"
|
||||
let details = try XCTUnwrap(find(in: status, suffix: detailsSuffix) as? UIButton, file: file, line: line)
|
||||
XCTAssertFalse(isHidden(details), file: file, line: line)
|
||||
if !isHidden(failure) {
|
||||
let details = try XCTUnwrap(find(in: status, suffix: "failureDetails") as? UIButton, file: file, line: line)
|
||||
XCTAssertFalse(isHidden(details), file: file, line: line)
|
||||
}
|
||||
}
|
||||
|
||||
private func assertContained(_ view: UIView, in container: UIView,
|
||||
|
||||
Reference in New Issue
Block a user