feat: optimize reader caching and document formats
This commit is contained in:
@@ -44,9 +44,9 @@ enum IDs {
|
||||
/// The text layer is the precise, image-coordinate based interaction surface.
|
||||
static let pdfTextLayer = "pdf.reader.text.layer"
|
||||
static let pdfOCRStatus = "pdf.reader.ocr.status"
|
||||
/// PDF 选区菜单与 EPUB 相同,使用系统编辑菜单,按菜单项标题(复制/高亮/注释)定位。
|
||||
/// PDF 选区菜单与 EPUB 相同,使用系统编辑菜单,按菜单项标题(复制/划线/注释)定位。
|
||||
static let pdfSelectionMenuCopy = "复制"
|
||||
static let pdfSelectionMenuHighlight = "高亮"
|
||||
static let pdfSelectionMenuHighlight = "划线"
|
||||
static let pdfSelectionMenuAnnotate = "注释"
|
||||
static let pdfCopyStatus = "pdf.reader.copy.status"
|
||||
|
||||
|
||||
@@ -119,7 +119,9 @@ final class HighlightsManagementTests: XCTestCase {
|
||||
let deleteControl = highlightsTable.buttons["删除"].firstMatch
|
||||
XCTAssertTrue(deleteControl.waitForExistence(timeout: 3), "编辑状态应显示删除控件")
|
||||
deleteControl.tap()
|
||||
app.buttons["删除"].lastMatch.tap()
|
||||
// 编辑态的行内“删除”与确认用的“删除”同名;确认按钮是最后出现的那个。
|
||||
let deleteButtons = app.buttons.matching(identifier: "删除")
|
||||
deleteButtons.element(boundBy: max(0, deleteButtons.count - 1)).tap()
|
||||
|
||||
XCTAssertTrue(app.staticTexts[IDs.readerHighlightsEmptyLabel].waitForExistence(timeout: 5), "删除后应显示空状态")
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ final class LocationPersistenceTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testHighlightNavigationSurvivesFontChoiceChange() throws {
|
||||
app.launchAndOpenSampleBook(resetsReaderState: true, pageNumber: 3)
|
||||
app.launchAndOpenSampleBook(pageNumber: 3, resetsReaderState: true)
|
||||
app.waitForReader(timeout: 12)
|
||||
|
||||
let initialState = app.waitForDemoReaderState(timeout: 8, description: "初始位于第 3 页") { state in
|
||||
|
||||
@@ -58,6 +58,46 @@ final class PDFDrawingModeTests: XCTestCase {
|
||||
)
|
||||
}
|
||||
|
||||
/// 放大状态下同一规则:未选中工具单指拖动画面,选中画笔后单指只用于绘制。
|
||||
func testZoomedPageDragsOnlyWhenDrawingToolIsDeselected() {
|
||||
app.launchAndOpenSampleBook(bookTitleQuery: "英汉大词典", displayType: "pagecurl")
|
||||
app.waitForReader()
|
||||
|
||||
let content = app.otherElements[IDs.readerContent].firstMatch
|
||||
XCTAssertTrue(content.waitForExistence(timeout: 8), "PDF 阅读页面未出现")
|
||||
|
||||
app.showReaderChromeIfNeeded(requiredButtonIDs: [IDs.pdfDrawing])
|
||||
let drawing = app.buttons[IDs.pdfDrawing]
|
||||
XCTAssertTrue(drawing.waitForExistence(timeout: 5), "画笔入口未出现")
|
||||
drawing.tap()
|
||||
|
||||
let pen = app.buttons[IDs.pdfDrawingPen]
|
||||
XCTAssertTrue(pen.waitForExistence(timeout: 5), "画笔工具未出现")
|
||||
|
||||
// 未选中工具 → 双指放大
|
||||
content.pinch(withScale: 2.5, velocity: 1)
|
||||
RunLoop.current.run(until: Date().addingTimeInterval(1.0))
|
||||
let zoomedFrame = content.frame
|
||||
XCTAssertGreaterThan(zoomedFrame.width, app.windows.firstMatch.frame.width * 1.2, "画笔面板打开时无法双指放大页面")
|
||||
|
||||
// 未选中工具 → 单指拖动应移动页面
|
||||
let start = content.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
|
||||
let end = content.coordinate(withNormalizedOffset: CGVector(dx: 0.3, dy: 0.3))
|
||||
start.press(forDuration: 0.05, thenDragTo: end)
|
||||
RunLoop.current.run(until: Date().addingTimeInterval(0.8))
|
||||
let draggedFrame = content.frame
|
||||
XCTAssertNotEqual(draggedFrame.origin, zoomedFrame.origin, "未选中工具时,放大页面无法单指拖动")
|
||||
|
||||
// 选中画笔 → 单指应绘制而非拖动
|
||||
pen.tap()
|
||||
let frameBeforeStroke = content.frame
|
||||
let strokeStart = content.coordinate(withNormalizedOffset: CGVector(dx: 0.45, dy: 0.45))
|
||||
let strokeEnd = content.coordinate(withNormalizedOffset: CGVector(dx: 0.6, dy: 0.6))
|
||||
strokeStart.press(forDuration: 0.05, thenDragTo: strokeEnd)
|
||||
RunLoop.current.run(until: Date().addingTimeInterval(0.8))
|
||||
XCTAssertEqual(content.frame.origin, frameBeforeStroke.origin, "选中画笔后,单指仍拖动了放大页面而不是绘制")
|
||||
}
|
||||
|
||||
private func waitForLandscapeLayout() -> Bool {
|
||||
let deadline = Date().addingTimeInterval(8)
|
||||
while Date() < deadline {
|
||||
@@ -69,8 +109,12 @@ final class PDFDrawingModeTests: XCTestCase {
|
||||
}
|
||||
|
||||
private func scrollToAnotherPage(_ content: XCUIElement, from page: Int) -> Bool {
|
||||
let window = app.windows.firstMatch
|
||||
for _ in 0..<5 {
|
||||
content.swipeUp()
|
||||
// 从屏幕上半部拖动,避开底部画笔工具条区域。
|
||||
let start = window.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.35))
|
||||
let end = window.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.05))
|
||||
start.press(forDuration: 0.05, thenDragTo: end, withVelocity: .fast, thenHoldForDuration: 0)
|
||||
let deadline = Date().addingTimeInterval(1.5)
|
||||
while Date() < deadline {
|
||||
if let current = app.currentDemoReaderState()?.page, current != page { return true }
|
||||
|
||||
Reference in New Issue
Block a user