修复离线路径误弹位置上报超时窗,并优化提醒设置与定位 Loading 展示。
离线或倒计时未进入提醒窗口时不再弹出超时提醒;全局 Loading 支持按需展示定位文案,提前提醒选项抽成共用组件。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -18,13 +18,13 @@ final class GlobalLoadingCenterTests: XCTestCase {
|
||||
center.show(message: "加载账号")
|
||||
center.show(message: "加载权限")
|
||||
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: true, message: "加载权限", activeCount: 2))
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: true, message: "加载权限", activeCount: 2, showsMessage: false))
|
||||
|
||||
center.hide()
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: true, message: "加载权限", activeCount: 1))
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: true, message: "加载权限", activeCount: 1, showsMessage: false))
|
||||
|
||||
center.hide()
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: false, message: "", activeCount: 0))
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: false, message: "", activeCount: 0, showsMessage: false))
|
||||
}
|
||||
|
||||
/// 测试 hide 调用次数超过 show 时不会产生负数计数。
|
||||
@ -33,7 +33,7 @@ final class GlobalLoadingCenterTests: XCTestCase {
|
||||
|
||||
center.hide()
|
||||
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: false, message: "", activeCount: 0))
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: false, message: "", activeCount: 0, showsMessage: false))
|
||||
}
|
||||
|
||||
/// 测试更新文案只影响当前展示内容,不改变引用计数。
|
||||
@ -41,12 +41,12 @@ final class GlobalLoadingCenterTests: XCTestCase {
|
||||
let center = GlobalLoadingCenter()
|
||||
|
||||
center.updateMessage("不会展示")
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: false, message: "", activeCount: 0))
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: false, message: "", activeCount: 0, showsMessage: false))
|
||||
|
||||
center.show(message: "加载中")
|
||||
center.updateMessage("即将完成")
|
||||
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: true, message: "即将完成", activeCount: 1))
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: true, message: "即将完成", activeCount: 1, showsMessage: false))
|
||||
}
|
||||
|
||||
/// 测试 withLoading 成功完成后自动隐藏 Loading。
|
||||
@ -54,12 +54,12 @@ final class GlobalLoadingCenterTests: XCTestCase {
|
||||
let center = GlobalLoadingCenter()
|
||||
|
||||
let value = try await center.withLoading(message: "提交中") {
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: true, message: "提交中", activeCount: 1))
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: true, message: "提交中", activeCount: 1, showsMessage: false))
|
||||
return 42
|
||||
}
|
||||
|
||||
XCTAssertEqual(value, 42)
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: false, message: "", activeCount: 0))
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: false, message: "", activeCount: 0, showsMessage: false))
|
||||
}
|
||||
|
||||
/// 测试 withLoading 抛错时也会自动隐藏 Loading。
|
||||
@ -75,7 +75,7 @@ final class GlobalLoadingCenterTests: XCTestCase {
|
||||
XCTAssertEqual(error as? TestFailure, .expected)
|
||||
}
|
||||
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: false, message: "", activeCount: 0))
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: false, message: "", activeCount: 0, showsMessage: false))
|
||||
}
|
||||
|
||||
/// 测试 withOptionalLoading 关闭时不会改变展示状态。
|
||||
@ -83,12 +83,28 @@ final class GlobalLoadingCenterTests: XCTestCase {
|
||||
let center = GlobalLoadingCenter()
|
||||
|
||||
let value = try await center.withOptionalLoading(false, message: "不展示") {
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: false, message: "", activeCount: 0))
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: false, message: "", activeCount: 0, showsMessage: false))
|
||||
return "done"
|
||||
}
|
||||
|
||||
XCTAssertEqual(value, "done")
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: false, message: "", activeCount: 0))
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: false, message: "", activeCount: 0, showsMessage: false))
|
||||
}
|
||||
|
||||
/// 测试默认不展示文案,仅在显式开启时记录展示状态。
|
||||
func testShowsMessageOnlyWhenEnabled() {
|
||||
let center = GlobalLoadingCenter()
|
||||
|
||||
center.show(message: "加载中")
|
||||
XCTAssertEqual(center.snapshotForTests.message, "加载中")
|
||||
XCTAssertFalse(center.snapshotForTests.showsMessage)
|
||||
|
||||
center.hide()
|
||||
center.show(message: "获取定位中", showsMessage: true)
|
||||
XCTAssertTrue(center.snapshotForTests.showsMessage)
|
||||
|
||||
center.hide()
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: false, message: "", activeCount: 0, showsMessage: false))
|
||||
}
|
||||
|
||||
/// 测试使用 Loading 不需要读取可观察展示状态,业务侧只能拿到命令中心类型。
|
||||
@ -97,7 +113,7 @@ final class GlobalLoadingCenterTests: XCTestCase {
|
||||
|
||||
issueLoadingCommand(center)
|
||||
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: true, message: "加载中", activeCount: 1))
|
||||
XCTAssertEqual(center.snapshotForTests, GlobalLoadingSnapshot(isVisible: true, message: "加载中", activeCount: 1, showsMessage: false))
|
||||
center.hide()
|
||||
}
|
||||
|
||||
|
||||
@ -331,19 +331,54 @@ final class HomeLocationViewModelTests: XCTestCase {
|
||||
XCTAssertEqual(viewModel.reminderMinutes, 10)
|
||||
}
|
||||
|
||||
/// 测试 detail 接口触发超时对话框。
|
||||
func testCheckLocationTimeoutShowsDialogWhenNearExpiry() async {
|
||||
let api = MockLocationReportService()
|
||||
/// 测试在线且倒计时进入提醒窗口时弹出超时对话框。
|
||||
func testCheckLocationTimeoutShowsDialogWhenOnlineAndWithinReminderWindow() async {
|
||||
let store = makeIsolatedStore()
|
||||
let expireTime = Int(Date().timeIntervalSince1970) + 120
|
||||
api.detailResponse = LocationDetailResponse(status: 1, needReport: true, expireTime: expireTime)
|
||||
let viewModel = HomeLocationViewModel(api: api, store: makeIsolatedStore())
|
||||
viewModel.updateReminderMinutes(5)
|
||||
store.saveOnlineStatus(true)
|
||||
store.saveExpireTime(expireTime)
|
||||
store.saveReminderMinutes(5)
|
||||
|
||||
let viewModel = HomeLocationViewModel(api: MockLocationReportService(), store: store)
|
||||
viewModel.restoreState()
|
||||
|
||||
await viewModel.checkLocationTimeout(staffId: 77)
|
||||
|
||||
XCTAssertTrue(viewModel.isOnline)
|
||||
XCTAssertTrue(viewModel.showTimeoutDialog)
|
||||
}
|
||||
|
||||
/// 测试离线状态不弹出超时对话框。
|
||||
func testCheckLocationTimeoutDoesNotShowDialogWhenOffline() async {
|
||||
let store = makeIsolatedStore()
|
||||
store.saveOnlineStatus(false)
|
||||
store.saveReminderMinutes(5)
|
||||
|
||||
let viewModel = HomeLocationViewModel(api: MockLocationReportService(), store: store)
|
||||
viewModel.restoreState()
|
||||
|
||||
await viewModel.checkLocationTimeout(staffId: 77)
|
||||
|
||||
XCTAssertFalse(viewModel.showTimeoutDialog)
|
||||
}
|
||||
|
||||
/// 测试在线但倒计时未进入提醒窗口时不弹窗。
|
||||
func testCheckLocationTimeoutDoesNotShowDialogWhenOutsideReminderWindow() async {
|
||||
let store = makeIsolatedStore()
|
||||
let expireTime = Int(Date().timeIntervalSince1970) + 3_600
|
||||
store.saveOnlineStatus(true)
|
||||
store.saveExpireTime(expireTime)
|
||||
store.saveReminderMinutes(5)
|
||||
|
||||
let viewModel = HomeLocationViewModel(api: MockLocationReportService(), store: store)
|
||||
viewModel.restoreState()
|
||||
|
||||
await viewModel.checkLocationTimeout(staffId: 77)
|
||||
|
||||
XCTAssertTrue(viewModel.isOnline)
|
||||
XCTAssertFalse(viewModel.showTimeoutDialog)
|
||||
}
|
||||
|
||||
private func makeIsolatedStore() -> LocationStateStore {
|
||||
let suiteName = "HomeLocationViewModelTests.\(UUID().uuidString)"
|
||||
let defaults = UserDefaults(suiteName: suiteName)!
|
||||
|
||||
Reference in New Issue
Block a user