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:
@@ -0,0 +1,83 @@
|
||||
import XCTest
|
||||
|
||||
/// 向后导航和显示模式切换测试
|
||||
/// 覆盖:向右滑动回到上一页、阅读中途切换显示模式
|
||||
final class NavigationBackwardTests: XCTestCase {
|
||||
|
||||
private let app = XCUIApplication()
|
||||
|
||||
override func setUpWithError() throws {
|
||||
continueAfterFailure = false
|
||||
}
|
||||
|
||||
/// 向右滑动应返回上一页
|
||||
func testSwipeRightGoesToPreviousPage() throws {
|
||||
app.launchAndOpenSampleBook()
|
||||
app.waitForReader()
|
||||
|
||||
// 先向左滑动两次前进
|
||||
let content = app.otherElements[IDs.readerContent].firstMatch
|
||||
guard content.waitForExistence(timeout: 5) else {
|
||||
throw XCTSkip("内容区域不存在")
|
||||
}
|
||||
|
||||
content.swipeLeft()
|
||||
Thread.sleep(forTimeInterval: 0.5)
|
||||
content.swipeLeft()
|
||||
Thread.sleep(forTimeInterval: 0.5)
|
||||
|
||||
// 记录当前页码
|
||||
let stateAfterForward = app.waitForDemoReaderState(timeout: 5, description: "page after forward") {
|
||||
($0.page ?? 0) > 1
|
||||
}
|
||||
let pageAfterForward = stateAfterForward.page ?? 2
|
||||
XCTAssertGreaterThan(pageAfterForward, 1, "应已前进到第 2 页或更后")
|
||||
|
||||
// 向右滑动返回
|
||||
content.swipeRight()
|
||||
Thread.sleep(forTimeInterval: 0.5)
|
||||
|
||||
// 验证页码减少
|
||||
let stateAfterBack = app.waitForDemoReaderState(timeout: 5, description: "page after back") {
|
||||
($0.page ?? 0) < pageAfterForward
|
||||
}
|
||||
XCTAssertLessThan(stateAfterBack.page ?? 0, pageAfterForward, "向右滑动后页码应减少")
|
||||
}
|
||||
|
||||
/// 阅读中途切换显示模式
|
||||
func testDisplayTypeSwitchMidSession() throws {
|
||||
app.launchAndOpenSampleBook(displayType: "horizontalScroll")
|
||||
app.waitForReader()
|
||||
|
||||
// 确认初始模式
|
||||
app.waitForDemoReaderState(timeout: 5, description: "initial horizontalScroll") {
|
||||
$0.display == "horizontalScroll"
|
||||
}
|
||||
|
||||
// 打开设置面板
|
||||
app.showReaderChromeIfNeeded()
|
||||
let settingsButton = app.buttons[IDs.readerSettings]
|
||||
guard settingsButton.waitForExistence(timeout: 3) else {
|
||||
throw XCTSkip("设置按钮不存在")
|
||||
}
|
||||
settingsButton.tap()
|
||||
|
||||
// 切换到垂直滚动
|
||||
let displayTypeButton = app.buttons[IDs.settingsDisplayType]
|
||||
guard displayTypeButton.waitForExistence(timeout: 3) else {
|
||||
throw XCTSkip("显示模式按钮不存在")
|
||||
}
|
||||
displayTypeButton.tap()
|
||||
|
||||
// 关闭设置
|
||||
let doneButton = app.buttons[IDs.settingsDone]
|
||||
if doneButton.waitForExistence(timeout: 3) {
|
||||
doneButton.tap()
|
||||
}
|
||||
|
||||
// 验证显示模式已切换
|
||||
app.waitForDemoReaderState(timeout: 5, description: "switched to verticalScroll") {
|
||||
$0.display == "verticalScroll"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user