Alerts: mile-friendly radius 1/2/3/5/8 + Follow search (capped 8 mi); Live Activity Follow search; legacy radii clamped

This commit is contained in:
FuelBoard Contributor
2026-08-13 15:00:53 +01:00
parent bb48995fac
commit 490c343fd5
5 changed files with 210 additions and 27 deletions
@@ -306,3 +306,50 @@ final class AlertsFuelTests: XCTestCase {
XCTAssertEqual(FuelStore.loadAlertsFuel(), .e10)
}
}
final class AlertRadiusFollowTests: XCTestCase {
func testAlertRadiusOptionsAreMileFriendly() {
// 12 city, 3 town, 5 default, 8 motorway the geofence ceiling.
XCTAssertEqual(FuelStore.alertRadiusOptions, [1, 2, 3, 5, 8])
}
func testLegacyRadiusClampsToCap() {
// Old options went to 20 km; stored values must not exceed the 8-mi cap.
FuelStore.saveAlertsRadius(30)
XCTAssertEqual(FuelStore.loadAlertsRadius(), FuelStore.alertFollowCapKM, accuracy: 0.001)
FuelStore.saveAlertsRadius(5) // still inside the cap untouched
XCTAssertEqual(FuelStore.loadAlertsRadius(), 5, accuracy: 0.001)
}
func testFollowSearchRoundTrips() {
FuelStore.saveAlertsFollowsSearch(true)
XCTAssertTrue(FuelStore.loadAlertsFollowsSearch())
FuelStore.saveAlertsFollowsSearch(false)
XCTAssertFalse(FuelStore.loadAlertsFollowsSearch())
FuelStore.saveLiveActivityFollowsSearch(true)
XCTAssertTrue(FuelStore.loadLiveActivityFollowsSearch())
FuelStore.saveLiveActivityFollowsSearch(false)
XCTAssertFalse(FuelStore.loadLiveActivityFollowsSearch())
}
func testEffectiveRadiusManualWhenNotFollowing() {
let eff = FuelStore.effectiveAlertsRadiusKM(followsSearch: false, manualKM: 3)
XCTAssertEqual(eff, 3, "manual radius passes through when not following")
}
func testEffectiveRadiusFollowsSearchCapped() {
// 15-mile search must cap at the 8-mile geofence ceiling.
FuelStore.saveDistanceUnit(.miles)
FuelStore.saveStationLimit(15)
let eff = FuelStore.effectiveAlertsRadiusKM(followsSearch: true, manualKM: 3)
XCTAssertEqual(eff, FuelStore.alertFollowCapKM, accuracy: 0.001)
}
func testEffectiveRadiusFollowsSmallSearch() {
// 5-mile search follows exactly (8.05 km), under the cap.
FuelStore.saveDistanceUnit(.miles)
FuelStore.saveStationLimit(5)
let eff = FuelStore.effectiveAlertsRadiusKM(followsSearch: true, manualKM: 3)
XCTAssertEqual(eff, 5 * 1.60934, accuracy: 0.001)
}
}