76 lines
2.8 KiB
Swift
76 lines
2.8 KiB
Swift
import XCTest
|
|
|
|
final class LocationPersistenceTests: XCTestCase {
|
|
private let app = XCUIApplication()
|
|
|
|
override func setUpWithError() throws {
|
|
continueAfterFailure = false
|
|
}
|
|
|
|
func testReadingPositionRestoredOnReopen() throws {
|
|
app.launchAndOpenSampleBook()
|
|
app.waitForReader(timeout: 12)
|
|
|
|
_ = app.waitForDemoReaderState(timeout: 5, description: "存在页码") { $0.page != nil }
|
|
|
|
let paging = app.collectionViews[IDs.readerPaging]
|
|
if paging.waitForExistence(timeout: 5) {
|
|
paging.swipeLeft()
|
|
}
|
|
|
|
let stateAfterSwipe = app.waitForDemoReaderState(timeout: 8, description: "翻页后页码变化") { state in
|
|
(state.page ?? 0) > 1
|
|
}
|
|
let pageAfterSwipe = stateAfterSwipe.page ?? 0
|
|
|
|
guard pageAfterSwipe > 1 else {
|
|
throw XCTSkip("当前翻页模式下未能翻到第 2 页")
|
|
}
|
|
|
|
let backButton = app.buttons[IDs.readerBack]
|
|
if backButton.waitForExistence(timeout: 3) { backButton.tap() }
|
|
|
|
app.launchAndOpenSampleBook()
|
|
app.waitForReader(timeout: 12)
|
|
|
|
let restoredState = app.waitForDemoReaderState(timeout: 8, description: "恢复阅读位置") { state in
|
|
state.page != nil
|
|
}
|
|
let restoredPage = restoredState.page ?? 0
|
|
XCTAssertEqual(restoredPage, pageAfterSwipe, "重新打开后应恢复到上次阅读页码")
|
|
}
|
|
|
|
func testResetStateLaunchesAtFirstPage() throws {
|
|
app.launchAndOpenSampleBook(resetsReaderState: true)
|
|
app.waitForReader(timeout: 12)
|
|
|
|
let state = app.waitForDemoReaderState(timeout: 5, description: "首开第 1 页") { state in
|
|
state.page != nil
|
|
}
|
|
let page = state.page ?? 0
|
|
XCTAssertEqual(page, 1, "重置状态后应从第 1 页开始")
|
|
}
|
|
|
|
func testPositionSurvivesFontChange() throws {
|
|
app.launchAndOpenSampleBook()
|
|
app.waitForReader(timeout: 12)
|
|
|
|
let paging = app.collectionViews[IDs.readerPaging]
|
|
if paging.waitForExistence(timeout: 5) { paging.swipeLeft() }
|
|
app.waitForReaderState(containing: "page=", timeout: 5)
|
|
|
|
app.showReaderChromeIfNeeded()
|
|
if app.buttons[IDs.readerSettings].waitForExistence(timeout: 3) { app.buttons[IDs.readerSettings].tap() }
|
|
if app.buttons[IDs.settingsFontIncrease].waitForExistence(timeout: 5) { app.buttons[IDs.settingsFontIncrease].tap() }
|
|
if app.buttons[IDs.settingsDone].waitForExistence(timeout: 3) { app.buttons[IDs.settingsDone].tap() }
|
|
|
|
let backButton = app.buttons[IDs.readerBack]
|
|
if backButton.waitForExistence(timeout: 3) { backButton.tap() }
|
|
|
|
app.launchAndOpenSampleBook()
|
|
app.waitForReader(timeout: 12)
|
|
|
|
app.waitForReaderState(containing: "reader=opened", timeout: 8)
|
|
}
|
|
}
|