Show ranking capsules and value breakdown in station details
The More info sheet now lists every ranking a station qualifies for, directly under the map and above the price and distance: the same StationLabelBadge the listing rows render, in a flow layout so two or three capsules wrap to a new line rather than truncating at large Dynamic Type. The rules are not restated. StationRanking defers to StationRecommendationBadge.badge for the Best Value gate, and takes Cheapest and Top as the flags the host list already computed for its own rows, so the sheet cannot award a capsule the row behind it withheld. A host passes one of the two, never both: Stations sends isCheapestInRange, Favourites sends isTopFavourite. No calculation, ranking, eligibility or savings logic changed. Rename the card heading Best Value to Value breakdown, since the working behind it can end in Costs rather than a saving, and drop the green section tint so the card matches the neutral background used elsewhere in the sheet. The Saves, Break even and Costs capsules and every breakdown row are untouched. Rename the explanation link to How does FuelBoard calculate value? It names the calculation rather than the feature, of which the Best Value gate is only the last step. The sheet's own title stays short: the full question truncated to 'How does FuelBoard...' as a navigation title at both inline and large display modes, so the row carries the question and the sheet names the topic. Tests: 269 pass, 5 new covering capsule selection, order and sheet-vs-row agreement on Best Value.
This commit is contained in:
@@ -324,6 +324,81 @@ final class KeySheetContentTests: XCTestCase {
|
||||
KeySheetContent.favourite,
|
||||
.init(label: "Favourites", description: "Star a station to save it to your Favourites.")
|
||||
)
|
||||
XCTAssertEqual(KeySheetContent.helpTitle, "How does Best Value work?")
|
||||
// The link names the calculation, not the feature: the sheet explains the
|
||||
// fill-up, the return trip and the total, of which the Best Value gate is
|
||||
// only the last step.
|
||||
XCTAssertEqual(KeySheetContent.helpTitle, "How does FuelBoard calculate value?")
|
||||
// The sheet title is a short form of the question, NOT the question itself:
|
||||
// a nav title clamps to the bar, and the full question truncated to
|
||||
// "How does FuelBoard…" at both display modes.
|
||||
XCTAssertEqual(KeySheetContent.helpSheetTitle, "How value is calculated")
|
||||
XCTAssertLessThan(KeySheetContent.helpSheetTitle.count, KeySheetContent.helpTitle.count)
|
||||
}
|
||||
}
|
||||
|
||||
/// The More info sheet's ranking capsules. Every rule must come from the shared
|
||||
/// badge logic — the sheet may show more labels than a row (which shows one), but
|
||||
/// it must not invent a qualification of its own.
|
||||
final class StationRankingTests: XCTestCase {
|
||||
private let threshold = 2.50
|
||||
|
||||
func testNoQualificationProducesNoCapsules() {
|
||||
XCTAssertEqual(
|
||||
StationRanking.kinds(netSavingGBP: 0.40, isCheapestInRange: false,
|
||||
isTopFavourite: false, bestValueThresholdGBP: threshold),
|
||||
[]
|
||||
)
|
||||
}
|
||||
|
||||
func testBestValueUsesTheSameGateAsTheListingBadge() {
|
||||
// Exactly at the threshold qualifies, matching StationRecommendationBadge.
|
||||
XCTAssertEqual(
|
||||
StationRanking.kinds(netSavingGBP: threshold, isCheapestInRange: false,
|
||||
isTopFavourite: false, bestValueThresholdGBP: threshold),
|
||||
[.bestValue]
|
||||
)
|
||||
// A hair under does not.
|
||||
XCTAssertEqual(
|
||||
StationRanking.kinds(netSavingGBP: threshold - 0.01, isCheapestInRange: false,
|
||||
isTopFavourite: false, bestValueThresholdGBP: threshold),
|
||||
[]
|
||||
)
|
||||
}
|
||||
|
||||
func testCheapestInRangeAndTopFavouriteAreDistinctLabels() {
|
||||
XCTAssertEqual(
|
||||
StationRanking.kinds(netSavingGBP: nil, isCheapestInRange: true,
|
||||
isTopFavourite: false, bestValueThresholdGBP: threshold),
|
||||
[.cheapest]
|
||||
)
|
||||
XCTAssertEqual(
|
||||
StationRanking.kinds(netSavingGBP: nil, isCheapestInRange: false,
|
||||
isTopFavourite: true, bestValueThresholdGBP: threshold),
|
||||
[.top]
|
||||
)
|
||||
}
|
||||
|
||||
func testCapsulesAreOrderedBestValueTopCheapest() {
|
||||
XCTAssertEqual(
|
||||
StationRanking.kinds(netSavingGBP: 9.99, isCheapestInRange: true,
|
||||
isTopFavourite: true, bestValueThresholdGBP: threshold),
|
||||
[.bestValue, .top, .cheapest]
|
||||
)
|
||||
}
|
||||
|
||||
/// A row shows ONE badge; the sheet may show several. Both must agree on the
|
||||
/// Best Value decision, or the sheet would claim a label the list behind it
|
||||
/// withheld.
|
||||
func testSheetAgreesWithTheRowOnBestValue() {
|
||||
for netSaving in [-3.0, 0.0, 2.49, 2.50, 12.0, .nan] as [Double] {
|
||||
let rowSaysBestValue = StationRecommendationBadge.badge(
|
||||
netSavingGBP: netSaving, isCheapest: false, bestValueThresholdGBP: threshold
|
||||
) == .bestValue
|
||||
let sheetSaysBestValue = StationRanking.kinds(
|
||||
netSavingGBP: netSaving, isCheapestInRange: false,
|
||||
isTopFavourite: false, bestValueThresholdGBP: threshold
|
||||
).contains(.bestValue)
|
||||
XCTAssertEqual(rowSaysBestValue, sheetSaysBestValue, "disagreed on net saving \(netSaving)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user