优化首页位置上报体验

This commit is contained in:
2026-07-10 11:44:56 +08:00
parent c03a625409
commit df547a16dc
8 changed files with 47 additions and 11 deletions

View File

@ -67,6 +67,27 @@ final class LocationReportServiceTests: XCTestCase {
XCTAssertTrue(stateStore.isOnline)
}
func testManualReportUsesLowerLocationAccuracy() async throws {
let reportJSON = """
{"code":100000,"msg":"success","data":{"staff_id":"staff-1","expired":0,"status":1}}
""".data(using: .utf8)!
let api = HomeAPI(client: APIClient(environment: .testing, session: MockURLSession(responses: [reportJSON])))
let stateStore = HomeLocationStateStore(store: appStore)
let locationProvider = MockLocationProvider()
let service = LocationReportService(
appStore: appStore,
locationStateStore: stateStore,
locationProvider: locationProvider
)
_ = try await service.manualReport(api: api)
XCTAssertEqual(
locationProvider.requestedSnapshotAccuracies,
[LocationReportService.manualReportDesiredAccuracy]
)
}
func testTooFrequentManualReportThrows() async throws {
let reportJSON = """
{"code":100000,"msg":"success","data":{"staff_id":"staff-1","expired":0,"status":1}}

View File

@ -13,9 +13,11 @@ final class MockLocationProvider: LocationProviding, @unchecked Sendable {
var reverseGeocodeResult = "北京市东城区"
var requestSnapshotError: Error?
var requestCoordinateError: Error?
var requestedSnapshotAccuracies: [CLLocationAccuracy] = []
var requestedAccuracies: [CLLocationAccuracy] = []
func requestSnapshot() async throws -> HomeLocationSnapshot {
func requestSnapshot(desiredAccuracy: CLLocationAccuracy = kCLLocationAccuracyBest) async throws -> HomeLocationSnapshot {
requestedSnapshotAccuracies.append(desiredAccuracy)
if let requestSnapshotError { throw requestSnapshotError }
return snapshot
}

View File

@ -245,7 +245,7 @@ private final class MockPunchPointLocationProvider: LocationProviding, @unchecke
self.reverseAddress = reverseAddress
}
func requestSnapshot() async throws -> HomeLocationSnapshot {
func requestSnapshot(desiredAccuracy: CLLocationAccuracy = kCLLocationAccuracyBest) async throws -> HomeLocationSnapshot {
snapshot
}

View File

@ -1465,7 +1465,7 @@ private final class MockRiskMapLocationProvider: LocationProviding, @unchecked S
self.onCoordinateRequest = onCoordinateRequest
}
func requestSnapshot() async throws -> HomeLocationSnapshot {
func requestSnapshot(desiredAccuracy: CLLocationAccuracy = kCLLocationAccuracyBest) async throws -> HomeLocationSnapshot {
switch result {
case .success(let latitude, let longitude):
return HomeLocationSnapshot(latitude: latitude, longitude: longitude, address: "测试地址")