Redesign nearby transfer and cloud delivery screens
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
import UIKit
|
||||
import XCTest
|
||||
@testable import suixinkan
|
||||
|
||||
/// 两种交付入口共享的摘要与真实本地封面,不访问网络或初始化 RTC。
|
||||
@MainActor
|
||||
final class DroneDockDeliveryDesignTests: XCTestCase {
|
||||
/// 长游客标题随卡片增高,订单仅展示原号码末四位,不挤压或截断标题。
|
||||
func testLongCustomerTitleWrapsAndKeepsRealOrderSuffixVisible() throws {
|
||||
let view = DroneDockDeliveryCustomerView(showsCard: true)
|
||||
let title = "游客 南京牛首山佛顶塔观景平台来自同一旅行团队的亲友共同拍摄成片接收人"
|
||||
view.apply(title: title, orderNumber: " 261105175018 \n")
|
||||
layout(view, width: 320)
|
||||
let name = try label(view, "drone.delivery.customer.title")
|
||||
let order = try label(view, "drone.delivery.customer.order")
|
||||
XCTAssertEqual(name.text, title)
|
||||
XCTAssertEqual(name.numberOfLines, 0)
|
||||
XCTAssertGreaterThan(name.bounds.height, name.font.lineHeight)
|
||||
XCTAssertGreaterThanOrEqual(name.bounds.height + 1, name.sizeThatFits(CGSize(width: name.bounds.width, height: .greatestFiniteMagnitude)).height)
|
||||
XCTAssertEqual(order.text, "订单尾号 5018")
|
||||
XCTAssertFalse(order.isHidden)
|
||||
XCTAssertTrue(view.bounds.contains(name.convert(name.bounds, to: view)))
|
||||
XCTAssertTrue(view.bounds.contains(order.convert(order.bounds, to: view)))
|
||||
XCTAssertFalse(view.hasAmbiguousLayout)
|
||||
}
|
||||
|
||||
/// 透明摘要与外部卡片齐边;切换为缺失订单后隐藏原尾号,没有占位假号码。
|
||||
func testTransparentCustomerHidesMissingOrderAndUsesNoHorizontalInset() throws {
|
||||
let view = DroneDockDeliveryCustomerView(showsCard: false)
|
||||
view.apply(title: "游客 132****9413", orderNumber: "123")
|
||||
let order = try label(view, "drone.delivery.customer.order")
|
||||
XCTAssertEqual(order.text, "订单尾号 123", "短订单号只展示实际内容,不补零")
|
||||
for value: String? in [nil, "", " \n "] {
|
||||
view.apply(title: "游客 132****9413", orderNumber: value)
|
||||
layout(view, width: 320)
|
||||
XCTAssertTrue(order.isHidden)
|
||||
XCTAssertNil(order.text)
|
||||
}
|
||||
XCTAssertEqual(view.backgroundColor, .clear)
|
||||
XCTAssertEqual(view.layer.borderWidth, 0)
|
||||
let name = try label(view, "drone.delivery.customer.title")
|
||||
XCTAssertEqual(name.convert(.zero, to: view).x, 60, accuracy: 0.5, "48 点头像与 12 点间距,不重复增加外层内边距")
|
||||
XCTAssertEqual(view.bounds.height, 64, accuracy: 0.5)
|
||||
}
|
||||
|
||||
/// 封面必须来自本地视频;同一选择不重新生成,更换/移除立即清除且迟到结果不恢复旧图。
|
||||
func testBundledVideoThumbnailDeduplicatesAndRemovalDiscardsLateImage() async throws {
|
||||
let source = try XCTUnwrap(Bundle.main.url(forResource: "drone_material_demo", withExtension: "mp4")
|
||||
?? Bundle.main.url(forResource: "drone_material_demo", withExtension: "mp4", subdirectory: "DroneDock"))
|
||||
let size = try XCTUnwrap(source.resourceValues(forKeys: [.fileSizeKey]).fileSize)
|
||||
let video = DroneDockDeliveryVideo(url: source, fileName: source.lastPathComponent, fileSize: size)
|
||||
let view = DroneDockDeliveryVideoThumbnailView(frame: CGRect(x: 0, y: 0, width: 320, height: 180))
|
||||
let image = try imageView(view, "drone.delivery.thumbnail.image")
|
||||
let placeholder = try imageView(view, "drone.delivery.thumbnail.placeholder")
|
||||
XCTAssertNil(image.image)
|
||||
XCTAssertFalse(placeholder.isHidden)
|
||||
view.apply(video: video)
|
||||
try await waitForImage(image)
|
||||
let firstImage = try XCTUnwrap(image.image)
|
||||
XCTAssertNotNil(firstImage.cgImage, "必须为实际视频帧,而不是系统符号或演示封面")
|
||||
XCTAssertTrue(placeholder.isHidden)
|
||||
for _ in 0..<3 { view.apply(video: video) }
|
||||
XCTAssertTrue(image.image === firstImage)
|
||||
let nextSelection = DroneDockDeliveryVideo(url: source, fileName: "另一选择.mp4", fileSize: size)
|
||||
view.apply(video: nextSelection)
|
||||
XCTAssertNil(image.image)
|
||||
view.apply(video: nil)
|
||||
try await Task.sleep(for: .milliseconds(200))
|
||||
XCTAssertNil(image.image, "已取消的首帧不能覆盖移除后的空状态")
|
||||
XCTAssertFalse(placeholder.isHidden)
|
||||
XCTAssertEqual(view.accessibilityLabel, "未选择视频")
|
||||
view.apply(video: nextSelection)
|
||||
try await waitForImage(image)
|
||||
XCTAssertTrue(placeholder.isHidden, "取消后重新选择仍可正常生成")
|
||||
view.apply(video: nil)
|
||||
XCTAssertNil(image.image)
|
||||
}
|
||||
|
||||
/// 非文件 URL 被直接拒绝,本地无视频内容也只展示中性占位,不以示例图替代。
|
||||
func testRemoteAndInvalidVideoKeepNeutralPlaceholder() async throws {
|
||||
let view = DroneDockDeliveryVideoThumbnailView(frame: .zero)
|
||||
let image = try imageView(view, "drone.delivery.thumbnail.image")
|
||||
let placeholder = try imageView(view, "drone.delivery.thumbnail.placeholder")
|
||||
view.apply(video: .init(url: try XCTUnwrap(URL(string: "https://invalid.test/not-requested.mp4")), fileName: "remote.mp4", fileSize: 100))
|
||||
XCTAssertNil(image.image)
|
||||
XCTAssertFalse(placeholder.isHidden)
|
||||
let url = FileManager.default.temporaryDirectory.appendingPathComponent("\(UUID().uuidString).mp4")
|
||||
try Data("not a video".utf8).write(to: url)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
view.apply(video: .init(url: url, fileName: "invalid.mp4", fileSize: 11))
|
||||
try await Task.sleep(for: .milliseconds(200))
|
||||
XCTAssertNil(image.image)
|
||||
XCTAssertFalse(placeholder.isHidden)
|
||||
XCTAssertEqual(view.accessibilityLabel, "视频封面暂不可用")
|
||||
view.apply(video: nil)
|
||||
}
|
||||
|
||||
private func layout(_ view: UIView, width: CGFloat) {
|
||||
let size = view.systemLayoutSizeFitting(CGSize(width: width, height: UIView.layoutFittingCompressedSize.height),
|
||||
withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
|
||||
view.frame = CGRect(origin: .zero, size: CGSize(width: width, height: size.height))
|
||||
view.layoutIfNeeded()
|
||||
}
|
||||
|
||||
private func label(_ view: UIView, _ id: String) throws -> UILabel {
|
||||
try XCTUnwrap(descendants(view).first { $0.accessibilityIdentifier == id } as? UILabel)
|
||||
}
|
||||
|
||||
private func imageView(_ view: UIView, _ id: String) throws -> UIImageView {
|
||||
try XCTUnwrap(descendants(view).first { $0.accessibilityIdentifier == id } as? UIImageView)
|
||||
}
|
||||
|
||||
private func descendants(_ view: UIView) -> [UIView] { [view] + view.subviews.flatMap(descendants) }
|
||||
|
||||
private func waitForImage(_ view: UIImageView, file: StaticString = #filePath, line: UInt = #line) async throws {
|
||||
for _ in 0..<300 {
|
||||
if view.image?.cgImage != nil { return }
|
||||
try await Task.sleep(for: .milliseconds(10))
|
||||
}
|
||||
XCTFail("本地测试视频未生成真实封面", file: file, line: line)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user