feat(drone-dock): 搭建机巢工作台与拍摄订单UI
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
import XCTest
|
||||
@testable import suixinkan
|
||||
|
||||
/// 验证首轮机巢 UI 的订单范围、履约分类、任务恢复与遥测占位规则。
|
||||
final class DroneDockViewModelTests: XCTestCase {
|
||||
func testOrdersAreScopedToCurrentUserAndScenic() {
|
||||
let visible = order(id: "mine")
|
||||
let otherUser = order(id: "other-user", userID: "another-user")
|
||||
let otherScenic = order(id: "other-scenic", scenicID: "another-scenic")
|
||||
let store = DroneDockDemoStore(context: context, orders: [visible, otherUser, otherScenic], devices: [])
|
||||
|
||||
XCTAssertEqual(DroneDockWorkbenchViewModel(store: store).orders.map(\.id), ["mine"])
|
||||
XCTAssertEqual(DroneShootingOrdersViewModel(store: store).orders.map(\.id), ["mine"])
|
||||
}
|
||||
|
||||
func testZeroQuotaReturningOrderLeavesHomeButRetainsTaskInCompletedTab() {
|
||||
let returning = order(id: "returning", total: 1, successful: 1, task: task(.returning, result: .succeeded))
|
||||
let pending = order(id: "pending")
|
||||
let store = DroneDockDemoStore(context: context, orders: [returning, pending], devices: [])
|
||||
let home = DroneDockWorkbenchViewModel(store: store)
|
||||
let completed = DroneShootingOrdersViewModel(store: store, initialFilter: .completed)
|
||||
|
||||
XCTAssertEqual(home.orders.map(\.id), ["pending"])
|
||||
XCTAssertEqual(completed.orders.map(\.id), ["returning"])
|
||||
XCTAssertEqual(completed.orders.first?.primaryAction, .viewCurrentTask)
|
||||
XCTAssertEqual(completed.orders.first?.statusTitle, "返航中")
|
||||
XCTAssertEqual(completed.orders.first?.fulfillmentState, .completed)
|
||||
}
|
||||
|
||||
func testActiveOrderIsStablyPinnedAheadOfOtherEligibleOrders() {
|
||||
let first = order(id: "first")
|
||||
let active = order(id: "active", task: task(.arrived))
|
||||
let partial = order(id: "partial", total: 5, successful: 2)
|
||||
let store = DroneDockDemoStore(context: context, orders: [first, active, partial], devices: [])
|
||||
|
||||
XCTAssertEqual(DroneDockWorkbenchViewModel(store: store).orders.map(\.id), ["active", "first", "partial"])
|
||||
}
|
||||
|
||||
func testPartiallyShotOrderRemainsInProgressWithoutFlight() {
|
||||
let partial = order(id: "partial", total: 5, successful: 2)
|
||||
XCTAssertNil(partial.activeTask)
|
||||
XCTAssertEqual(partial.fulfillmentState, .inProgress)
|
||||
XCTAssertEqual(partial.remainingShootingCount, 3)
|
||||
XCTAssertEqual(partial.primaryAction, .continueShooting)
|
||||
XCTAssertTrue(DroneShootingOrderFilter.inProgress.includes(partial))
|
||||
XCTAssertFalse(DroneShootingOrderFilter.pending.includes(partial))
|
||||
}
|
||||
|
||||
func testFiltersUseFulfillmentInsteadOfUploadOrDelivery() {
|
||||
let pending = order(id: "pending")
|
||||
let partial = order(id: "partial", total: 5, successful: 2, material: .failed)
|
||||
let completedUploading = order(id: "uploading", total: 1, successful: 1, material: .uploading)
|
||||
let completedConfirmed = order(
|
||||
id: "confirmed", total: 5, successful: 5, material: .ready,
|
||||
delivered: 2, confirmation: .confirmed
|
||||
)
|
||||
let viewModel = DroneShootingOrdersViewModel(store: DroneDockDemoStore(
|
||||
context: context, orders: [pending, partial, completedUploading, completedConfirmed], devices: []
|
||||
))
|
||||
|
||||
XCTAssertEqual(viewModel.count(for: .all), 4)
|
||||
XCTAssertEqual(viewModel.count(for: .pending), 1)
|
||||
XCTAssertEqual(viewModel.count(for: .inProgress), 1)
|
||||
XCTAssertEqual(viewModel.count(for: .completed), 2)
|
||||
viewModel.selectFilter(.completed)
|
||||
XCTAssertEqual(viewModel.orders.map(\.id), ["uploading", "confirmed"])
|
||||
}
|
||||
|
||||
func testPrimaryActionPreservesStartContinueRecoveryAndCurrentTaskMeaning() {
|
||||
XCTAssertEqual(order(id: "new").primaryAction, .startShooting)
|
||||
XCTAssertEqual(order(id: "partial", total: 3, successful: 1).primaryAction, .continueShooting)
|
||||
XCTAssertEqual(order(id: "failed", needsRepreparation: true).primaryAction, .prepareAgain)
|
||||
XCTAssertEqual(order(id: "done", total: 1, successful: 1).primaryAction, .none)
|
||||
for phase in DroneShootingTaskPhase.allCases {
|
||||
XCTAssertEqual(order(id: phase.rawValue, task: task(phase)).primaryAction, .viewCurrentTask)
|
||||
}
|
||||
}
|
||||
|
||||
func testSevenTaskLabelsAndIndependentSuccessfulReturn() {
|
||||
XCTAssertEqual(DroneShootingTaskPhase.allCases.map(\.title), [
|
||||
"前往拍摄点中", "已到达,待拍摄", "拍摄中", "拍摄已暂停", "返航中", "返航已暂停", "任务状态待确认"
|
||||
])
|
||||
let succeeded = order(id: "success", total: 3, successful: 1, task: task(.returning, result: .succeeded))
|
||||
XCTAssertEqual(succeeded.activeTask?.shootingResult, .succeeded)
|
||||
XCTAssertEqual(succeeded.activeTask?.phase, .returning)
|
||||
XCTAssertEqual(succeeded.remainingShootingCount, 2)
|
||||
XCTAssertEqual(succeeded.primaryAction.title, "查看当前任务")
|
||||
}
|
||||
|
||||
func testRepeatedPageRefreshDoesNotChangeTaskOrConsumeQuota() {
|
||||
let active = order(id: "active", total: 5, successful: 2, task: task(.unconfirmed, result: .unknown))
|
||||
let store = DroneDockDemoStore(context: context, orders: [active], devices: [])
|
||||
let home = DroneDockWorkbenchViewModel(store: store)
|
||||
let list = DroneShootingOrdersViewModel(store: store)
|
||||
|
||||
for _ in 0..<5 {
|
||||
home.refresh()
|
||||
list.selectFilter(.inProgress)
|
||||
list.refresh()
|
||||
}
|
||||
|
||||
XCTAssertEqual(home.orders, [active])
|
||||
XCTAssertEqual(list.orders, [active])
|
||||
XCTAssertEqual(store.orders.first?.remainingShootingCount, 3)
|
||||
}
|
||||
|
||||
func testScenicSwitchPreservesOriginalTaskOnReturn() {
|
||||
let original = order(id: "active", task: task(.shootingPaused))
|
||||
let store = DroneDockDemoStore(context: context, orders: [original], devices: [])
|
||||
let home = DroneDockWorkbenchViewModel(store: store)
|
||||
let other = DroneDockContext(
|
||||
scenicID: "another-scenic", scenicName: "另一景区",
|
||||
userID: context.userID, photographerName: context.photographerName
|
||||
)
|
||||
|
||||
home.switchContext(to: other)
|
||||
XCTAssertNil(home.order(id: original.id))
|
||||
XCTAssertTrue(home.orders.allSatisfy { $0.scenicID == other.scenicID })
|
||||
home.switchContext(to: context)
|
||||
XCTAssertEqual(home.orders, [original])
|
||||
XCTAssertEqual(home.orders.first?.activeTask?.phase, .shootingPaused)
|
||||
}
|
||||
|
||||
func testUnknownTelemetryDiffersFromMeasuredZero() {
|
||||
let unknown = DroneDockTelemetry.unknown
|
||||
XCTAssertNil(unknown.batteryProgress)
|
||||
XCTAssertEqual([
|
||||
unknown.batteryText, unknown.temperatureText, unknown.windText,
|
||||
unknown.rainText, unknown.signalText, unknown.satelliteText
|
||||
], Array(repeating: "—", count: 6))
|
||||
|
||||
let zero = DroneDockTelemetry(
|
||||
batteryPercent: 0, temperatureCelsius: 0, windSpeed: 0,
|
||||
rainDescription: "无雨", signalDescription: "无信号", satelliteCount: 0
|
||||
)
|
||||
XCTAssertEqual(zero.batteryProgress, 0)
|
||||
XCTAssertEqual(zero.batteryText, "0%")
|
||||
XCTAssertEqual(zero.temperatureText, "0.0°C")
|
||||
XCTAssertEqual(zero.windText, "0m/s")
|
||||
XCTAssertEqual(zero.satelliteText, "0颗")
|
||||
}
|
||||
|
||||
func testPaymentOriginCanOpenPendingFilterWithoutChangingDefaultAllEntry() {
|
||||
let store = DroneDockDemoStore(context: context)
|
||||
XCTAssertEqual(DroneShootingOrdersViewModel(store: store).selectedFilter, .all)
|
||||
let fromPayment = DroneShootingOrdersViewModel(store: store, initialFilter: .pending)
|
||||
XCTAssertEqual(fromPayment.selectedFilter, .pending)
|
||||
XCTAssertTrue(fromPayment.orders.allSatisfy { $0.fulfillmentState == .pending })
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
func testScenarioChangesAreVisibleToSharedOrderPageOnRefresh() {
|
||||
let store = DroneDockDemoStore(context: context)
|
||||
let home = DroneDockWorkbenchViewModel(store: store)
|
||||
let completed = DroneShootingOrdersViewModel(store: store, initialFilter: .completed)
|
||||
|
||||
home.applyScenario(.completedReturning)
|
||||
completed.refresh()
|
||||
let returning = completed.orders.first { $0.activeTask?.phase == .returning }
|
||||
XCTAssertNotNil(returning)
|
||||
XCTAssertEqual(returning?.remainingShootingCount, 0)
|
||||
XCTAssertFalse(home.orders.contains { $0.id == returning?.id })
|
||||
|
||||
home.applyScenario(.emptyOrders)
|
||||
completed.refresh()
|
||||
XCTAssertTrue(home.orders.isEmpty)
|
||||
XCTAssertTrue(completed.orders.isEmpty)
|
||||
XCTAssertEqual(home.statistics.orderCount, 0)
|
||||
}
|
||||
#endif
|
||||
|
||||
private var context: DroneDockContext {
|
||||
DroneDockContext(scenicID: "scenic", scenicName: "测试景区", userID: "user", photographerName: "工作人员")
|
||||
}
|
||||
|
||||
private func task(
|
||||
_ phase: DroneShootingTaskPhase, result: DroneShootingResult = .inProgress
|
||||
) -> DroneShootingTask {
|
||||
DroneShootingTask(id: "test-task", phase: phase, shootingResult: result)
|
||||
}
|
||||
|
||||
private func order(
|
||||
id: String, scenicID: String = "scenic", userID: String = "user",
|
||||
total: Int = 1, successful: Int = 0, task: DroneShootingTask? = nil,
|
||||
needsRepreparation: Bool = false, material: DroneShootingMaterialState = .none,
|
||||
delivered: Int = 0, confirmation: DroneVisitorConfirmationState = .none
|
||||
) -> DroneShootingOrder {
|
||||
DroneShootingOrder(
|
||||
id: id, scenicID: scenicID, assignedUserID: userID, customerName: "游客136****2806",
|
||||
orderNumber: "TEST-\(id)", createdAtText: "10-23 09:00", packageName: "测试航拍套餐",
|
||||
totalShootingCount: total, successfulShootingCount: successful,
|
||||
activeTask: task, needsRepreparation: needsRepreparation, materialState: material,
|
||||
deliveredVideoCount: delivered, visitorConfirmationState: confirmation
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
import UIKit
|
||||
import XCTest
|
||||
@testable import suixinkan
|
||||
|
||||
/// 在真机窗口中验证机巢页面的交互连线与布局,并保留视觉验收截图。
|
||||
@MainActor
|
||||
final class DroneDockViewTests: XCTestCase {
|
||||
private weak var previousKeyWindow: UIWindow?
|
||||
|
||||
/// 零次订单仍在返航时,完整订单卡保留当前任务入口,渲染及点击都不改变次数。
|
||||
func testCompletedReturningCardKeepsCurrentTaskActionWithoutChangingQuota() async throws {
|
||||
let order = returningOrder()
|
||||
let store = DroneDockDemoStore(context: .demo, orders: [order], devices: [])
|
||||
let controller = UIViewController()
|
||||
controller.title = "返航中的已完成订单"
|
||||
controller.view.backgroundColor = .systemGroupedBackground
|
||||
let card = DroneShootingOrderCardView()
|
||||
card.translatesAutoresizingMaskIntoConstraints = false
|
||||
controller.view.addSubview(card)
|
||||
NSLayoutConstraint.activate([
|
||||
card.leadingAnchor.constraint(equalTo: controller.view.leadingAnchor, constant: 16),
|
||||
card.trailingAnchor.constraint(equalTo: controller.view.trailingAnchor, constant: -16),
|
||||
card.topAnchor.constraint(equalTo: controller.view.safeAreaLayoutGuide.topAnchor, constant: 16)
|
||||
])
|
||||
var currentTaskTapCount = 0
|
||||
var deliveryTapCount = 0
|
||||
card.onShootingTap = { currentTaskTapCount += 1 }
|
||||
card.onDeliveryTap = { deliveryTapCount += 1 }
|
||||
card.apply(order: order)
|
||||
let window = makeWindow(root: controller)
|
||||
defer { close(window) }
|
||||
try await settle(window: window) { card.bounds.height > 0 }
|
||||
|
||||
let action = try button(in: card, identifier: "drone.order.\(order.id).primary")
|
||||
XCTAssertEqual(action.title(for: .normal), "查看当前任务")
|
||||
assertVisibleAndEnabled(action, in: window)
|
||||
XCTAssertTrue(labels(in: card).contains { $0.text == "返航中" })
|
||||
for _ in 0..<3 {
|
||||
card.apply(order: order)
|
||||
action.sendActions(for: .touchUpInside)
|
||||
}
|
||||
|
||||
XCTAssertEqual(currentTaskTapCount, 3)
|
||||
XCTAssertEqual(deliveryTapCount, 0)
|
||||
XCTAssertEqual(store.orders, [order])
|
||||
XCTAssertEqual(store.orders.first?.remainingShootingCount, 0)
|
||||
XCTAssertEqual(store.orders.first?.activeTask?.shootingResult, .succeeded)
|
||||
assertUnambiguousVisibleLayout(in: card)
|
||||
capture(window, named: "机巢-零次仍返航订单卡")
|
||||
}
|
||||
|
||||
/// 工作台实际展示本地设备与订单,查看全部通过真实按钮进入共享数据的订单页。
|
||||
func testWorkbenchRendersAndViewAllOpensOrders() async throws {
|
||||
let store = DroneDockDemoStore()
|
||||
let controller = DroneDockWorkbenchViewController(viewModel: DroneDockWorkbenchViewModel(store: store))
|
||||
let window = makeWindow(root: controller)
|
||||
defer { close(window) }
|
||||
let list = try collection(in: controller.view, identifier: "drone.workbench.list")
|
||||
try await settle(window: window) {
|
||||
!list.visibleCells.isEmpty && self.find(in: controller.view, identifier: "drone.workbench.allOrders") != nil
|
||||
}
|
||||
|
||||
XCTAssertEqual(controller.title, "机巢工作台")
|
||||
let firstDevice = try XCTUnwrap(store.devices.first)
|
||||
XCTAssertTrue(allViews(in: controller.view).contains { $0.accessibilityIdentifier == "drone.device.\(firstDevice.id)" })
|
||||
XCTAssertTrue(controller.navigationItem.rightBarButtonItems?.contains { $0.accessibilityLabel == "收款码" } == true)
|
||||
let viewAll = try button(in: controller.view, identifier: "drone.workbench.allOrders")
|
||||
assertVisibleAndEnabled(viewAll, in: window)
|
||||
assertUnambiguousVisibleLayout(in: controller.view)
|
||||
capture(window, named: "机巢-工作台首屏")
|
||||
|
||||
viewAll.sendActions(for: .touchUpInside)
|
||||
try await settle(window: window) {
|
||||
controller.navigationController?.topViewController is DroneShootingOrdersViewController
|
||||
&& controller.navigationController?.transitionCoordinator == nil
|
||||
}
|
||||
let ordersController = try XCTUnwrap(controller.navigationController?.topViewController as? DroneShootingOrdersViewController)
|
||||
let ordersList = try collection(in: ordersController.view, identifier: "drone.orders.list")
|
||||
try await settle(window: window) { ordersList.numberOfSections > 0 && ordersList.numberOfItems(inSection: 0) == store.orders.count }
|
||||
let allFilter = try button(in: ordersController.view, identifier: "drone.orders.filter.all")
|
||||
XCTAssertTrue(allFilter.accessibilityTraits.contains(.selected))
|
||||
capture(window, named: "机巢-查看全部进入拍摄订单")
|
||||
}
|
||||
|
||||
/// 通过真实 Tab 切到已完成后,零次返航订单仍可回到同一任务,素材和交付状态不改变分类。
|
||||
func testCompletedOrdersRenderAndKeepReturningTaskCallback() async throws {
|
||||
let demo = DroneDockDemoStore()
|
||||
let returning = returningOrder()
|
||||
let store = DroneDockDemoStore(context: .demo, orders: [returning] + demo.orders, devices: demo.devices)
|
||||
let originalOrders = store.orders
|
||||
let viewModel = DroneShootingOrdersViewModel(store: store)
|
||||
let controller = DroneShootingOrdersViewController(viewModel: viewModel)
|
||||
let delegate = DroneDockOrdersDelegateSpy()
|
||||
controller.delegate = delegate
|
||||
let window = makeWindow(root: controller)
|
||||
defer { close(window) }
|
||||
let list = try collection(in: controller.view, identifier: "drone.orders.list")
|
||||
try await settle(window: window) { list.numberOfSections > 0 && list.numberOfItems(inSection: 0) == originalOrders.count }
|
||||
|
||||
let completedTab = try button(in: controller.view, identifier: "drone.orders.filter.completed")
|
||||
assertVisibleAndEnabled(completedTab, in: window)
|
||||
completedTab.sendActions(for: .touchUpInside)
|
||||
let completedCount = originalOrders.filter { $0.fulfillmentState == .completed }.count
|
||||
try await settle(window: window) {
|
||||
viewModel.selectedFilter == .completed
|
||||
&& list.numberOfSections > 0 && list.numberOfItems(inSection: 0) == completedCount
|
||||
&& self.find(in: controller.view, identifier: "drone.order.\(returning.id).primary") != nil
|
||||
}
|
||||
|
||||
XCTAssertTrue(completedTab.accessibilityTraits.contains(.selected))
|
||||
XCTAssertTrue(viewModel.orders.allSatisfy { $0.remainingShootingCount == 0 })
|
||||
XCTAssertEqual(viewModel.orders.first?.id, returning.id)
|
||||
let currentTask = try button(in: controller.view, identifier: "drone.order.\(returning.id).primary")
|
||||
XCTAssertEqual(currentTask.title(for: .normal), "查看当前任务")
|
||||
assertVisibleAndEnabled(currentTask, in: window)
|
||||
assertUnambiguousVisibleLayout(in: controller.view)
|
||||
capture(window, named: "机巢-已完成订单含零次返航")
|
||||
currentTask.sendActions(for: .touchUpInside)
|
||||
|
||||
XCTAssertEqual(delegate.shootingOrders, [returning])
|
||||
XCTAssertTrue(delegate.materialOrders.isEmpty)
|
||||
XCTAssertTrue(delegate.deliveryOrders.isEmpty)
|
||||
XCTAssertEqual(store.orders, originalOrders)
|
||||
|
||||
let pendingTab = try button(in: controller.view, identifier: "drone.orders.filter.pending")
|
||||
pendingTab.sendActions(for: .touchUpInside)
|
||||
try await settle(window: window) {
|
||||
viewModel.selectedFilter == .pending
|
||||
&& list.numberOfSections > 0 && list.numberOfItems(inSection: 0) == viewModel.orders.count
|
||||
}
|
||||
XCTAssertFalse(viewModel.orders.contains { $0.id == returning.id })
|
||||
XCTAssertTrue(viewModel.orders.allSatisfy { $0.fulfillmentState == .pending })
|
||||
}
|
||||
|
||||
/// 创建真实场景中的临时窗口,不更改会话或权限。
|
||||
private func makeWindow(root controller: UIViewController) -> UIWindow {
|
||||
let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
|
||||
let scene = scenes.first { $0.activationState == .foregroundActive } ?? scenes.first
|
||||
previousKeyWindow = scene?.windows.first { $0.isKeyWindow }
|
||||
let window = scene.map { UIWindow(windowScene: $0) } ?? UIWindow(frame: UIScreen.main.bounds)
|
||||
window.frame = scene?.coordinateSpace.bounds ?? UIScreen.main.bounds
|
||||
window.overrideUserInterfaceStyle = .light
|
||||
window.rootViewController = UINavigationController(rootViewController: controller)
|
||||
window.makeKeyAndVisible()
|
||||
window.layoutIfNeeded()
|
||||
return window
|
||||
}
|
||||
|
||||
/// 关闭临时窗口并恢复测试前的主窗口。
|
||||
private func close(_ window: UIWindow) {
|
||||
window.endEditing(true)
|
||||
window.rootViewController?.dismiss(animated: false)
|
||||
window.isHidden = true
|
||||
window.rootViewController = nil
|
||||
previousKeyWindow?.makeKeyAndVisible()
|
||||
}
|
||||
|
||||
/// 等待 Diffable 快照及导航布局完成,再给自适应单元格一次稳定布局机会。
|
||||
private func settle(window: UIWindow, until condition: () -> Bool) async throws {
|
||||
for _ in 0..<150 {
|
||||
window.layoutIfNeeded()
|
||||
window.rootViewController?.view.layoutIfNeeded()
|
||||
if condition() {
|
||||
try await Task.sleep(nanoseconds: 350_000_000)
|
||||
window.layoutIfNeeded()
|
||||
return
|
||||
}
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
XCTFail("机巢页面未在预期时间内完成快照和布局")
|
||||
throw NSError(domain: "DroneDockViewTests", code: 1)
|
||||
}
|
||||
|
||||
/// 仅查询实际视图树中的控件,避免依赖页面私有存储。
|
||||
private func allViews(in view: UIView) -> [UIView] {
|
||||
[view] + view.subviews.flatMap { allViews(in: $0) }
|
||||
}
|
||||
|
||||
private func find(in view: UIView, identifier: String) -> UIView? {
|
||||
allViews(in: view).first { $0.accessibilityIdentifier == identifier }
|
||||
}
|
||||
|
||||
private func button(in view: UIView, identifier: String) throws -> UIButton {
|
||||
try XCTUnwrap(find(in: view, identifier: identifier) as? UIButton, "缺少按钮 \(identifier)")
|
||||
}
|
||||
|
||||
private func collection(in view: UIView, identifier: String) throws -> UICollectionView {
|
||||
try XCTUnwrap(find(in: view, identifier: identifier) as? UICollectionView, "缺少列表 \(identifier)")
|
||||
}
|
||||
|
||||
private func labels(in view: UIView) -> [UILabel] {
|
||||
allViews(in: view).compactMap { $0 as? UILabel }
|
||||
}
|
||||
|
||||
/// 排除隐藏祖先的控件,检查实际可见按钮有可触达的面积。
|
||||
private func assertVisibleAndEnabled(_ button: UIButton, in window: UIWindow, file: StaticString = #filePath, line: UInt = #line) {
|
||||
XCTAssertTrue(button.isEnabled, file: file, line: line)
|
||||
XCTAssertFalse(isHiddenByAncestor(button), file: file, line: line)
|
||||
let frame = button.convert(button.bounds, to: window)
|
||||
XCTAssertGreaterThan(frame.width, 0, file: file, line: line)
|
||||
XCTAssertGreaterThanOrEqual(frame.height, 30, file: file, line: line)
|
||||
XCTAssertTrue(window.bounds.contains(frame), "按钮超出窗口:\(frame)", file: file, line: line)
|
||||
}
|
||||
|
||||
/// 只检查可见且参与约束布局的应用内容,不检查 UIKit 私有视图或隐藏复用内容。
|
||||
private func assertUnambiguousVisibleLayout(in root: UIView, file: StaticString = #filePath, line: UInt = #line) {
|
||||
let ambiguous = allViews(in: root).filter {
|
||||
!$0.translatesAutoresizingMaskIntoConstraints && !isHiddenByAncestor($0)
|
||||
&& !$0.bounds.isEmpty && !String(describing: type(of: $0)).hasPrefix("_") && $0.hasAmbiguousLayout
|
||||
}
|
||||
let descriptions = ambiguous.map { "\(type(of: $0)) \($0.accessibilityIdentifier ?? "") \($0.frame)" }
|
||||
XCTAssertTrue(ambiguous.isEmpty, "布局存在歧义:\(descriptions)", file: file, line: line)
|
||||
}
|
||||
|
||||
private func isHiddenByAncestor(_ view: UIView) -> Bool {
|
||||
if view.isHidden || view.alpha < 0.01 { return true }
|
||||
return view.superview.map { isHiddenByAncestor($0) } ?? false
|
||||
}
|
||||
|
||||
/// 将页面保留到真机 xcresult,供开发者按新版原型进行视觉复核。
|
||||
private func capture(_ window: UIWindow, named name: String) {
|
||||
let image = UIGraphicsImageRenderer(bounds: window.bounds).image { _ in
|
||||
window.drawHierarchy(in: window.bounds, afterScreenUpdates: true)
|
||||
}
|
||||
let attachment = XCTAttachment(image: image)
|
||||
attachment.name = name
|
||||
attachment.lifetime = .keepAlways
|
||||
add(attachment)
|
||||
}
|
||||
|
||||
/// 构造已成功扣完一次、但无人机仍在返航的确定性订单。
|
||||
private func returningOrder() -> DroneShootingOrder {
|
||||
DroneShootingOrder(
|
||||
id: "ui-returning-completed", scenicID: DroneDockContext.demo.scenicID,
|
||||
assignedUserID: DroneDockContext.demo.userID, customerName: "游客136****2806",
|
||||
orderNumber: "HT202610230001", createdAtText: "10-23 09:00", packageName: "单次航拍",
|
||||
totalShootingCount: 1, successfulShootingCount: 1,
|
||||
activeTask: DroneShootingTask(id: "ui-returning-task", phase: .returning, shootingResult: .succeeded),
|
||||
needsRepreparation: false, materialState: .uploading, deliveredVideoCount: 0,
|
||||
visitorConfirmationState: .none
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// 记录订单页发出的语义导航回调,不弹出未完成的下级业务页面。
|
||||
@MainActor
|
||||
private final class DroneDockOrdersDelegateSpy: DroneShootingOrdersViewControllerDelegate {
|
||||
var shootingOrders: [DroneShootingOrder] = []
|
||||
var materialOrders: [DroneShootingOrder] = []
|
||||
var deliveryOrders: [DroneShootingOrder] = []
|
||||
|
||||
func shootingOrdersViewController(_ controller: DroneShootingOrdersViewController, didSelectShooting order: DroneShootingOrder) {
|
||||
shootingOrders.append(order)
|
||||
}
|
||||
|
||||
func shootingOrdersViewController(_ controller: DroneShootingOrdersViewController, didSelectMaterials order: DroneShootingOrder) {
|
||||
materialOrders.append(order)
|
||||
}
|
||||
|
||||
func shootingOrdersViewController(_ controller: DroneShootingOrdersViewController, didSelectDelivery order: DroneShootingOrder) {
|
||||
deliveryOrders.append(order)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user