feat: EPUB 阅读器搜索、选中注释、书签 chrome 状态及大量重构优化
- 新增 RDEPUBReaderSearchCoordinator 与 RDEPUBSelectionState 管理搜索和选中状态 - 新增 BookmarkChromeStateTests、NavigationBackwardTests、SelectionAnnotateTests 等 UI 测试 - 新增多个边界测试 epub 样本(损坏结构、空归档、缺失文件、流式外链验证) - 重构阅读器 chrome 状态管理,统一 tool bar 与 search bar 交互 - 优化大书分页缓存策略(RDEPUBChapterSummaryDiskCache、RDEPUBPageCountCache) - 移除废弃的 RDEPUBLocationConverter 和 RDEPUBPageBreakPolicy - 更新 epub-bridge.js 与 JS bridge 通信协议 - 全面更新现有 UI 测试以适配新的 helper 和状态管理
This commit is contained in:
@@ -14,7 +14,7 @@ final class ErrorAndEdgeCaseTests: XCTestCase {
|
||||
let paging = app.collectionViews[IDs.readerPaging]
|
||||
if paging.waitForExistence(timeout: 5) { paging.swipeUp() }
|
||||
|
||||
app.waitForReaderState(containing: "reader=opened", timeout: 5)
|
||||
app.waitForDemoReaderState(timeout: 5, description: "reader=opened") { $0.isOpened }
|
||||
}
|
||||
|
||||
func testOpenAndCloseMultipleTimes() throws {
|
||||
@@ -42,7 +42,7 @@ final class ErrorAndEdgeCaseTests: XCTestCase {
|
||||
|
||||
for _ in 1...5 { paging.swipeLeft() }
|
||||
|
||||
app.waitForReaderState(containing: "reader=opened", timeout: 8)
|
||||
app.waitForDemoReaderState(timeout: 8, description: "reader=opened") { $0.isOpened }
|
||||
}
|
||||
|
||||
func testSettingsPanelScrollReachesAllControls() throws {
|
||||
@@ -66,4 +66,85 @@ final class ErrorAndEdgeCaseTests: XCTestCase {
|
||||
|
||||
app.buttons[IDs.settingsDone].tap()
|
||||
}
|
||||
}
|
||||
|
||||
func testHTTPSExternalLinkShowsConfirmationAlert() throws {
|
||||
app.launchAndOpenSampleBook(bookTitleQuery: "Web交互流式外链验证", displayType: "scroll")
|
||||
app.waitForReader(timeout: 20)
|
||||
|
||||
let httpsLink = externalLinkElement(named: "HTTPS Link")
|
||||
guard httpsLink.waitForExistence(timeout: 8) else {
|
||||
throw XCTSkip("HTTPS 外链元素未暴露")
|
||||
}
|
||||
httpsLink.tap()
|
||||
|
||||
XCTAssertTrue(app.alerts["打开外部链接"].waitForExistence(timeout: 5), "HTTPS 外链应弹出确认框")
|
||||
XCTAssertTrue(app.buttons["打开"].waitForExistence(timeout: 2), "确认框应提供打开按钮")
|
||||
app.buttons["取消"].tap()
|
||||
}
|
||||
|
||||
func testMailtoExternalLinkBlockedByDefaultPolicy() throws {
|
||||
app.launchAndOpenSampleBook(bookTitleQuery: "Web交互流式外链验证", displayType: "scroll")
|
||||
app.waitForReader(timeout: 20)
|
||||
|
||||
let mailtoLink = externalLinkElement(named: "Mailto Link")
|
||||
guard mailtoLink.waitForExistence(timeout: 8) else {
|
||||
throw XCTSkip("Mailto 外链元素未暴露")
|
||||
}
|
||||
mailtoLink.tap()
|
||||
|
||||
XCTAssertFalse(app.alerts["打开外部链接"].waitForExistence(timeout: 2), "默认策略下 mailto 不应弹出确认框")
|
||||
let state = app.waitForDemoReaderState(timeout: 5, description: "mailto activation recorded") { state in
|
||||
(state.externalLinks ?? 0) >= 1 && state.lastExternalURL != nil
|
||||
}
|
||||
XCTAssertTrue(state.lastExternalURL?.contains("mailto:test@example.com") == true, "应记录 mailto 激活但不继续打开")
|
||||
}
|
||||
|
||||
func testLargeWebResourceUsesStreamingPath() throws {
|
||||
app.launchAndOpenSampleBook(bookTitleQuery: "Web交互流式外链验证", displayType: "scroll")
|
||||
app.waitForReader(timeout: 20)
|
||||
|
||||
let state = app.waitForDemoReaderState(timeout: 15, description: "streamedResources>0") { state in
|
||||
(state.streamedResources ?? 0) > 0
|
||||
}
|
||||
XCTAssertGreaterThan(state.streamedResources ?? 0, 0, "大资源应走流式传输路径")
|
||||
}
|
||||
|
||||
func testInvalidEPUBReportsFailure() {
|
||||
app.launchAndOpenSampleBook(bookTitleQuery: "损坏结构样本", resetsReaderState: true)
|
||||
|
||||
let state = app.waitForDemoReaderState(timeout: 12, description: "invalid epub failure") { state in
|
||||
state.lastError != nil && state.lastError != "none"
|
||||
}
|
||||
XCTAssertNotEqual(state.lastError, "none")
|
||||
}
|
||||
|
||||
func testEmptyArchiveReportsFailure() {
|
||||
app.launchAndOpenSampleBook(bookTitleQuery: "空归档样本", resetsReaderState: true)
|
||||
|
||||
let state = app.waitForDemoReaderState(timeout: 12, description: "empty archive failure") { state in
|
||||
state.lastError != nil && state.lastError != "none"
|
||||
}
|
||||
XCTAssertNotEqual(state.lastError, "none")
|
||||
}
|
||||
|
||||
func testMissingSpineDocumentReportsFailure() {
|
||||
app.launchAndOpenSampleBook(bookTitleQuery: "缺失文件样本", resetsReaderState: true)
|
||||
|
||||
let state = app.waitForDemoReaderState(timeout: 12, description: "missing file failure") { state in
|
||||
state.lastError != nil && state.lastError != "none"
|
||||
}
|
||||
XCTAssertNotEqual(state.lastError, "none")
|
||||
}
|
||||
|
||||
private func externalLinkElement(named label: String) -> XCUIElement {
|
||||
let link = app.links[label]
|
||||
if link.exists {
|
||||
return link
|
||||
}
|
||||
let staticText = app.staticTexts[label]
|
||||
if staticText.exists {
|
||||
return staticText
|
||||
}
|
||||
return link
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user