145 lines
5.8 KiB
Swift
145 lines
5.8 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.waitForReaderState(containing: "page=", timeout: 5)
|
||
|
||
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.waitForReaderState(containing: "reader=opened", timeout: 8)
|
||
}
|
||
|
||
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.waitForReaderState(containing: "reader=opened", timeout: 8)
|
||
}
|
||
|
||
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.waitForReaderState(containing: "reader=opened", timeout: 8)
|
||
}
|
||
|
||
func testDisplayTypeChangeRePaginates() throws {
|
||
app.launchAndOpenSampleBook(displayType: "horizontalscroll")
|
||
app.waitForReader(timeout: 12)
|
||
app.waitForReaderState(containing: "display=horizontalScroll", timeout: 5)
|
||
|
||
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.waitForReaderState(containing: "display=", timeout: 8)
|
||
}
|
||
|
||
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()
|
||
}
|
||
}
|