阅读器修改
This commit is contained in:
@@ -205,4 +205,71 @@ final class LocationPersistenceTests: XCTestCase {
|
||||
}
|
||||
XCTAssertEqual(restoredState.page, 3, "字体变化后,通过高亮面板跳转仍应回到原始高亮页")
|
||||
}
|
||||
|
||||
// MARK: - PDF 阅读进度恢复
|
||||
//
|
||||
// 回归点:`RDPDFReaderViewController.viewDidLoad` 里 `reloadData()` 会同步触发
|
||||
// `pageNum(0)` → `saveReadingPage(0)`,把待恢复的页覆盖成 0,导致 `restoreReadingPage`
|
||||
// 永远读到第 1 页。修复:`reloadData()` 前先读恢复页,恢复窗口内跳过写盘。
|
||||
// 前置:Demo 侧 `PDFDemoReaderViewController` 现已把 `RDPDFReaderPersistenceStore`
|
||||
// 同时作为 `persistence:` 传入(此前只传了 `annotationPersistence:`)。
|
||||
|
||||
func testPDFReadingPositionRestoredOnReopen() throws {
|
||||
app.launchAndOpenSampleBook(
|
||||
bookTitleQuery: "英汉大词典",
|
||||
pageNumber: 4,
|
||||
resetsReaderState: true,
|
||||
pdfTextSource: "none"
|
||||
)
|
||||
app.waitForReader(timeout: 30)
|
||||
let moved = app.waitForDemoReaderState(timeout: 20, description: "PDF 跳到第 4 页") { $0.page == 4 }
|
||||
XCTAssertEqual(moved.page, 4)
|
||||
|
||||
// 翻页写盘有 1s 防抖,再留出后台 IO 队列写文件的时间。
|
||||
RunLoop.current.run(until: Date().addingTimeInterval(2.5))
|
||||
|
||||
app.showReaderChromeIfNeeded()
|
||||
let back = app.buttons[IDs.readerBack]
|
||||
XCTAssertTrue(back.waitForExistence(timeout: 5), "返回按钮应出现")
|
||||
back.tap()
|
||||
XCTAssertTrue(app.tables[IDs.demoBooksTable].waitForExistence(timeout: 8), "应返回书库列表")
|
||||
RunLoop.current.run(until: Date().addingTimeInterval(1.5))
|
||||
|
||||
// 重开必须保留状态,displayType 不传:避免 Demo 的 applyDemoDisplayType 把
|
||||
// 状态标签重置成 page=1 干扰断言。
|
||||
app.launchAndOpenSampleBook(
|
||||
bookTitleQuery: "英汉大词典",
|
||||
resetsReaderState: false,
|
||||
pdfTextSource: "none"
|
||||
)
|
||||
app.waitForReader(timeout: 30)
|
||||
let restored = app.waitForDemoReaderState(timeout: 15, description: "PDF 恢复到第 4 页") { $0.page == 4 }
|
||||
XCTAssertEqual(restored.page, 4, "重开 PDF 应恢复上次阅读页,而不是被开局 reloadData 覆盖成第 1 页")
|
||||
}
|
||||
|
||||
func testPDFResetStateClearsPersistedReadingPage() throws {
|
||||
app.launchAndOpenSampleBook(
|
||||
bookTitleQuery: "英汉大词典",
|
||||
pageNumber: 5,
|
||||
resetsReaderState: true,
|
||||
pdfTextSource: "none"
|
||||
)
|
||||
app.waitForReader(timeout: 30)
|
||||
app.waitForDemoReaderState(timeout: 20, description: "PDF 跳到第 5 页") { $0.page == 5 }
|
||||
RunLoop.current.run(until: Date().addingTimeInterval(2.5))
|
||||
|
||||
app.showReaderChromeIfNeeded()
|
||||
let back = app.buttons[IDs.readerBack]
|
||||
if back.waitForExistence(timeout: 5) { back.tap() }
|
||||
RunLoop.current.run(until: Date().addingTimeInterval(1.0))
|
||||
|
||||
app.launchAndOpenSampleBook(
|
||||
bookTitleQuery: "英汉大词典",
|
||||
resetsReaderState: true,
|
||||
pdfTextSource: "none"
|
||||
)
|
||||
app.waitForReader(timeout: 30)
|
||||
let state = app.waitForDemoReaderState(timeout: 15, description: "reset 后回到第 1 页") { $0.page != nil }
|
||||
XCTAssertEqual(state.page, 1, "--demo-reset-state 应清掉 reader-state.json,重开回到第 1 页")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user