统一 HTTP 和 WebSocket 控制台 JSON 输出,保留完整入参、响应及本地错误。为多点位航拍订单增加已支付退款入口和回归测试,并同步联调文档、接口记录及截图。
134 lines
4.2 KiB
Swift
134 lines
4.2 KiB
Swift
import UIKit
|
|
import XCTest
|
|
@testable import suixinkan
|
|
|
|
/// 使用真实订单卡片与本地 JSON 验证退款入口的状态、类型及只读限制。
|
|
@MainActor
|
|
final class OrderCardCellRefundVisibilityTests: XCTestCase {
|
|
func testPaidMultiPointAerialOrderShowsRefund() throws {
|
|
let cell = makeCell()
|
|
|
|
try configure(cell, orderType: 25, orderStatus: 20)
|
|
|
|
try assertRefundVisible(true, in: cell)
|
|
}
|
|
|
|
func testReadOnlyMultiPointAerialOrdersHideRefund() throws {
|
|
let cell = makeCell()
|
|
|
|
for status in [18, 20, 30] {
|
|
try configure(cell, orderType: 25, orderStatus: status, readOnly: true)
|
|
try assertRefundVisible(false, in: cell)
|
|
}
|
|
}
|
|
|
|
func testOtherPaidOrderTypesKeepRefundHidden() throws {
|
|
let cell = makeCell()
|
|
|
|
for type in [11, 14] {
|
|
try configure(cell, orderType: type, orderStatus: 20)
|
|
try assertRefundVisible(false, in: cell)
|
|
}
|
|
}
|
|
|
|
func testMultiTravelOrdersKeepRefundHidden() throws {
|
|
let cell = makeCell()
|
|
|
|
for status in [18, 20, 30] {
|
|
try configure(cell, orderType: 19, orderStatus: status)
|
|
try assertRefundVisible(false, in: cell)
|
|
}
|
|
}
|
|
|
|
func testDepositPaidAndCompletedOrdersKeepRefundVisible() throws {
|
|
let cell = makeCell()
|
|
|
|
for type in [11, 14, 25] {
|
|
for status in [18, 30] {
|
|
try configure(cell, orderType: type, orderStatus: status)
|
|
try assertRefundVisible(true, in: cell)
|
|
}
|
|
}
|
|
}
|
|
|
|
func testOtherMultiPointAerialStatusesHideRefund() throws {
|
|
let cell = makeCell()
|
|
|
|
for status in [0, 10, 40, 50] {
|
|
try configure(cell, orderType: 25, orderStatus: status)
|
|
try assertRefundVisible(false, in: cell)
|
|
}
|
|
}
|
|
|
|
func testReusedCellUpdatesRefundVisibility() throws {
|
|
let cell = makeCell()
|
|
|
|
try configure(cell, orderType: 25, orderStatus: 20, readOnly: true)
|
|
try assertRefundVisible(false, in: cell)
|
|
|
|
try configure(cell, orderType: 25, orderStatus: 20)
|
|
try assertRefundVisible(true, in: cell)
|
|
|
|
try configure(cell, orderType: 25, orderStatus: 50)
|
|
try assertRefundVisible(false, in: cell)
|
|
|
|
try configure(cell, orderType: 14, orderStatus: 30)
|
|
try assertRefundVisible(true, in: cell)
|
|
|
|
try configure(cell, orderType: 14, orderStatus: 20)
|
|
try assertRefundVisible(false, in: cell)
|
|
}
|
|
|
|
private func makeCell() -> OrderCardCell {
|
|
OrderCardCell(style: .default, reuseIdentifier: OrderCardCell.reuseIdentifier)
|
|
}
|
|
|
|
private func configure(
|
|
_ cell: OrderCardCell,
|
|
orderType: Int,
|
|
orderStatus: Int,
|
|
readOnly: Bool = false
|
|
) throws {
|
|
let json = """
|
|
{"order_number":"refund-visibility-test","order_type":\(orderType),"order_status":\(orderStatus)}
|
|
"""
|
|
let order = try JSONDecoder().decode(OrderEntity.self, from: Data(json.utf8))
|
|
cell.configure(
|
|
order: order,
|
|
hideWriteActions: readOnly,
|
|
actions: OrderCardActions(),
|
|
showOrderSource: false,
|
|
sourceSelection: nil
|
|
)
|
|
}
|
|
|
|
/// 同时检查退款按钮及其父视图,避免操作行被隐藏时误判为可见。
|
|
private func assertRefundVisible(
|
|
_ expected: Bool,
|
|
in cell: OrderCardCell,
|
|
file: StaticString = #filePath,
|
|
line: UInt = #line
|
|
) throws {
|
|
let button = try XCTUnwrap(refundButton(in: cell), file: file, line: line)
|
|
var view: UIView? = button
|
|
var visible = true
|
|
while let current = view {
|
|
visible = visible && !current.isHidden
|
|
view = current.superview
|
|
}
|
|
XCTAssertEqual(visible, expected, file: file, line: line)
|
|
}
|
|
|
|
private func refundButton(in view: UIView) -> OrderActionButton? {
|
|
if let button = view as? OrderActionButton, button.title(for: .normal) == "退款" {
|
|
return button
|
|
}
|
|
for subview in view.subviews {
|
|
if let button = refundButton(in: subview) {
|
|
return button
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|