From f7a2a19deebb45c9739856c9bbfadfa12b37d72b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=89=E7=A7=8B?= <497055328@qq.com> Date: Tue, 27 Oct 2026 17:58:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(drone-dock):=20=E5=B1=95=E7=A4=BA=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E7=9C=9F=E5=AE=9E=E6=8B=8D=E6=91=84=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/DroneDockHomeModels.swift | 130 ++++++++++- .../DroneDock/DroneDockCompactOrderCell.swift | 57 ++++- .../DroneDockHomeViewController.swift | 42 ++-- suixinkanTests/DroneDockHomeAPITests.swift | 22 +- suixinkanTests/DroneDockHomeOrderTests.swift | 134 +++++++++++ .../DroneDockRemoteHomeViewTests.swift | 209 +++++++++++++++++- 6 files changed, 552 insertions(+), 42 deletions(-) create mode 100644 suixinkanTests/DroneDockHomeOrderTests.swift diff --git a/suixinkan/Features/DroneDock/Models/DroneDockHomeModels.swift b/suixinkan/Features/DroneDock/Models/DroneDockHomeModels.swift index 803708d..0734e03 100644 --- a/suixinkan/Features/DroneDock/Models/DroneDockHomeModels.swift +++ b/suixinkan/Features/DroneDock/Models/DroneDockHomeModels.swift @@ -6,8 +6,8 @@ struct DroneDockHomeResponse: Decodable, Equatable, Sendable { let scenicID: Int /// 当前景区的机巢设备,按真实非空响应的字段读取。 let airports: [DroneDockHomeAirport] - /// 订单原始记录;不将未知字段猜测成演示订单。 - let orders: [DroneDockHomeRecord] + /// 按真实响应字段读取的拍摄订单,保持后端返回顺序。 + let orders: [DroneDockHomeOrder] /// 今日数据缺失时保留未知,不生成零值统计。 let today: DroneDockHomeToday? @@ -28,7 +28,10 @@ struct DroneDockHomeResponse: Decodable, Equatable, Sendable { guard Set(airports.map(\.id)).count == airports.count else { throw DecodingError.dataCorruptedError(forKey: .airports, in: container, debugDescription: "设备 ID 重复,无法确定设备身份") } - orders = try container.decode([DroneDockHomeRecord].self, forKey: .orders) + orders = try container.decode([DroneDockHomeOrder].self, forKey: .orders) + guard Set(orders.map(\.orderID)).count == orders.count else { + throw DecodingError.dataCorruptedError(forKey: .orders, in: container, debugDescription: "订单 ID 重复,无法确定订单身份") + } today = try container.decodeIfPresent(DroneDockHomeToday.self, forKey: .today) } } @@ -153,14 +156,123 @@ struct DroneDockHomeToday: Decodable, Equatable, Sendable { } } -/// 尚未取得真实样本的订单行,保留对象字段供后续精确接入和诊断。 -struct DroneDockHomeRecord: Decodable, Equatable, Sendable { - /// 原始对象键值,不猜测订单状态或拍摄次数的字段别名。 - let fields: [String: DroneDockHomeJSONValue] +/// 首页拍摄订单的展示数据;状态及动作仅用于呈现,不代表飞行执行许可。 +struct DroneDockHomeOrder: Decodable, Equatable, Sendable { + /// 后端订单稳定 ID,用于 Diffable 项身份。 + let orderID: Int + /// 后端订单编号,保留字符串形式与前导零。 + let orderNumber: String? + /// 后端游客展示名称。 + let touristLabel: String? + /// 后端已脱敏的游客手机号。 + let touristPhoneMask: String? + /// 后端套餐名称,不据此推断套餐类型或项目 ID。 + let packageName: String? + /// 后端订单状态展示文案。 + let statusLabel: String? + /// 后端拍摄总次数,未知时不默认成零。 + let shotTotal: Int? + /// 后端已拍摄次数,不在客户端根据任务状态重新计算。 + let shotUsed: Int? + /// 后端剩余拍摄次数,不用总次数减已拍摄次数推断。 + let shotRemain: Int? + /// 后端格式化的拍摄进度文案。 + let progressText: String? + /// 后端素材状态原始值,保留尚未验证的值。 + let mediaStatus: String? + /// 后端素材状态展示文案;空文案不生成新的业务状态。 + let mediaStatusLabel: String? + /// 后端主动作标识,仅用于展示入口,不作为执行权限。 + let primaryAction: String? + /// 后端主动作按钮文案。 + let primaryActionLabel: String? + /// 后端游客用户 ID。 + let userID: Int? - /// 只接受 JSON 对象作为列表记录,拒绝 null、标量和嵌套数组。 + /// 已实测的首页订单字段名。 + private enum CodingKeys: String, CodingKey { + case orderID = "order_id" + case orderNumber = "order_number" + case touristLabel = "tourist_label" + case touristPhoneMask = "tourist_phone_mask" + case packageName = "package_name" + case statusLabel = "status_label" + case shotTotal = "shot_total" + case shotUsed = "shot_used" + case shotRemain = "shot_remain" + case progressText = "progress_text" + case mediaStatus = "media_status" + case mediaStatusLabel = "media_status_label" + case primaryAction = "primary_action" + case primaryActionLabel = "primary_action_label" + case userID = "user_id" + } + + /// 严格校验列表身份和计数;缺失展示字段保留未知。 init(from decoder: Decoder) throws { - fields = try decoder.singleValueContainer().decode([String: DroneDockHomeJSONValue].self) + let container = try decoder.container(keyedBy: CodingKeys.self) + orderID = try container.decode(DroneDockHomeInteger.self, forKey: .orderID).value + guard orderID > 0 else { + throw DecodingError.dataCorruptedError(forKey: .orderID, in: container, debugDescription: "订单 ID 必须为正整数") + } + orderNumber = try container.decodeIfPresent(String.self, forKey: .orderNumber) + touristLabel = try container.decodeIfPresent(String.self, forKey: .touristLabel) + touristPhoneMask = try container.decodeIfPresent(String.self, forKey: .touristPhoneMask) + packageName = try container.decodeIfPresent(String.self, forKey: .packageName) + statusLabel = try container.decodeIfPresent(String.self, forKey: .statusLabel) + shotTotal = try container.decodeIfPresent(DroneDockHomeInteger.self, forKey: .shotTotal)?.value + shotUsed = try container.decodeIfPresent(DroneDockHomeInteger.self, forKey: .shotUsed)?.value + shotRemain = try container.decodeIfPresent(DroneDockHomeInteger.self, forKey: .shotRemain)?.value + for (key, value) in [(CodingKeys.shotTotal, shotTotal), (.shotUsed, shotUsed), (.shotRemain, shotRemain)] { + if let value, value < 0 { + throw DecodingError.dataCorruptedError(forKey: key, in: container, debugDescription: "拍摄次数不能为负数") + } + } + progressText = try container.decodeIfPresent(String.self, forKey: .progressText) + mediaStatus = try container.decodeIfPresent(String.self, forKey: .mediaStatus) + mediaStatusLabel = try container.decodeIfPresent(String.self, forKey: .mediaStatusLabel) + primaryAction = try container.decodeIfPresent(String.self, forKey: .primaryAction) + primaryActionLabel = try container.decodeIfPresent(String.self, forKey: .primaryActionLabel) + userID = try container.decodeIfPresent(DroneDockHomeInteger.self, forKey: .userID)?.value + } + + /// 页面稳定身份,与后端订单 ID 一致。 + var id: Int { orderID } + + /// 展示后端订单编号;缺失时不以内部 ID 冒充订单编号。 + var orderNumberText: String { DroneDockHomeMetric.usableText(orderNumber) ?? "—" } + + /// 优先展示服务端游客文案,其次使用已脱敏手机号。 + var touristTitle: String { + if let label = DroneDockHomeMetric.usableText(touristLabel) { return label } + if let phone = DroneDockHomeMetric.usableText(touristPhoneMask) { return "游客 \(phone)" } + return "游客信息待确认" + } + + /// 展示后端套餐名称,缺失时不生成套餐或次数。 + var packageTitle: String { DroneDockHomeMetric.usableText(packageName) ?? "套餐信息待确认" } + + /// 展示后端状态,缺失时不默认成待拍摄。 + var statusTitle: String { DroneDockHomeMetric.usableText(statusLabel) ?? "状态待确认" } + + /// 优先展示后端进度文案;没有文案时逐项展示真实计数与未知占位。 + var progressTitle: String { + if let text = DroneDockHomeMetric.usableText(progressText) { return text } + let used = shotUsed.map(String.init) ?? "—" + let total = shotTotal.map(String.init) ?? "—" + let remain = shotRemain.map(String.init) ?? "—" + return "已拍摄 \(used)/\(total) 次,剩余 \(remain) 次" + } + + /// 只有后端同时提供动作标识和文案时才显示按钮,不猜测缺失动作。 + var actionTitle: String? { + guard DroneDockHomeMetric.usableText(primaryAction) != nil else { return nil } + return DroneDockHomeMetric.usableText(primaryActionLabel) + } + + /// 仅展示有效的后端素材状态文案,不将空值转成未上传等新状态。 + var mediaStatusTitle: String? { + DroneDockHomeMetric.usableText(mediaStatusLabel) } } diff --git a/suixinkan/UI/DroneDock/DroneDockCompactOrderCell.swift b/suixinkan/UI/DroneDock/DroneDockCompactOrderCell.swift index 99b7f3c..fcefcf8 100644 --- a/suixinkan/UI/DroneDock/DroneDockCompactOrderCell.swift +++ b/suixinkan/UI/DroneDock/DroneDockCompactOrderCell.swift @@ -10,6 +10,7 @@ final class DroneDockCompactOrderCell: UICollectionViewCell { private let customerLabel = DroneDockStyle.label(size: 16, weight: .bold) private let statusLabel = DroneDockStatusLabel() + private let orderNumberLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary) private let packageLabel = DroneDockStyle.label(size: 13, color: UIColor(hex: 0x666E7C)) private let countsLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary) private let actionButton = UIButton(type: .system) @@ -29,19 +30,54 @@ final class DroneDockCompactOrderCell: UICollectionViewCell { /// 应用数据,不展示具体点位或航线,也不在卡片自行扣次。 func apply(order: DroneShootingOrder) { customerLabel.text = order.customerName + orderNumberLabel.isHidden = true statusLabel.apply(title: order.statusTitle, tone: order.statusTone) packageLabel.text = order.packageSummary + packageLabel.numberOfLines = 1 + countsLabel.numberOfLines = 1 + actionButton.titleLabel?.numberOfLines = 1 countsLabel.text = "已拍摄 \(order.successfulShootingCount)/\(order.totalShootingCount) 次 · 剩余 \(order.remainingShootingCount) 次" actionButton.setTitle(order.primaryAction.title, for: .normal) + actionButton.isHidden = false actionButton.isEnabled = order.primaryActionEnabled + actionButton.backgroundColor = DroneDockStyle.primary actionButton.accessibilityIdentifier = "drone.home.\(order.id).primary" footer.isHidden = !order.hasMaterials + applyMaterial(title: order.materialState.title, symbol: order.materialState.systemImageName, + tone: order.materialState.tone) + accessibilityIdentifier = "drone.home.\(order.id)" + } + + /// 展示 home 的真实订单快照,缺失字段保持未知,按钮只向页面报告点击。 + func apply(homeOrder order: DroneDockHomeOrder) { + customerLabel.text = order.touristTitle + orderNumberLabel.isHidden = false + orderNumberLabel.text = "订单号 \(order.orderNumberText)" + statusLabel.apply(title: order.statusTitle, tone: order.statusTitle == "待拍摄" ? .blue : .gray) + packageLabel.text = order.packageTitle + packageLabel.numberOfLines = 0 + countsLabel.numberOfLines = 0 + actionButton.titleLabel?.numberOfLines = 2 + countsLabel.text = order.progressTitle + actionButton.setTitle(order.actionTitle, for: .normal) + actionButton.isHidden = order.actionTitle == nil + actionButton.isEnabled = order.actionTitle != nil && order.primaryAction != "blocked" + actionButton.backgroundColor = actionButton.isEnabled ? DroneDockStyle.primary : DroneDockStyle.secondary + actionButton.accessibilityIdentifier = "drone.home.order.\(order.orderID).primary" + let materialTitle = order.mediaStatusTitle ?? "" + let materialStatus = order.mediaStatus?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "" + footer.isHidden = materialStatus.isEmpty || materialStatus == "none" || materialTitle.isEmpty + applyMaterial(title: materialTitle, symbol: "photo.on.rectangle.angled", tone: .gray) + accessibilityIdentifier = "drone.home.order.\(order.orderID)" + } + + private func applyMaterial(title: String, symbol: String, tone: DroneDockStatusTone) { var configuration = UIButton.Configuration.plain() - configuration.image = UIImage(systemName: order.materialState.systemImageName) + configuration.image = UIImage(systemName: symbol) configuration.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(pointSize: 15) configuration.imagePadding = 6 - configuration.title = order.materialState.title - configuration.baseForegroundColor = DroneDockStyle.color(for: order.materialState.tone) + configuration.title = title + configuration.baseForegroundColor = DroneDockStyle.color(for: tone) configuration.contentInsets = .zero configuration.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { attributes in var attributes = attributes @@ -49,8 +85,7 @@ final class DroneDockCompactOrderCell: UICollectionViewCell { return attributes } materialButton.configuration = configuration - materialButton.accessibilityLabel = "查看素材,\(order.materialState.title)" - accessibilityIdentifier = "drone.home.\(order.id)" + materialButton.accessibilityLabel = "查看素材,\(title)" } override func prepareForReuse() { @@ -66,6 +101,8 @@ final class DroneDockCompactOrderCell: UICollectionViewCell { let titleRow = UIStackView(arrangedSubviews: [customerLabel, statusLabel]) titleRow.alignment = .center titleRow.spacing = 8 + orderNumberLabel.isHidden = true + orderNumberLabel.numberOfLines = 0 let labels = UIStackView(arrangedSubviews: [packageLabel, countsLabel]) labels.axis = .vertical labels.spacing = 9 @@ -78,12 +115,18 @@ final class DroneDockCompactOrderCell: UICollectionViewCell { actionButton.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium) actionButton.titleLabel?.adjustsFontSizeToFitWidth = true actionButton.titleLabel?.minimumScaleFactor = 0.8 + actionButton.titleLabel?.textAlignment = .center actionButton.layer.cornerRadius = 8 actionButton.addTarget(self, action: #selector(shootingTapped), for: .touchUpInside) - actionButton.snp.makeConstraints { make in make.width.equalTo(106); make.height.equalTo(42) } + actionButton.snp.makeConstraints { make in + make.width.equalTo(106).priority(999) + make.height.equalTo(42) + } let body = UIStackView(arrangedSubviews: [labels, actionButton]) body.spacing = 10 body.alignment = .center + // 让内容行紧贴文字;按钮的固有高度仍可撑高整行,避免自适应高度的舍入余量在两行间游移。 + body.snp.makeConstraints { make in make.height.equalTo(labels).priority(249) } let divider = UIView() divider.backgroundColor = DroneDockStyle.border @@ -106,7 +149,7 @@ final class DroneDockCompactOrderCell: UICollectionViewCell { make.trailing.lessThanOrEqualTo(viewButton.snp.leading).offset(-8) } viewButton.snp.makeConstraints { make in make.centerY.equalTo(materialButton); make.trailing.equalToSuperview() } - let stack = UIStackView(arrangedSubviews: [titleRow, body, footer]) + let stack = UIStackView(arrangedSubviews: [titleRow, orderNumberLabel, body, footer]) stack.axis = .vertical stack.spacing = 12 contentView.addSubview(stack) diff --git a/suixinkan/UI/DroneDock/DroneDockHomeViewController.swift b/suixinkan/UI/DroneDock/DroneDockHomeViewController.swift index 6823b02..c02d43b 100644 --- a/suixinkan/UI/DroneDock/DroneDockHomeViewController.swift +++ b/suixinkan/UI/DroneDock/DroneDockHomeViewController.swift @@ -11,10 +11,10 @@ final class DroneDockHomeViewController: BaseViewController { private var devicePage = 0 private let pageControl = UIPageControl() - /// 首页固定分区;设备与订单的数据结构以实际联调结果为准。 + /// 首页按当前身份、设备、订单与统计展示服务端快照。 private enum Section: Int, CaseIterable { case context, devices, orders, statistics } /// 稳定身份确保刷新使用 Diffable 更新。 - private enum Item: Hashable { case context, devices, device(Int), orders, statistics } + private enum Item: Hashable { case context, devices, device(Int), orders, order(Int), statistics } private lazy var collectionView = UICollectionView(frame: .zero, collectionViewLayout: makeLayout()) private var dataSource: UICollectionViewDiffableDataSource! @@ -56,6 +56,7 @@ final class DroneDockHomeViewController: BaseViewController { collectionView.accessibilityIdentifier = "drone.home.remote.list" collectionView.register(DroneDockHomeContentCell.self, forCellWithReuseIdentifier: "content") collectionView.register(DroneDockDeviceCell.self, forCellWithReuseIdentifier: "device") + collectionView.register(DroneDockCompactOrderCell.self, forCellWithReuseIdentifier: "order") collectionView.register(DroneDockHomeHeader.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header") collectionView.register(DroneDockHomePageFooter.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, @@ -97,12 +98,17 @@ final class DroneDockHomeViewController: BaseViewController { isRefreshing = true refreshTask = Task { @MainActor [weak self] in guard let self else { return } + let isInitialLoad = self.viewModel.response == nil self.applySnapshot(animated: false) await self.viewModel.refresh() guard !Task.isCancelled else { return } self.isRefreshing = false self.collectionView.refreshControl?.endRefreshing() self.applySnapshot(animated: true) { [weak self] in + if isInitialLoad, let self { + self.collectionView.layoutIfNeeded() + self.collectionView.setContentOffset(CGPoint(x: 0, y: -self.collectionView.adjustedContentInset.top), animated: false) + } #if DEBUG Task { @MainActor [weak self] in await self?.captureHomeIfRequested() } #endif @@ -120,6 +126,17 @@ final class DroneDockHomeViewController: BaseViewController { } return cell } + if case .order(let id) = item { + let cell = collection.dequeueReusableCell(withReuseIdentifier: "order", for: path) as! DroneDockCompactOrderCell + if let order = self.viewModel.response?.orders.first(where: { $0.orderID == id }) { + cell.apply(homeOrder: order) + cell.onShootingTap = { [weak self] in + self?.showAlert(title: order.actionTitle ?? "拍摄订单", message: "拍摄流程暂未接入,请稍后再试") + } + cell.onMaterialsTap = { [weak self] in self?.showUnavailable("订单素材") } + } + return cell + } let cell = collection.dequeueReusableCell(withReuseIdentifier: "content", for: path) as! DroneDockHomeContentCell switch item { case .context: @@ -130,7 +147,7 @@ final class DroneDockHomeViewController: BaseViewController { cell.applyStatistics(self.viewModel.response?.today) case .devices, .orders: self.applyDataState(to: cell, isDevice: item == .devices) - case .device: break + case .device, .order: break } return cell } @@ -158,20 +175,13 @@ final class DroneDockHomeViewController: BaseViewController { cell.applyMessage(symbol: "wifi.exclamationmark", title: "首页加载失败", detail: error + ",请下拉重试") return } - guard let response = viewModel.response else { + guard viewModel.response != nil else { cell.applyMessage(symbol: "arrow.triangle.2.circlepath", title: "正在加载", detail: "正在获取最新数据") return } - let recordCount = isDevice ? response.airports.count : response.orders.count - if recordCount == 0 { - cell.applyMessage(symbol: isDevice ? "airplane" : "doc.text", - title: isDevice ? "暂无无人机" : "暂无待拍摄订单", - detail: isDevice ? "当前景区暂无设备数据" : "当前景区暂无拍摄订单数据") - } else { - // 订单仍等待真实非空样例,不影响已接入的设备卡片。 - cell.applyMessage(symbol: "exclamationmark.circle", title: "订单信息暂不可用", - detail: "已获取 \(recordCount) 条数据,暂时无法展示详情") - } + cell.applyMessage(symbol: isDevice ? "airplane" : "doc.text", + title: isDevice ? "暂无无人机" : "暂无待拍摄订单", + detail: isDevice ? "当前景区暂无设备数据" : "当前景区暂无拍摄订单数据") } private func applySnapshot(animated: Bool, completion: (() -> Void)? = nil) { @@ -181,7 +191,8 @@ final class DroneDockHomeViewController: BaseViewController { snapshot.appendItems([.context], toSection: .context) let airports = viewModel.response?.airports ?? [] snapshot.appendItems(airports.isEmpty ? [.devices] : airports.map { .device($0.id) }, toSection: .devices) - snapshot.appendItems([.orders], toSection: .orders) + let orders = viewModel.response?.orders ?? [] + snapshot.appendItems(orders.isEmpty ? [.orders] : orders.map { .order($0.orderID) }, toSection: .orders) snapshot.appendItems([.statistics], toSection: .statistics) let old = Set(dataSource.snapshot().itemIdentifiers) let previousDeviceCount = old.filter { if case .device = $0 { return true }; return false }.count @@ -207,6 +218,7 @@ final class DroneDockHomeViewController: BaseViewController { let group = NSCollectionLayoutGroup.horizontal(layoutSize: NSCollectionLayoutSize(widthDimension: width, heightDimension: height), subitems: [item]) let layout = NSCollectionLayoutSection(group: group) layout.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 16, bottom: section == .statistics ? 24 : 0, trailing: 16) + if section == .orders { layout.interGroupSpacing = 12 } if multipleDevices { layout.interGroupSpacing = 12 layout.orthogonalScrollingBehavior = .groupPaging diff --git a/suixinkanTests/DroneDockHomeAPITests.swift b/suixinkanTests/DroneDockHomeAPITests.swift index 37aff32..6f45a96 100644 --- a/suixinkanTests/DroneDockHomeAPITests.swift +++ b/suixinkanTests/DroneDockHomeAPITests.swift @@ -2,7 +2,7 @@ import Foundation import XCTest @testable import suixinkan -/// 使用真机实测的首页结构验证接口参数、统计精度与未知列表的保留规则。 +/// 使用实测的首页结构验证接口参数、统计精度及设备和订单的解析规则。 @MainActor final class DroneDockHomeAPITests: XCTestCase { /// 首页仅发起一次带当前景区、门店和登录凭证的 GET,真实空数据不替换为演示数据。 @@ -73,10 +73,14 @@ final class DroneDockHomeAPITests: XCTestCase { } } - /// 设备按已验证字段读取,订单继续保留未知对象,不猜测订单契约。 - func testVerifiedAirportAndUnverifiedOrderArePreserved() throws { - let payload = #"{"scenic_id":128,"airports":[{"id":58,"name":"测试机巢M4D","sn_number":"test-airport-sn","scenic_area_id":128,"online_status":1,"work_status":1,"work_status_label":"空闲","is_receive_order":1,"task_type":null,"metrics":[{"key":"battery","label":"电池电量","raw":null,"value":"—"}]}],"orders":[{"custom_order_key":"B","extra":false}],"today":null}"# - let response = try JSONDecoder().decode(DroneDockHomeResponse.self, from: Data(payload.utf8)) + /// 首页请求同时解析已验证的设备和订单字段,不依赖额外订单详情请求。 + func testHomeDecodesVerifiedAirportAndOrderInOneRequest() async throws { + let payload = #"{"scenic_id":128,"airports":[{"id":58,"name":"测试机巢M4D","sn_number":"test-airport-sn","scenic_area_id":128,"online_status":1,"work_status":1,"work_status_label":"空闲","is_receive_order":1,"task_type":null,"metrics":[{"key":"battery","label":"电池电量","raw":null,"value":"—"}]}],"orders":[{"order_id":101,"order_number":"TEST-ORDER-001","tourist_label":"游客 138****0000","package_name":"测试单次套餐","status_label":"待拍摄","shot_total":1,"shot_used":0,"shot_remain":1,"primary_action":"start_shoot","primary_action_label":"开始拍摄"}],"today":null}"# + let session = MockURLSession(responses: [envelope(payload)]) + let api = DroneDockAPI(client: APIClient(environment: .testing, session: session)) + let response = try await api.home(scenicID: 128, storeID: 37) + XCTAssertEqual(session.requests.count, 1) + XCTAssertEqual(session.requests.first?.httpMethod, "GET") XCTAssertEqual(response.airports.count, 1) XCTAssertEqual(response.orders.count, 1) XCTAssertEqual(response.airports[0].id, 58) @@ -85,7 +89,13 @@ final class DroneDockHomeAPITests: XCTestCase { XCTAssertEqual(response.airports[0].statusTitle, "空闲") XCTAssertEqual(response.airports[0].metricText(for: "battery"), "—") XCTAssertNil(response.airports[0].batteryProgress) - XCTAssertEqual(Set(response.orders[0].fields.keys), ["custom_order_key", "extra"]) + XCTAssertEqual(response.orders[0].orderID, 101) + XCTAssertEqual(response.orders[0].orderNumberText, "TEST-ORDER-001") + XCTAssertEqual(response.orders[0].touristTitle, "游客 138****0000") + XCTAssertEqual(response.orders[0].packageTitle, "测试单次套餐") + XCTAssertEqual(response.orders[0].statusTitle, "待拍摄") + XCTAssertEqual(response.orders[0].progressTitle, "已拍摄 0/1 次,剩余 1 次") + XCTAssertEqual(response.orders[0].actionTitle, "开始拍摄") } /// 无效统计值明确报解析错误,避免错误数据悄悄显示成零。 diff --git a/suixinkanTests/DroneDockHomeOrderTests.swift b/suixinkanTests/DroneDockHomeOrderTests.swift new file mode 100644 index 0000000..36909b2 --- /dev/null +++ b/suixinkanTests/DroneDockHomeOrderTests.swift @@ -0,0 +1,134 @@ +import Foundation +import XCTest +@testable import suixinkan + +/// 验证首页订单的真实字段结构、稳定身份及未知展示值,不访问后端或执行拍摄。 +final class DroneDockHomeOrderTests: XCTestCase { + /// 使用匿名化的完整响应形状,保留游客、套餐、次数及服务端动作字段。 + func testObservedOrderShapePreservesServerDisplayFields() throws { + let order = try decodeOrder(#""" + { + "order_id":101,"order_number":"001TESTORDER", + "tourist_label":"游客 138****0000","tourist_phone_mask":"138****0000", + "package_name":"单次航拍 · 含 1 次拍摄","status_label":"待拍摄", + "shot_total":1,"shot_used":0,"shot_remain":1, + "progress_text":"已拍摄 0/1 次,剩余 1 次", + "media_status":"none","media_status_label":"", + "primary_action":"start_shoot","primary_action_label":"开始拍摄","user_id":501 + } + """#) + + XCTAssertEqual(order.id, 101) + XCTAssertEqual(order.orderID, 101) + XCTAssertEqual(order.orderNumberText, "001TESTORDER") + XCTAssertEqual(order.touristTitle, "游客 138****0000") + XCTAssertEqual(order.touristPhoneMask, "138****0000") + XCTAssertEqual(order.packageTitle, "单次航拍 · 含 1 次拍摄") + XCTAssertEqual(order.statusTitle, "待拍摄") + XCTAssertEqual(order.shotTotal, 1) + XCTAssertEqual(order.shotUsed, 0) + XCTAssertEqual(order.shotRemain, 1) + XCTAssertEqual(order.progressTitle, "已拍摄 0/1 次,剩余 1 次") + XCTAssertEqual(order.mediaStatus, "none") + XCTAssertNil(order.mediaStatusTitle) + XCTAssertEqual(order.primaryAction, "start_shoot") + XCTAssertEqual(order.actionTitle, "开始拍摄") + XCTAssertEqual(order.userID, 501) + } + + /// 缺失、null 与占位文案显示未知,不伪造游客、套餐、待拍摄状态或零次数。 + func testMissingAndNullFieldsStayUnknown() throws { + for payload in [#"{"order_id":101}"#, + #"{"order_id":101,"order_number":null,"tourist_label":" ","tourist_phone_mask":null,"package_name":"--","status_label":null,"shot_total":null,"shot_used":null,"shot_remain":null,"progress_text":"—","media_status_label":" ","primary_action":null,"primary_action_label":"开始拍摄","user_id":null}"#] { + let order = try decodeOrder(payload) + XCTAssertEqual(order.orderNumberText, "—") + XCTAssertEqual(order.touristTitle, "游客信息待确认") + XCTAssertEqual(order.packageTitle, "套餐信息待确认") + XCTAssertEqual(order.statusTitle, "状态待确认") + XCTAssertNil(order.shotTotal) + XCTAssertNil(order.shotUsed) + XCTAssertNil(order.shotRemain) + XCTAssertEqual(order.progressTitle, "已拍摄 —/— 次,剩余 — 次") + XCTAssertNil(order.actionTitle) + XCTAssertNil(order.mediaStatusTitle) + XCTAssertNil(order.userID) + } + } + + /// 数字字符串与数字等价,真实零次不会被替换为未知。 + func testNumericStringsAndZeroCountsArePreserved() throws { + let order = try decodeOrder(#"{"order_id":"101","shot_total":"0","shot_used":0,"shot_remain":"0","user_id":"501"}"#) + XCTAssertEqual(order.orderID, 101) + XCTAssertEqual(order.userID, 501) + XCTAssertEqual(order.shotTotal, 0) + XCTAssertEqual(order.shotUsed, 0) + XCTAssertEqual(order.shotRemain, 0) + XCTAssertEqual(order.progressTitle, "已拍摄 0/0 次,剩余 0 次") + } + + /// 不根据总次数计算缺失的剩余次数,也不擅自修正后端已使用超出总量的情况。 + func testProgressDoesNotInferOrRecalculateQuota() throws { + let incomplete = try decodeOrder(#"{"order_id":101,"shot_total":5,"shot_used":2}"#) + XCTAssertEqual(incomplete.progressTitle, "已拍摄 2/5 次,剩余 — 次") + + let overQuota = try decodeOrder(#"{"order_id":101,"shot_total":5,"shot_used":6,"shot_remain":0}"#) + XCTAssertEqual(overQuota.progressTitle, "已拍摄 6/5 次,剩余 0 次") + + let serverText = try decodeOrder(#"{"order_id":101,"shot_total":5,"shot_used":2,"progress_text":" 服务端进度说明 "}"#) + XCTAssertEqual(serverText.progressTitle, "服务端进度说明") + } + + /// 游客展示先取服务端名称,名称未知时才使用服务端已脱敏手机号。 + func testTouristLabelTakesPrecedenceOverMaskedPhone() throws { + let named = try decodeOrder(#"{"order_id":101,"tourist_label":"测试游客","tourist_phone_mask":"138****0000"}"#) + XCTAssertEqual(named.touristTitle, "测试游客") + let masked = try decodeOrder(#"{"order_id":101,"tourist_label":"—","tourist_phone_mask":"138****0000"}"#) + XCTAssertEqual(masked.touristTitle, "游客 138****0000") + } + + /// 新状态和动作保持后端文案,缺少动作标识或文案时不合成“开始拍摄”。 + func testUnknownStatusAndActionRemainServerSupplied() throws { + let future = try decodeOrder(#"{"order_id":101,"status_label":"人工处理中","media_status":"future","media_status_label":"素材校验中","primary_action":"future_action","primary_action_label":"查看进度","extra":{"value":true}}"#) + XCTAssertEqual(future.statusTitle, "人工处理中") + XCTAssertEqual(future.mediaStatus, "future") + XCTAssertEqual(future.mediaStatusTitle, "素材校验中") + XCTAssertEqual(future.primaryAction, "future_action") + XCTAssertEqual(future.actionTitle, "查看进度") + for suffix in [#""primary_action":"start_shoot""#, + #""primary_action_label":"开始拍摄""#, + #""primary_action":"start_shoot","primary_action_label":"—""#, + #""primary_action":" ","primary_action_label":"开始拍摄""#] { + let order = try decodeOrder("{\"order_id\":101,\(suffix)}") + XCTAssertNil(order.actionTitle) + } + } + + /// 无效身份与重复身份会破坏 Diffable 列表,解析阶段拒绝这些响应。 + func testInvalidAndDuplicateOrderIdentitiesAreRejected() throws { + for payload in ["{}", "null", "[]", "false", #"{"order_id":0}"#, + #"{"order_id":-1}"#, #"{"order_id":1.5}"#, + #"{"order_id":true}"#, #"{"order_id":"invalid"}"#] { + XCTAssertThrowsError(try decodeOrder(payload), payload) + } + let duplicate = #"{"scenic_id":128,"airports":[],"orders":[{"order_id":101},{"order_id":"101"}]}"# + XCTAssertThrowsError(try JSONDecoder().decode(DroneDockHomeResponse.self, from: Data(duplicate.utf8))) + let distinct = #"{"scenic_id":128,"airports":[],"orders":[{"order_id":102},{"order_id":101}]}"# + let response = try JSONDecoder().decode(DroneDockHomeResponse.self, from: Data(distinct.utf8)) + XCTAssertEqual(response.orders.map(\.orderID), [102, 101]) + } + + /// 非整数、负数和非法类型不悄悄转换为有效拍摄额度。 + func testMalformedCountsAndDisplayTypesAreRejected() { + for field in ["shot_total", "shot_used", "shot_remain"] { + for value in ["-1", "1.5", "true", "\"invalid\"", "{}"] { + XCTAssertThrowsError(try decodeOrder("{\"order_id\":101,\"\(field)\":\(value)}")) + } + } + XCTAssertThrowsError(try decodeOrder(#"{"order_id":101,"order_number":1001}"#)) + } + + /// 将独立匿名订单载荷解码为首页展示模型。 + private func decodeOrder(_ payload: String) throws -> DroneDockHomeOrder { + try JSONDecoder().decode(DroneDockHomeOrder.self, from: Data(payload.utf8)) + } +} diff --git a/suixinkanTests/DroneDockRemoteHomeViewTests.swift b/suixinkanTests/DroneDockRemoteHomeViewTests.swift index 55ecc04..05591c7 100644 --- a/suixinkanTests/DroneDockRemoteHomeViewTests.swift +++ b/suixinkanTests/DroneDockRemoteHomeViewTests.swift @@ -2,7 +2,7 @@ import UIKit import XCTest @testable import suixinkan -/// 在真机窗口验证正式首页的真实空态、错误显示和演示流程隔离,网络全部使用替身。 +/// 在测试窗口验证正式首页的真实数据、空态、错误显示和演示流程隔离,网络全部使用替身。 @MainActor final class DroneDockRemoteHomeViewTests: XCTestCase { private weak var previousKeyWindow: UIWindow? @@ -186,6 +186,205 @@ final class DroneDockRemoteHomeViewTests: XCTestCase { capture(window, named: "机巢真实首页-多设备横向卡片") } + /// 首次返回设备和多条订单时仍停留页首,避免 Diffable 将页面锚定到新增订单之后。 + func testInitialHomeWithEightOrdersKeepsScenicContextAndDeviceVisible() async throws { + var envelope = try XCTUnwrap(JSONSerialization.jsonObject(with: populatedEnvelope) as? [String: Any]) + var data = try XCTUnwrap(envelope["data"] as? [String: Any]) + data["orders"] = (701...708).map { orderRecord(id: $0) } + envelope["data"] = data + let (controller, session) = makeController(responses: [try JSONSerialization.data(withJSONObject: envelope)]) + let window = makeWindow(root: controller) + defer { close(window) } + let collection = try XCTUnwrap(find(in: controller.view, identifier: "drone.home.remote.list") as? UICollectionView) + + try await settle(window: window) { + collection.numberOfItems(inSection: 2) == 8 + && !collection.hasUncommittedUpdates + && abs(collection.contentOffset.y + collection.adjustedContentInset.top) < 1 + && self.find(in: controller.view, identifier: "drone.device.58") != nil + } + + XCTAssertEqual(collection.contentOffset.y, -collection.adjustedContentInset.top, accuracy: 1) + XCTAssertEqual(collection.numberOfItems(inSection: 2), 8) + let visibleFrame = collection.bounds.inset(by: collection.adjustedContentInset) + let contextFrame = try XCTUnwrap(collection.collectionViewLayout.layoutAttributesForItem(at: IndexPath(item: 0, section: 0))).frame + let deviceFrame = try XCTUnwrap(collection.collectionViewLayout.layoutAttributesForItem(at: IndexPath(item: 0, section: 1))).frame + XCTAssertTrue(visibleFrame.contains(contextFrame), "首次加载后景区信息应完整位于可见区域") + XCTAssertTrue(visibleFrame.contains(deviceFrame), "首次加载后设备卡片应完整位于可见区域") + XCTAssertTrue(visibleTexts(in: controller.view).contains("测试景区 · 测试工作人员")) + XCTAssertTrue(visibleTexts(in: controller.view).contains("测试机巢M4D")) + XCTAssertEqual(session.requests.count, 1) + assertOnlyReadHomeRequests(session) + } + + /// 首页按服务端顺序呈现每条订单,字段来自响应,不替换成演示游客或套餐。 + func testOrdersDisplayServerFieldsAndPreserveServerOrder() async throws { + let orders = [orderRecord(id: 703), orderRecord(id: 701), orderRecord(id: 702)] + let (controller, session) = makeController(responses: [try orderEnvelope(orders)]) + let window = makeWindow(root: controller) + defer { close(window) } + let collection = try XCTUnwrap(find(in: controller.view, identifier: "drone.home.remote.list") as? UICollectionView) + + try await settle(window: window) { collection.numberOfItems(inSection: 2) == 3 } + for (index, id) in [703, 701, 702].enumerated() { + let card = try await orderCard(at: index, id: id, in: collection, window: window) + let texts = visibleTexts(in: card) + XCTAssertTrue(texts.contains("游客 130****0001")) + XCTAssertTrue(texts.contains("订单号 TEST-ORDER-\(id)")) + XCTAssertTrue(texts.contains("测试单次航拍 · 含 1 次拍摄")) + XCTAssertTrue(texts.contains("待拍摄")) + XCTAssertTrue(texts.contains("已拍摄 0/1 次,剩余 1 次")) + XCTAssertTrue(texts.contains("开始拍摄")) + XCTAssertFalse(texts.contains("查看素材 ›")) + assertUnambiguousVisibleLayout(in: card) + } + XCTAssertFalse(visibleTexts(in: controller.view).contains("订单信息暂不可用")) + XCTAssertEqual(session.requests.count, 1) + assertOnlyReadHomeRequests(session) + capture(window, named: "机巢真实首页-订单游客套餐状态与次数") + } + + /// 同一订单刷新会更新剩余次数与按钮状态,服务端移除的订单和空列表不会残留旧卡片。 + func testOrderRefreshUpdatesExistingCardAndRemovesDeletedOrders() async throws { + var completed = orderRecord(id: 701) + completed["status_label"] = "已完成" + completed["shot_used"] = 1 + completed["shot_remain"] = 0 + completed["progress_text"] = "已拍摄 1/1 次,剩余 0 次" + completed["primary_action"] = "blocked" + completed["primary_action_label"] = "拍摄次数已用完" + let responses = try [ + orderEnvelope([orderRecord(id: 701), orderRecord(id: 702)]), + orderEnvelope([completed]), orderEnvelope([]) + ] + let (controller, session) = makeController(responses: responses) + let window = makeWindow(root: controller) + defer { close(window) } + let collection = try XCTUnwrap(find(in: controller.view, identifier: "drone.home.remote.list") as? UICollectionView) + try await settle(window: window) { collection.numberOfItems(inSection: 2) == 2 } + _ = try await orderCard(at: 0, id: 701, in: collection, window: window) + + let refresh = try XCTUnwrap(collection.refreshControl) + refresh.sendActions(for: .valueChanged) + try await settle(window: window) { + collection.numberOfItems(inSection: 2) == 1 + && self.visibleTexts(in: controller.view).contains("已拍摄 1/1 次,剩余 0 次") + } + let card = try await orderCard(at: 0, id: 701, in: collection, window: window) + XCTAssertTrue(visibleTexts(in: card).contains("已完成")) + XCTAssertFalse(visibleTexts(in: card).contains("已拍摄 0/1 次,剩余 1 次")) + let button = try XCTUnwrap(find(in: card, identifier: "drone.home.order.701.primary") as? UIButton) + XCTAssertFalse(button.isEnabled) + XCTAssertEqual(visibleOrderCardIdentifiers(in: collection), ["drone.home.order.701"]) + XCTAssertEqual(controller.viewModel.response?.orders.map(\.orderID), [701]) + assertUnambiguousVisibleLayout(in: card) + + refresh.sendActions(for: .valueChanged) + try await settle(window: window) { self.visibleTexts(in: controller.view).contains("暂无待拍摄订单") } + XCTAssertEqual(collection.numberOfItems(inSection: 2), 1) + XCTAssertTrue(visibleOrderCardIdentifiers(in: collection).isEmpty) + XCTAssertTrue(controller.viewModel.response?.orders.isEmpty == true) + XCTAssertEqual(session.requests.count, 3) + assertOnlyReadHomeRequests(session) + } + + /// 真实订单的拍摄按钮只说明待接入流程,不进入演示任务或发送设备控制请求。 + func testOrderShootingActionOnlyShowsIntegrationNotice() async throws { + let (controller, session) = makeController(responses: [try orderEnvelope([orderRecord(id: 701)])]) + let window = makeWindow(root: controller) + defer { close(window) } + let collection = try XCTUnwrap(find(in: controller.view, identifier: "drone.home.remote.list") as? UICollectionView) + try await settle(window: window) { self.find(in: controller.view, identifier: "drone.home.order.701") != nil } + let card = try await orderCard(at: 0, id: 701, in: collection, window: window) + let button = try XCTUnwrap(find(in: card, identifier: "drone.home.order.701.primary") as? UIButton) + XCTAssertTrue(button.isEnabled) + button.sendActions(for: .touchUpInside) + + try await settle(window: window) { controller.presentedViewController is UIAlertController } + let alert = try XCTUnwrap(controller.presentedViewController as? UIAlertController) + XCTAssertEqual(alert.title, "开始拍摄") + XCTAssertEqual(alert.message, "拍摄流程暂未接入,请稍后再试") + XCTAssertEqual(controller.navigationController?.viewControllers.count, 1) + XCTAssertEqual(session.requests.count, 1) + assertOnlyReadHomeRequests(session) + } + + /// 刷新后的缺失信息清除旧游客、套餐、次数和操作,不将未知拍摄次数伪装为零。 + func testMissingOrderFieldsClearPreviousDisplayWithoutInventingCounts() async throws { + let minimal: [String: Any] = ["order_id": 701, "order_number": "TEST-ORDER-701"] + let (controller, session) = makeController(responses: try [ + orderEnvelope([orderRecord(id: 701)]), orderEnvelope([minimal]) + ]) + let window = makeWindow(root: controller) + defer { close(window) } + let collection = try XCTUnwrap(find(in: controller.view, identifier: "drone.home.remote.list") as? UICollectionView) + try await settle(window: window) { self.find(in: controller.view, identifier: "drone.home.order.701") != nil } + _ = try await orderCard(at: 0, id: 701, in: collection, window: window) + try XCTUnwrap(collection.refreshControl).sendActions(for: .valueChanged) + try await settle(window: window) { self.visibleTexts(in: controller.view).contains("游客信息待确认") } + + let card = try await orderCard(at: 0, id: 701, in: collection, window: window) + let texts = visibleTexts(in: card) + XCTAssertTrue(texts.contains("套餐信息待确认")) + XCTAssertTrue(texts.contains("状态待确认")) + XCTAssertTrue(texts.contains { $0.contains("—") }) + XCTAssertFalse(texts.contains("游客 130****0001")) + XCTAssertFalse(texts.contains("测试单次航拍 · 含 1 次拍摄")) + XCTAssertFalse(texts.contains { $0.contains("0/1") || $0.contains("0/0") }) + if let button = find(in: card, identifier: "drone.home.order.701.primary") { + XCTAssertTrue(isHiddenByAncestor(button)) + } + assertUnambiguousVisibleLayout(in: card) + XCTAssertEqual(session.requests.count, 2) + assertOnlyReadHomeRequests(session) + } + + /// 与实际 home 订单字段一致的匿名夹具,避免将游客或业务订单信息写入仓库。 + private func orderRecord(id: Int) -> [String: Any] { + [ + "order_id": id, "order_number": "TEST-ORDER-\(id)", "user_id": 901, + "tourist_label": "游客 130****0001", "tourist_phone_mask": "130****0001", + "package_name": "测试单次航拍 · 含 1 次拍摄", "status_label": "待拍摄", + "shot_total": 1, "shot_used": 0, "shot_remain": 1, + "progress_text": "已拍摄 0/1 次,剩余 1 次", "media_status": "none", + "media_status_label": "", "primary_action": "start_shoot", "primary_action_label": "开始拍摄" + ] + } + + /// 为订单展示单独构造成功响应,设备为空以便在测试窗口观察卡片。 + private func orderEnvelope(_ orders: [[String: Any]]) throws -> Data { + var envelope = try XCTUnwrap(JSONSerialization.jsonObject(with: emptyEnvelope) as? [String: Any]) + var data = try XCTUnwrap(envelope["data"] as? [String: Any]) + data["orders"] = orders + envelope["data"] = data + return try JSONSerialization.data(withJSONObject: envelope) + } + + /// 滚动到指定服务端顺序的订单,等待实际复用卡片出现再检查内容。 + private func orderCard(at index: Int, id: Int, in collection: UICollectionView, window: UIWindow) async throws -> UICollectionViewCell { + let path = IndexPath(item: index, section: 2) + collection.scrollToItem(at: path, at: .centeredVertically, animated: false) + try await settle(window: window) { + collection.cellForItem(at: path)?.accessibilityIdentifier == "drone.home.order.\(id)" + } + return try XCTUnwrap(collection.cellForItem(at: path)) + } + + /// 只读取当前可见索引对应的订单卡,排除集合视图复用池中暂存的已删除单元格。 + private func visibleOrderCardIdentifiers(in collection: UICollectionView) -> [String] { + collection.indexPathsForVisibleItems.filter { $0.section == 2 }.sorted().compactMap { path in + guard let cell = collection.cellForItem(at: path), !isHiddenByAncestor(cell), + let identifier = cell.accessibilityIdentifier, identifier.hasPrefix("drone.home.order.") else { return nil } + return identifier + } + } + + /// 检查实际展示的卡片内容约束,隐藏素材栏和按钮不参与可见布局检查。 + private func assertUnambiguousVisibleLayout(in card: UIView, file: StaticString = #filePath, line: UInt = #line) { + let ambiguous = allViews(in: card).filter { !isHiddenByAncestor($0) && $0.hasAmbiguousLayout } + XCTAssertTrue(ambiguous.isEmpty, "订单卡片存在布局歧义:\(ambiguous.map { String(describing: type(of: $0)) })", file: file, line: line) + } + /// 服务端确定的六项读数键,按标识查找而不依赖数组排序。 private var metricKeys: [String] { ["battery", "env_temp", "wind_speed", "rainfall", "signal", "satellite"] } @@ -232,12 +431,12 @@ final class DroneDockRemoteHomeViewTests: XCTestCase { return values } - /// 与实际控制台响应结构一致的成功空数据,不依赖当前真机账户。 + /// 与实际控制台响应结构一致的成功空数据,不依赖当前登录账户。 private var emptyEnvelope: Data { Data(#"{"code":100000,"msg":"success","data":{"scenic_id":128,"airports":[],"orders":[],"today":{"finished_shoot":0,"order_amount":0,"order_count":0}}}"#.utf8) } - /// 创建只接替身网络的正式首页,不读取或修改真机登录状态。 + /// 创建只接替身网络的正式首页,不读取或修改当前登录状态。 private func makeController(responses: [Data]) -> (DroneDockHomeViewController, MockURLSession) { let context = DroneDockHomeContext( userID: "remote-home-ui-test", accountType: "store_user", scenicID: 128, @@ -253,7 +452,7 @@ final class DroneDockRemoteHomeViewTests: XCTestCase { }), session) } - /// 创建临时真机窗口,结束后恢复原窗口。 + /// 创建临时测试窗口,结束后恢复原窗口。 private func makeWindow(root: UIViewController) -> UIWindow { let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene } let scene = scenes.first { $0.activationState == .foregroundActive } ?? scenes.first @@ -322,7 +521,7 @@ final class DroneDockRemoteHomeViewTests: XCTestCase { XCTAssertTrue(session.requests.allSatisfy { $0.httpMethod == "GET" && $0.url?.path == "/api/app/airport/home" }, file: file, line: line) } - /// 保存测试窗口截图到真机 xcresult,便于核对空态样式。 + /// 保存测试窗口截图到 xcresult,便于核对页面样式。 private func capture(_ window: UIWindow, named name: String) { let image = UIGraphicsImageRenderer(bounds: window.bounds).image { _ in window.drawHierarchy(in: window.bounds, afterScreenUpdates: true)