Load role-permission on first visit to drive menus, role-based layout, store card, and location reporting with account-scoped persistence and unit tests. Co-authored-by: Cursor <cursoragent@cursor.com>
67 lines
2.3 KiB
Swift
67 lines
2.3 KiB
Swift
//
|
|
// HomeLocationStateStoreTests.swift
|
|
// suixinkanTests
|
|
//
|
|
|
|
import XCTest
|
|
@testable import suixinkan
|
|
|
|
/// 首页在线状态存储测试。
|
|
final class HomeLocationStateStoreTests: XCTestCase {
|
|
|
|
private var appStore: AppStore!
|
|
|
|
override func setUp() {
|
|
let defaults = UserDefaults(suiteName: "HomeLocationStateStoreTests")!
|
|
defaults.removePersistentDomain(forName: "HomeLocationStateStoreTests")
|
|
appStore = AppStore(defaults: defaults)
|
|
appStore.userId = "1001"
|
|
appStore.accountType = "scenic_user"
|
|
}
|
|
|
|
override func tearDown() {
|
|
appStore.logout()
|
|
super.tearDown()
|
|
}
|
|
|
|
func testExpiredOnlineSessionIsClearedOnRestore() {
|
|
let expiredTimestamp = Int64(Date().timeIntervalSince1970 * 1000) - HomeLocationStateStore.onlineDurationMillis - 1_000
|
|
appStore.onlineStatus = true
|
|
appStore.lastLocationReportTime = expiredTimestamp
|
|
|
|
let stateStore = HomeLocationStateStore(store: appStore)
|
|
stateStore.restoreStateIfNeeded()
|
|
|
|
XCTAssertFalse(stateStore.isOnline)
|
|
XCTAssertFalse(appStore.onlineStatus)
|
|
XCTAssertEqual(appStore.lastLocationReportTime, 0)
|
|
}
|
|
|
|
func testActiveOnlineSessionRestoresCountdown() {
|
|
let recentTimestamp = Int64(Date().timeIntervalSince1970 * 1000) - 60_000
|
|
appStore.onlineStatus = true
|
|
appStore.lastLocationReportTime = recentTimestamp
|
|
|
|
let stateStore = HomeLocationStateStore(store: appStore)
|
|
stateStore.restoreStateIfNeeded()
|
|
|
|
XCTAssertTrue(stateStore.isOnline)
|
|
XCTAssertGreaterThan(stateStore.nextReportCountdownSeconds, 0)
|
|
}
|
|
|
|
func testFormattedCountdownText() {
|
|
let stateStore = HomeLocationStateStore(store: appStore)
|
|
XCTAssertEqual(stateStore.formattedCountdown(from: 3661), "01:01:01")
|
|
}
|
|
|
|
func testShouldTriggerTimeoutReminderWithinWindow() {
|
|
appStore.locationReminderMinutes = 10
|
|
let stateStore = HomeLocationStateStore(store: appStore)
|
|
stateStore.startLocationReport(at: Int64(Date().timeIntervalSince1970 * 1000))
|
|
stateStore.updateReminderMinutes(10)
|
|
// Force countdown into reminder window via reflection of internal state is not available;
|
|
// verify helper with manual expectation on threshold logic.
|
|
XCTAssertFalse(stateStore.shouldTriggerTimeoutReminder())
|
|
}
|
|
}
|