Files
suixinkan_uikit/suixinkanTests/DroneMaterialsFooterLayoutTests.swift
lujiuyin b95b251de1 feat: 完善机巢模拟调试与素材交付交互
增加禁飞期间的设备指令拦截及本地模拟拍摄流程;适配订单素材库和景区空境库,完善素材筛选、预览与下载;订单交付入口改为方式选择弹窗并复用云端上传。补充单元测试、接口记录和模拟器截图。
2026-10-30 09:59:11 +08:00

86 lines
5.1 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import UIKit
import XCTest
@testable import suixinkan
/// 验证演示下载底栏的状态组合在小屏与标准宽度下不裁切、不覆盖操作。
@MainActor
final class DroneMaterialsFooterLayoutTests: XCTestCase {
/// 选择、下载、暂停、失败、完成与权限状态在不同宽度下保持标题、说明和操作顺序。
func testFooterStatesFitCompactAndRegularWidths() throws {
for width in [375.0, 402.0] {
let footer = DroneMaterialsFooterView()
for state in 0..<6 {
apply(state, to: footer)
layout(footer, width: width)
let primary = try XCTUnwrap(allViews(footer).first {
$0.accessibilityIdentifier == "footer.primary"
} as? UIButton)
XCTAssertGreaterThanOrEqual(primary.bounds.height, 44)
XCTAssertLessThanOrEqual(primary.convert(primary.bounds, to: footer).maxY, footer.bounds.maxY + 0.5)
for view in allViews(footer).filter({ !$0.isHidden && ($0.accessibilityIdentifier?.hasPrefix("drone.materials.footer.") == true || $0 is UIButton) && isVisible($0, within: footer) }) {
let rect = view.convert(view.bounds, to: footer)
XCTAssertGreaterThanOrEqual(rect.minX, -0.5)
XCTAssertLessThanOrEqual(rect.maxX, width + 0.5)
XCTAssertGreaterThan(view.bounds.height, 0)
}
let title = try XCTUnwrap(allViews(footer).first { $0.accessibilityIdentifier == "drone.materials.footer.title" })
let trailing = try XCTUnwrap(allViews(footer).first { $0.accessibilityIdentifier == "drone.materials.footer.trailing" })
if !trailing.isHidden {
XCTAssertLessThanOrEqual(title.convert(title.bounds, to: footer).maxX,
trailing.convert(trailing.bounds, to: footer).minX)
}
}
}
}
/// 完成后回到选择状态不残留结果图标、交付按钮或旧进度;演示提示仍明确不写相册。
func testCompletedFooterResetsCleanlyToSelection() throws {
let footer = DroneMaterialsFooterView()
apply(4, to: footer)
layout(footer, width: 375)
let delivery = try XCTUnwrap(allViews(footer).first { $0.accessibilityIdentifier == "drone.materials.completedDelivery" } as? UIButton)
XCTAssertFalse(delivery.isHidden)
XCTAssertEqual(delivery.layer.borderWidth, 1)
let detail = try XCTUnwrap(allViews(footer).first { $0.accessibilityIdentifier == "drone.materials.footer.detail" } as? UILabel)
XCTAssertTrue(detail.text?.contains("未写入系统相册") == true)
apply(0, to: footer)
layout(footer, width: 375)
XCTAssertTrue(delivery.isHidden)
XCTAssertEqual(delivery.layer.borderWidth, 0)
XCTAssertTrue(detail.isHidden)
let icon = try XCTUnwrap(allViews(footer).first { $0.accessibilityIdentifier == "drone.materials.footer.resultIcon" })
XCTAssertTrue(icon.isHidden)
}
private func apply(_ state: Int, to footer: DroneMaterialsFooterView) {
let titles = ["已选择2项", "本次下载2项", "下载已暂停", "部分素材下载失败", "本次素材下载完成(演示)", "无法保存到手机相册"]
let details = ["", "请保持本页开启,下载期间不可更改选择", "已完成项会保留;继续时仅处理未完成文件。", "演示成功1项 · 失败1项,已完成的无需重复下载", "2项演示完成,未写入系统相册", "演示相册权限未开启,恢复后请手动继续。"]
let symbols: [String?] = [nil, nil, "pause.circle", "exclamationmark.triangle", "checkmark.circle", "lock"]
footer.apply(title: titles[state], detail: details[state], primaryTitle: state == 3 ? "重试失败素材(1)" : "下载所选素材",
primarySymbol: "arrow.down.to.line", enabled: state != 1, identifier: "footer.primary",
progress: state == 1 || state == 2 ? 0.5 : nil,
secondaryTitle: state == 3 ? "选择其他素材" : state == 4 ? "交付成片" : nil,
tone: state == 4 ? .green : .orange,
trailingText: state == 0 ? "仅可选择已上传素材" : state == 1 || state == 2 ? "已完成1/2项" : nil,
resultSymbol: symbols[state], secondaryOutlined: state == 4)
}
private func layout(_ footer: UIView, width: Double) {
let size = footer.systemLayoutSizeFitting(CGSize(width: width, height: 1),
withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
footer.frame = CGRect(origin: .zero, size: size)
footer.layoutIfNeeded()
}
private func allViews(_ view: UIView) -> [UIView] { [view] + view.subviews.flatMap { allViews($0) } }
private func isVisible(_ view: UIView, within root: UIView) -> Bool {
var ancestor = view.superview
while let current = ancestor, current !== root {
if current.isHidden { return false }
ancestor = current.superview
}
return true
}
}