migration

This commit is contained in:
Daniel Arantes Loverde
2026-08-11 13:22:02 -03:00
parent c4d6998595
commit 7702836fe7
231 changed files with 4329 additions and 1958 deletions

View File

@@ -0,0 +1,67 @@
import SwiftUI
import Testing
@testable import PediFoods
/// Constructs a `HomeView` directly (no host window/hierarchy needed to
/// call its plain funcs that take explicit parameters). Note:
/// `@State`-backed properties (`stores`, etc.) mutated *after*
/// construction do NOT reliably persist outside a real SwiftUI render
/// pass - confirmed empirically (computed properties reading `stores`
/// saw the untouched `[]` default even after `view.stores = ...`). So
/// this only covers `HomeView+Filtering` functions that take their
/// input as parameters, not ones that read `@State` implicitly -
/// `filteredStores` and friends are UI-test territory (Batch F), not
/// unit-test territory.
@MainActor
private func makeHomeView() -> HomeView {
var state = AppState()
let appStateBinding = Binding(get: { state }, set: { state = $0 })
let tabBinding = Binding<MainTab>(get: { .home }, set: { _ in })
return HomeView(appState: appStateBinding, selectedTab: tabBinding)
}
@Test("normalizeSearch folds diacritics and case")
@MainActor
func normalizeSearchFoldsDiacriticsAndCase() {
let view = makeHomeView()
#expect(view.normalizeSearch("Açaí") == "acai")
#expect(view.normalizeSearch("PIZZA") == "pizza")
#expect(view.normalizeSearch(" Café ") == "cafe")
}
@Test("matchesPriceTier buckets delivery fees at the documented boundaries")
@MainActor
func matchesPriceTierBoundaries() {
let view = makeHomeView()
#expect(view.matchesPriceTier(fee: 5, tier: .low))
#expect(view.matchesPriceTier(fee: 5.01, tier: .low) == false)
#expect(view.matchesPriceTier(fee: 5.01, tier: .medium))
#expect(view.matchesPriceTier(fee: 10, tier: .medium))
#expect(view.matchesPriceTier(fee: 10.01, tier: .high))
#expect(view.matchesPriceTier(fee: 20.01, tier: .veryHigh))
}
@Test("estimatedDeliveryMinutes picks the smaller number out of a range like '30-45 min'")
@MainActor
func estimatedDeliveryMinutesPicksMinimumOfRange() {
let view = makeHomeView()
#expect(view.estimatedDeliveryMinutes("30-45 min") == 30)
}
@Test("estimatedDeliveryMinutes returns Int.max for nil or non-numeric input")
@MainActor
func estimatedDeliveryMinutesMaxForMissingOrGarbageInput() {
let view = makeHomeView()
#expect(view.estimatedDeliveryMinutes(nil) == Int.max)
#expect(view.estimatedDeliveryMinutes("indisponível") == Int.max)
}
@Test("formatDistance shows meters below 1km and kilometers at or above 1km")
@MainActor
func formatDistanceSwitchesUnitsAtOneKm() {
let view = makeHomeView()
#expect(view.formatDistance(0.5) == "500 m")
#expect(view.formatDistance(1.0) == "1.0 km")
#expect(view.formatDistance(2.3) == "2.3 km")
#expect(view.formatDistance(nil) == "Distância indisponível")
}