- 新增 RDEPUBReaderSearchCoordinator 与 RDEPUBSelectionState 管理搜索和选中状态 - 新增 BookmarkChromeStateTests、NavigationBackwardTests、SelectionAnnotateTests 等 UI 测试 - 新增多个边界测试 epub 样本(损坏结构、空归档、缺失文件、流式外链验证) - 重构阅读器 chrome 状态管理,统一 tool bar 与 search bar 交互 - 优化大书分页缓存策略(RDEPUBChapterSummaryDiskCache、RDEPUBPageCountCache) - 移除废弃的 RDEPUBLocationConverter 和 RDEPUBPageBreakPolicy - 更新 epub-bridge.js 与 JS bridge 通信协议 - 全面更新现有 UI 测试以适配新的 helper 和状态管理
201 lines
8.3 KiB
Swift
201 lines
8.3 KiB
Swift
import XCTest
|
||
|
||
final class SettingsEffectTests: XCTestCase {
|
||
private let app = XCUIApplication()
|
||
|
||
override func setUpWithError() throws {
|
||
continueAfterFailure = false
|
||
}
|
||
|
||
func testFontSizeChangeUpdatesContent() throws {
|
||
app.launchAndOpenSampleBook()
|
||
app.waitForReader(timeout: 12)
|
||
app.waitForDemoReaderState(timeout: 5, description: "page exists") { $0.page != nil }
|
||
|
||
app.showReaderChromeIfNeeded()
|
||
XCTAssertTrue(app.buttons[IDs.readerSettings].waitForExistence(timeout: 3), "设置按钮不存在")
|
||
app.buttons[IDs.readerSettings].tap()
|
||
|
||
XCTAssertTrue(app.scrollViews[IDs.settingsScroll].waitForExistence(timeout: 5), "设置面板未出现")
|
||
XCTAssertTrue(app.buttons[IDs.settingsFontIncrease].waitForExistence(timeout: 3), "字号增大按钮不存在")
|
||
app.buttons[IDs.settingsFontIncrease].tap()
|
||
|
||
XCTAssertTrue(app.buttons[IDs.settingsDone].waitForExistence(timeout: 3), "完成按钮不存在")
|
||
app.buttons[IDs.settingsDone].tap()
|
||
|
||
app.waitForDemoReaderState(timeout: 8, description: "reader=opened") { $0.isOpened }
|
||
}
|
||
|
||
func testThemeSwitchChangesBackground() throws {
|
||
app.launchAndOpenSampleBook()
|
||
app.waitForReader(timeout: 12)
|
||
|
||
app.showReaderChromeIfNeeded()
|
||
app.buttons[IDs.readerSettings].tap()
|
||
XCTAssertTrue(app.scrollViews[IDs.settingsScroll].waitForExistence(timeout: 5), "设置面板未出现")
|
||
app.scrollViews[IDs.settingsScroll].swipeUp()
|
||
|
||
let darkThemeButton = app.buttons[IDs.settingsTheme(5)]
|
||
if darkThemeButton.waitForExistence(timeout: 3) { darkThemeButton.tap() }
|
||
|
||
app.buttons[IDs.settingsDone].tap()
|
||
|
||
let contentView = app.otherElements[IDs.readerContentView]
|
||
XCTAssertTrue(contentView.waitForExistence(timeout: 5), "主题切换后内容区应存在")
|
||
}
|
||
|
||
func testColumnCountChangeUpdatesLayout() throws {
|
||
app.launchAndOpenSampleBook()
|
||
app.waitForReader(timeout: 12)
|
||
|
||
app.showReaderChromeIfNeeded()
|
||
app.buttons[IDs.readerSettings].tap()
|
||
XCTAssertTrue(app.scrollViews[IDs.settingsScroll].waitForExistence(timeout: 5))
|
||
app.scrollViews[IDs.settingsScroll].swipeUp()
|
||
|
||
let columnsControl = app.segmentedControls[IDs.settingsColumns]
|
||
if columnsControl.waitForExistence(timeout: 3) && columnsControl.buttons.count > 1 {
|
||
columnsControl.buttons.element(boundBy: 1).tap()
|
||
}
|
||
|
||
app.buttons[IDs.settingsDone].tap()
|
||
app.waitForDemoReaderState(timeout: 8, description: "reader=opened") { $0.isOpened }
|
||
}
|
||
|
||
func testLineHeightChangeUpdatesContent() throws {
|
||
app.launchAndOpenSampleBook()
|
||
app.waitForReader(timeout: 12)
|
||
|
||
app.showReaderChromeIfNeeded()
|
||
app.buttons[IDs.readerSettings].tap()
|
||
XCTAssertTrue(app.scrollViews[IDs.settingsScroll].waitForExistence(timeout: 5))
|
||
|
||
let lineHeightControl = app.segmentedControls[IDs.settingsLineHeight]
|
||
if lineHeightControl.waitForExistence(timeout: 3) && lineHeightControl.buttons.count > 1 {
|
||
lineHeightControl.buttons.element(boundBy: 1).tap()
|
||
}
|
||
|
||
app.buttons[IDs.settingsDone].tap()
|
||
app.waitForDemoReaderState(timeout: 8, description: "reader=opened") { $0.isOpened }
|
||
}
|
||
|
||
func testDisplayTypeChangeRePaginates() throws {
|
||
app.launchAndOpenSampleBook(displayType: "horizontalscroll")
|
||
app.waitForReader(timeout: 12)
|
||
app.waitForDemoReaderState(timeout: 5, description: "display=horizontalScroll") { $0.display == "horizontalScroll" }
|
||
|
||
app.showReaderChromeIfNeeded()
|
||
app.buttons[IDs.readerSettings].tap()
|
||
XCTAssertTrue(app.scrollViews[IDs.settingsScroll].waitForExistence(timeout: 5))
|
||
|
||
let displayTypeControl = app.segmentedControls[IDs.settingsDisplayType]
|
||
if displayTypeControl.waitForExistence(timeout: 3) && displayTypeControl.buttons.count > 0 {
|
||
displayTypeControl.buttons.element(boundBy: 0).tap()
|
||
}
|
||
|
||
app.buttons[IDs.settingsDone].tap()
|
||
app.waitForDemoReaderState(timeout: 8, description: "display changed") { $0.display != nil }
|
||
}
|
||
|
||
func testDefaultBodyPaginationDoesNotEnableWidowOrphanCompaction() throws {
|
||
app.launchAndOpenSampleBook()
|
||
app.waitForReader(timeout: 12)
|
||
|
||
let state = app.waitForDemoReaderState(timeout: 8, description: "默认正文分页策略") { state in
|
||
state.avoidWidows != nil && state.avoidOrphans != nil
|
||
}
|
||
|
||
XCTAssertEqual(state.avoidWidows, 0, "默认正文分页不应启用 widow compaction,避免页尾明显留白")
|
||
XCTAssertEqual(state.avoidOrphans, 0, "默认正文分页不应启用 orphan compaction,避免提前换页")
|
||
}
|
||
|
||
func testSettingsPersistAfterReopen() throws {
|
||
app.launchAndOpenSampleBook()
|
||
app.waitForReader(timeout: 12)
|
||
|
||
app.showReaderChromeIfNeeded()
|
||
app.buttons[IDs.readerSettings].tap()
|
||
|
||
XCTAssertTrue(app.buttons[IDs.settingsFontIncrease].waitForExistence(timeout: 5))
|
||
let fontValueLabel = app.staticTexts[IDs.settingsFontValue]
|
||
XCTAssertTrue(fontValueLabel.waitForExistence(timeout: 3))
|
||
let originalFontValue = fontValueLabel.label
|
||
|
||
app.buttons[IDs.settingsFontIncrease].tap()
|
||
let newFontValue = fontValueLabel.label
|
||
XCTAssertNotEqual(newFontValue, originalFontValue, "点击增大后字号 label 应变化")
|
||
|
||
app.buttons[IDs.settingsDone].tap()
|
||
app.buttons[IDs.readerBack].tap()
|
||
|
||
app.launchAndOpenSampleBook()
|
||
app.waitForReader(timeout: 12)
|
||
|
||
app.showReaderChromeIfNeeded()
|
||
app.buttons[IDs.readerSettings].tap()
|
||
|
||
let persistedFontValue = app.staticTexts[IDs.settingsFontValue]
|
||
if persistedFontValue.waitForExistence(timeout: 5) {
|
||
XCTAssertEqual(persistedFontValue.label, newFontValue, "重新打开后字号应持久化为之前的值")
|
||
}
|
||
|
||
app.buttons[IDs.settingsDone].tap()
|
||
}
|
||
|
||
func testThemeSelectionPersistsAfterReopen() throws {
|
||
app.launchAndOpenSampleBook(resetsReaderState: true)
|
||
app.waitForReader(timeout: 12)
|
||
|
||
app.showReaderChromeIfNeeded()
|
||
app.buttons[IDs.readerSettings].tap()
|
||
|
||
let darkThemeButton = app.buttons[IDs.settingsTheme(5)]
|
||
XCTAssertTrue(darkThemeButton.waitForExistence(timeout: 5))
|
||
darkThemeButton.tap()
|
||
XCTAssertEqual(darkThemeButton.value as? String, "selected", "切换主题后当前主题按钮应为选中态")
|
||
app.buttons[IDs.settingsDone].tap()
|
||
|
||
app.showReaderChromeIfNeeded()
|
||
app.buttons[IDs.readerBack].tap()
|
||
|
||
app.launchAndOpenSampleBook(resetsReaderState: false)
|
||
app.waitForReader(timeout: 12)
|
||
app.showReaderChromeIfNeeded()
|
||
app.buttons[IDs.readerSettings].tap()
|
||
|
||
let reopenedDarkThemeButton = app.buttons[IDs.settingsTheme(5)]
|
||
XCTAssertTrue(reopenedDarkThemeButton.waitForExistence(timeout: 5))
|
||
XCTAssertEqual(reopenedDarkThemeButton.value as? String, "selected", "主题应在重启后保持选中")
|
||
app.buttons[IDs.settingsDone].tap()
|
||
}
|
||
|
||
func testFontChoiceChangePersistsAfterReopen() throws {
|
||
app.launchAndOpenSampleBook(resetsReaderState: true)
|
||
app.waitForReader(timeout: 12)
|
||
|
||
app.showReaderChromeIfNeeded()
|
||
app.buttons[IDs.readerSettings].tap()
|
||
|
||
let fontChoiceControl = app.segmentedControls[IDs.settingsFontChoice]
|
||
XCTAssertTrue(fontChoiceControl.waitForExistence(timeout: 5))
|
||
if fontChoiceControl.buttons.count > 1 {
|
||
fontChoiceControl.buttons.element(boundBy: 1).tap()
|
||
}
|
||
XCTAssertEqual(fontChoiceControl.value as? String, "宋体", "切换字体后当前字体值应更新")
|
||
app.buttons[IDs.settingsDone].tap()
|
||
|
||
app.showReaderChromeIfNeeded()
|
||
app.buttons[IDs.readerBack].tap()
|
||
|
||
app.launchAndOpenSampleBook(resetsReaderState: false)
|
||
app.waitForReader(timeout: 12)
|
||
app.showReaderChromeIfNeeded()
|
||
app.buttons[IDs.readerSettings].tap()
|
||
|
||
let reopenedFontChoiceControl = app.segmentedControls[IDs.settingsFontChoice]
|
||
XCTAssertTrue(reopenedFontChoiceControl.waitForExistence(timeout: 5))
|
||
XCTAssertEqual(reopenedFontChoiceControl.value as? String, "宋体", "字体选择应在重启后保持")
|
||
app.buttons[IDs.settingsDone].tap()
|
||
}
|
||
}
|