增加禁飞期间的设备指令拦截及本地模拟拍摄流程;适配订单素材库和景区空境库,完善素材筛选、预览与下载;订单交付入口改为方式选择弹窗并复用云端上传。补充单元测试、接口记录和模拟器截图。
76 lines
3.9 KiB
Swift
76 lines
3.9 KiB
Swift
import AVKit
|
|
import UIKit
|
|
import XCTest
|
|
@testable import suixinkan
|
|
|
|
/// 使用包内短片验证预览进度来自真实播放器,并在暂停和关闭时停止推进。
|
|
@MainActor
|
|
final class ScenicMaterialPreviewPlaybackTests: XCTestCase {
|
|
/// 本地演示的实际 3 秒时长不能伪装为素材元信息的 28 秒,关闭后也不能继续回调进度。
|
|
func testDemoProgressUsesAssetDurationAndStopsAfterClosing() async throws {
|
|
let clip = ScenicMaterialClip(id: "preview:1", groupID: "preview", ordinal: 1,
|
|
durationSeconds: 28, fileSizeBytes: 178_000_000, resolution: "4K",
|
|
coverAssetName: "drone_demo_mountain")
|
|
let controller = ScenicMaterialPreviewViewController(clip: clip, routeName: "测试航线",
|
|
capturedAt: Date(timeIntervalSince1970: 1_700_000_000))
|
|
let scene = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.first
|
|
let previousKeyWindow = scene?.windows.first { $0.isKeyWindow }
|
|
let window = scene.map { UIWindow(windowScene: $0) } ?? UIWindow(frame: UIScreen.main.bounds)
|
|
window.rootViewController = controller
|
|
window.makeKeyAndVisible()
|
|
window.layoutIfNeeded()
|
|
defer {
|
|
controller.viewWillDisappear(false)
|
|
controller.viewDidDisappear(false)
|
|
window.isHidden = true
|
|
window.rootViewController = nil
|
|
previousKeyWindow?.makeKeyAndVisible()
|
|
}
|
|
let play = try XCTUnwrap(find(in: controller.view, identifier: "scenic.materials.preview.play") as? UIButton)
|
|
let progress = try XCTUnwrap(find(in: controller.view, identifier: "scenic.materials.preview.progress") as? UIProgressView)
|
|
let time = try XCTUnwrap(find(in: controller.view, identifier: "scenic.materials.preview.playbackTime") as? UILabel)
|
|
let playerController = try XCTUnwrap(controller.children.compactMap { $0 as? AVPlayerViewController }.first)
|
|
XCTAssertEqual(time.text, "00:00 / 原片 00:28")
|
|
|
|
play.sendActions(for: .touchUpInside)
|
|
try await waitUntil { progress.progress > 0.05 }
|
|
let player = try XCTUnwrap(playerController.player)
|
|
XCTAssertTrue(time.text?.hasSuffix(" / 00:03") == true)
|
|
XCTAssertFalse(time.text?.contains("00:28") == true)
|
|
|
|
play.sendActions(for: .touchUpInside)
|
|
XCTAssertEqual(player.rate, 0)
|
|
try await Task.sleep(nanoseconds: 150_000_000)
|
|
let pausedProgress = progress.progress
|
|
try await Task.sleep(nanoseconds: 200_000_000)
|
|
XCTAssertEqual(progress.progress, pausedProgress, accuracy: 0.02)
|
|
|
|
play.sendActions(for: .touchUpInside)
|
|
XCTAssertTrue(playerController.player === player)
|
|
try await waitUntil { progress.progress > pausedProgress + 0.04 }
|
|
|
|
let done = try XCTUnwrap(find(in: controller.view, identifier: "scenic.materials.preview.done") as? UIButton)
|
|
done.sendActions(for: .touchUpInside)
|
|
XCTAssertNil(playerController.player)
|
|
XCTAssertEqual(player.rate, 0)
|
|
XCTAssertEqual(progress.progress, 0)
|
|
try await Task.sleep(nanoseconds: 250_000_000)
|
|
XCTAssertEqual(progress.progress, 0)
|
|
XCTAssertEqual(time.text, "00:00 / 原片 00:28")
|
|
}
|
|
|
|
private func waitUntil(_ condition: () -> Bool) async throws {
|
|
let deadline = Date().addingTimeInterval(4)
|
|
while Date() < deadline {
|
|
if condition() { return }
|
|
try await Task.sleep(nanoseconds: 20_000_000)
|
|
}
|
|
XCTFail("本地预览播放器未在限定时间内推进")
|
|
}
|
|
|
|
private func find(in root: UIView, identifier: String) -> UIView? {
|
|
if root.accessibilityIdentifier == identifier { return root }
|
|
return root.subviews.lazy.compactMap { self.find(in: $0, identifier: identifier) }.first
|
|
}
|
|
}
|