30 lines
1.2 KiB
Swift
30 lines
1.2 KiB
Swift
import UIKit
|
|
import XCTest
|
|
@testable import suixinkan
|
|
|
|
/// 分页末行的加载与失败重试按钮不能在忙碌状态重复触发请求。
|
|
@MainActor
|
|
final class ScenicMaterialPageFooterTests: XCTestCase {
|
|
/// 禁用、重试及复用时保持一致的点击语义。
|
|
func testLoadingDisablesActionAndReuseClearsOldCallback() throws {
|
|
let cell = ScenicMaterialPageFooterCell(frame: CGRect(x: 0, y: 0, width: 320, height: 48))
|
|
let button = try XCTUnwrap(cell.contentView.subviews.compactMap { $0 as? UIButton }.first)
|
|
var requests = 0
|
|
cell.onLoadMore = { requests += 1 }
|
|
cell.configure(title: "正在加载更多场次…", enabled: false)
|
|
button.sendActions(for: .touchUpInside)
|
|
XCTAssertEqual(requests, 0)
|
|
|
|
cell.configure(title: "加载失败,点击重试", enabled: true)
|
|
button.sendActions(for: .touchUpInside)
|
|
XCTAssertEqual(requests, 1)
|
|
XCTAssertEqual(button.accessibilityIdentifier, "scenic.materials.loadMore")
|
|
cell.layoutIfNeeded()
|
|
XCTAssertGreaterThanOrEqual(button.bounds.height, 44)
|
|
|
|
cell.prepareForReuse()
|
|
button.sendActions(for: .touchUpInside)
|
|
XCTAssertEqual(requests, 1)
|
|
}
|
|
}
|