feat: complete large-book pagination runtime and UI coverage

This commit is contained in:
shenlei
2026-06-03 17:47:16 +08:00
parent 584976ac5f
commit feb05eaf87
53 changed files with 6307 additions and 5126 deletions
@@ -0,0 +1,63 @@
import XCTest
final class TOCInteractionTests: XCTestCase {
private let app = XCUIApplication()
override func setUpWithError() throws {
continueAfterFailure = false
}
func testTOCPanelShowsChapterList() throws {
app.launchAndOpenSampleBook()
app.waitForReader(timeout: 12)
app.showReaderChromeIfNeeded()
let tocButton = app.buttons[IDs.readerToc]
XCTAssertTrue(tocButton.waitForExistence(timeout: 3), "目录按钮不存在")
tocButton.tap()
let tocTable = app.tables[IDs.readerTocTable]
XCTAssertTrue(tocTable.waitForExistence(timeout: 5), "目录表格未出现")
XCTAssertTrue(tocTable.cells.count > 0, "目录应至少有 1 个章节")
}
func testTOCNavigatesToChapter() throws {
app.launchAndOpenSampleBook()
app.waitForReader(timeout: 12)
let initialState = app.waitForDemoReaderState(timeout: 5, description: "初始页码") { state in
state.page != nil
}
let initialPage = initialState.page ?? 0
app.showReaderChromeIfNeeded()
app.buttons[IDs.readerToc].tap()
let tocTable = app.tables[IDs.readerTocTable]
XCTAssertTrue(tocTable.waitForExistence(timeout: 5), "目录表格未出现")
if tocTable.cells.count > 1 {
tocTable.cells.element(boundBy: 1).tap()
let updatedState = app.waitForDemoReaderState(timeout: 8, description: "目录跳转后页码变化") { state in
guard let page = state.page else { return false }
return page != initialPage
}
let updatedPage = updatedState.page ?? 0
XCTAssertNotEqual(updatedPage, initialPage, "目录跳转后页码应变化")
} else {
tocTable.cells.element(boundBy: 0).tap()
app.waitForReaderState(containing: "reader=opened", timeout: 8)
}
}
func testTOCEmptyHandling() throws {
app.launchAndOpenSampleBook()
app.waitForReader(timeout: 12)
app.showReaderChromeIfNeeded()
app.buttons[IDs.readerToc].tap()
XCTAssertTrue(app.otherElements[IDs.readerTocPanel].waitForExistence(timeout: 5), "目录面板应可打开")
}
}