Fuel Savings: MPG and fill-up are sliders, not typed fields

The two Fuel Savings figures and the in-list fill-up control were text
fields. A typed figure could sit outside the slider's own bounds, so the
control and the number it claimed to show could disagree, and the decimal
pad needed a Done button to escape.

- Settings: "Average fuel economy" and "Typical fill-up" are now sliders
  with a read-out ("45 MPG", "£40" / "40 L") in place of the field. The
  warning copy reads "Set a realistic..." rather than "Enter...".
- FuelSavingsAdjustmentView (shared by the Stations Worth-the-Drive header
  and the Favourites tab) drops its text field and gains the same read-out;
  the typed-value machinery and the -focusFillAmount QA hook go with it.
- Slider bounds live in FuelSavingsCalculator (fillAmountSliderRange/Step,
  mpgSliderRange/Step) so the Settings control and the in-list control can
  never offer different ranges, and the fill-up slider range stays inside
  the calculator's validity ceiling (asserted by test).
- Two tests pin those invariants: every slider position is a valid amount,
  and both MPG bounds are valid MPG values. 155 tests, 0 failures.
- Comments that described the removed fields were updated; the keyboard
  Done-bar plumbing is kept (no numeric field remains in the app, so it can
  no longer fire) rather than deleted, so any field added later still has an
  escape route.

Verified on the simulator: Settings shows "Average fuel economy / 45 MPG"
with no field, and the Worth-the-Drive fill-up control shows the unit picker
with a "£40" read-out and a slider. The Settings "Typical fill-up" row sits
below the fold on every simulator available here (and synthetic input cannot
scroll it), so those pixels are unverified.
This commit is contained in:
FuelBoard Contributor
2026-10-11 17:41:53 +01:00
parent d0a89d97d5
commit cf3abb3fa7
5 changed files with 116 additions and 65 deletions
@@ -432,4 +432,35 @@ final class FuelSavingsEstimateTests: XCTestCase {
)
XCTAssertEqual(worse.capsuleHeadline(), "£0.31 worse off after travel")
}
// MARK: - Slider bounds (Settings and the in-list control share these)
/// Both fill-up controls are slider-only now, so every position the slider
/// can reach must be a usable amount — otherwise the control could sit on a
/// figure the calculator rejects.
func testFillAmountSliderBoundsAreAlwaysValidAmounts() {
for unit in FuelSavingsFillUnit.allCases {
let range = FuelSavingsCalculator.fillAmountSliderRange(for: unit)
let step = FuelSavingsCalculator.fillAmountSliderStep(for: unit)
XCTAssertLessThan(range.lowerBound, range.upperBound, "\(unit) range must be usable")
XCTAssertGreaterThan(step, 0, "\(unit) step must advance")
XCTAssertGreaterThan(range.lowerBound, 0, "\(unit) must never offer a zero fill")
XCTAssertLessThanOrEqual(range.upperBound,
FuelSavingsCalculator.maximumFillAmount(for: unit),
"\(unit) slider must stay inside the valid ceiling")
for position in [range.lowerBound, range.upperBound, (range.lowerBound + range.upperBound) / 2] {
XCTAssertTrue(FuelSavingsFillAmount(value: position, unit: unit).isValid,
"\(position) \(unit) must be a valid amount")
}
}
}
func testMPGSliderBoundsAreInsideTheValidMPGRange() {
let range = FuelSavingsCalculator.mpgSliderRange
XCTAssertLessThan(range.lowerBound, range.upperBound)
XCTAssertGreaterThan(FuelSavingsCalculator.mpgSliderStep, 0)
XCTAssertTrue(FuelSavingsCalculator.isValidMPG(range.lowerBound))
XCTAssertTrue(FuelSavingsCalculator.isValidMPG(range.upperBound))
XCTAssertTrue(FuelSavingsCalculator.isValidMPG(45), "a typical UK figure must be reachable")
}
}