fix(dronedock): 保留拍摄订单的查看素材入口

This commit is contained in:
2026-11-11 10:31:40 +08:00
parent 31f98537a0
commit 156ea871fa
6 changed files with 104 additions and 36 deletions
+55 -20
View File
@@ -63,10 +63,12 @@ final class DroneDockOrdersViewTests: XCTestCase {
primary.sendActions(for: .touchUpInside); primary.sendActions(for: .touchUpInside)
let navigation = try XCTUnwrap(controller.navigationController)
try await settle(window) {
(navigation.topViewController as? DroneDockShootingTaskViewController)?.viewModel.response != nil
navigation.topViewController is DroneDockShootingTaskViewController
&& navigation.transitionCoordinator == nil
}
let page = try XCTUnwrap(navigation.topViewController as? DroneDockShootingTaskViewController)
NotificationCenter.default.post(name: UIApplication.didBecomeActiveNotification, object: nil)
try await settle(window) { page.viewModel.response != nil }
XCTAssertEqual(page.viewModel.taskID, 801)
XCTAssertEqual(page.viewModel.order.orderID, "TEST-ORDER-ACTIVE")
XCTAssertEqual(factoryCalls, 1)
@@ -362,24 +364,26 @@ final class DroneDockOrdersViewTests: XCTestCase {
XCTAssertEqual(confirmations, 1)
}
/// 复用卡片仅显示上传或失败提示;无提示时折叠整行,但保留独立的邀请确认和历史记录。
func testReusedCardHidesMaterialNoticeWithoutRemovingConfirmation() throws {
/// 复用卡片根据已拍次数和上传状态更新素材入口,并保留邀请确认和历史记录。
func testReusedCardUpdatesMaterialEntryAndConfirmation() throws {
let card = DroneShootingOrderCardView(frame: CGRect(x: 0, y: 0, width: 358, height: 360))
let cases: [(Int?, Int?, Bool, Bool, String?)] = [
(0, 25, false, false, "素材上传中"),
(0, nil, false, false, nil), (1, nil, false, false, nil),
(nil, nil, false, false, nil), (99, nil, false, false, nil),
(2, nil, false, false, "上传中"), (3, nil, false, false, "上传失败"),
(0, nil, true, false, nil), (1, nil, true, true, nil),
(nil, 25, false, false, "素材上传中"), (0, nil, false, false, nil)
let cases: [(Int?, Int?, Int, Bool, String?)] = [
(0, 25, 0, false, "素材上传中"),
(0, nil, 0, false, nil), (1, nil, 1, false, "上传完成"),
(nil, nil, 0, false, nil), (99, nil, 0, false, nil),
(2, nil, 1, false, "上传中"), (3, nil, 1, false, "上传失败"),
(0, nil, 5, false, "未开始上传"), (1, nil, 5, true, "上传完成"),
(nil, nil, 1, false, "素材状态待确认"), (99, nil, 1, false, "素材状态待确认"),
(nil, 25, 0, false, "素材上传中"), (0, nil, 0, false, nil)
]
for (materialStatus, activeStatus, fullQuota, confirmed, notice) in cases {
for (materialStatus, activeStatus, shotCount, confirmed, notice) in cases {
var value = record("NOTICE", status: "processing")
let fullQuota = shotCount == 5
value["material_status"] = materialStatus
value["active_task_status"] = activeStatus
value["active_task_id"] = 21
value["shot_count"] = fullQuota ? 5 : 1
value["remaining_count"] = fullQuota ? 0 : 4
value["shot_count"] = shotCount
value["remaining_count"] = 5 - shotCount
value["can_confirm"] = fullQuota
value["order_status"] = confirmed ? 30 : 20
value["confirm_status"] = confirmed ? 2 : 0
@@ -399,6 +403,7 @@ final class DroneDockOrdersViewTests: XCTestCase {
XCTAssertEqual(confirmation.isHidden, !fullQuota)
XCTAssertEqual(row.isHidden, notice == nil && !fullQuota)
if let notice {
XCTAssertTrue(visibleTexts(in: material).contains("查看素材"))
XCTAssertTrue(visibleTexts(in: material).contains(notice))
XCTAssertFalse(hidden(material))
} else {
@@ -582,25 +587,55 @@ final class DroneDockOrdersViewTests: XCTestCase {
XCTAssertEqual(controller.viewModel.orders.count, 1)
}
/// 素材入口按选中订单进入真实页面,页面出现后才读取摘要与任务,不创建任务。
func testMaterialsLoadsSelectedOrderDetailAndTasksAfterNavigation() async throws {
/// 从已有任务返回后刷新同一订单,已上传的素材可以从列表打开并读取正确订单。
func testReturningFromTaskShowsUploadedMaterialsAndOpensSelectedOrder() async throws {
var materialsSession: MockURLSession?
var second = record("SECOND")
second["material_status"] = 2
let (controller, session) = makeController(responses: [try envelope([record("FIRST"), second], total: 2)],
var second = record("SECOND", status: "processing")
second["shoot_count"] = 1
second["shot_count"] = 0
second["remaining_count"] = 1
second["active_task_id"] = 801
second["active_task_status"] = 20
var completed = record("SECOND", status: "completed")
completed["shoot_count"] = 1
completed["shot_count"] = 1
completed["material_status"] = 1
let task = UIViewController()
let responses = try [
envelope([record("FIRST"), second], total: 2),
envelope([record("FIRST"), completed], total: 2)
]
let (controller, session) = makeController(responses: responses,
materialsFactory: { order, context in
XCTAssertEqual(order.canUploadFilm, false)
let result = try! DroneDockMaterialsNavigationFixtures.controller(context: context, order: order)
materialsSession = result.1
XCTAssertTrue(result.1.requests.isEmpty)
return result.0
}, taskFactory: { taskID, order, _ in
XCTAssertEqual(taskID, 801)
XCTAssertEqual(order.orderNumber, "TEST-ORDER-SECOND")
return task
})
let window = makeWindow(root: controller)
defer { close(window) }
let list = try collection(in: controller)
try await settle(window) { controller.viewModel.orders.count == 2 }
let cell = try await card(at: 1, in: list, window: window)
let control = try XCTUnwrap(find(in: cell, id: "drone.orders.order.TEST-ORDER-SECOND.materials") as? UIControl)
let identifier = "drone.orders.order.TEST-ORDER-SECOND"
XCTAssertTrue(hidden(try XCTUnwrap(find(in: cell, id: identifier + ".materials"))))
try button(in: cell, id: identifier + ".primary").sendActions(for: .touchUpInside)
let navigation = try XCTUnwrap(controller.navigationController)
try await settle(window) { navigation.topViewController === task && navigation.transitionCoordinator == nil }
navigation.popViewController(animated: false)
try await settle(window) { controller.viewModel.orders.last?.materialStatus == 1 }
let refreshed = try await card(at: 1, in: list, window: window)
let control = try XCTUnwrap(find(in: refreshed, id: identifier + ".materials") as? UIControl)
XCTAssertFalse(hidden(control))
XCTAssertTrue(control.isEnabled)
XCTAssertTrue(visibleTexts(in: control).contains("查看素材"))
XCTAssertTrue(visibleTexts(in: control).contains("上传完成"))
control.sendActions(for: .touchUpInside)
try await settle(window) {
(controller.navigationController?.topViewController as? DroneDockMaterialsViewController)?.viewModel.total == 0
@@ -615,7 +650,7 @@ final class DroneDockOrdersViewTests: XCTestCase {
XCTAssertTrue(requests.allSatisfy { $0.httpMethod == "GET" && $0.httpBody == nil })
XCTAssertEqual(requests.map { query($0)["order_number"] }, ["TEST-ORDER-SECOND", "TEST-ORDER-SECOND"])
XCTAssertEqual(requests.map { query($0)["scenic_id"] }, ["128", "128"])
XCTAssertEqual(session.requests.count, 1)
XCTAssertEqual(session.requests.count, 2)
assertOnlyOrders(session)
}