115 lines
3.4 KiB
Swift
115 lines
3.4 KiB
Swift
import ComposableArchitecture
|
|
@testable import PressureEstimationsFeature
|
|
import Testing
|
|
import XCTest
|
|
|
|
struct EquipmentSettingsFormStateTests {
|
|
|
|
@Test(
|
|
"Ensure setting static pressure",
|
|
.tags(.equipmentSettingsForm),
|
|
arguments: [Optional<Double>(42), nil]
|
|
)
|
|
func setStaticPressure(staticPressure: Double?) {
|
|
var sharedSettings = SharedPressureEstimationState()
|
|
|
|
sharedSettings.handleStaticPressure(\.maximum, staticPressure)
|
|
sharedSettings.handleStaticPressure(\.minimum, staticPressure)
|
|
sharedSettings.handleStaticPressure(\.rated, staticPressure)
|
|
|
|
if let staticPressure {
|
|
#expect(sharedSettings.equipmentMetadata.ratedStaticPressures.maximum == staticPressure)
|
|
#expect(sharedSettings.equipmentMetadata.ratedStaticPressures.minimum == staticPressure)
|
|
#expect(sharedSettings.equipmentMetadata.ratedStaticPressures.rated == staticPressure)
|
|
} else {
|
|
#expect(sharedSettings.equipmentMetadata.ratedStaticPressures.maximum == 0)
|
|
#expect(sharedSettings.equipmentMetadata.ratedStaticPressures.minimum == 0)
|
|
#expect(sharedSettings.equipmentMetadata.ratedStaticPressures.rated == 0)
|
|
}
|
|
}
|
|
|
|
struct ValidationContainer {
|
|
let state: EquipmentSettingsForm.State
|
|
let expectsValid: Bool
|
|
}
|
|
|
|
@Test(
|
|
"Validations",
|
|
.tags(.equipmentSettingsForm),
|
|
arguments: [
|
|
ValidationContainer(
|
|
state: .init(sharedSettings: Shared(SharedPressureEstimationState())),
|
|
expectsValid: true
|
|
),
|
|
ValidationContainer(
|
|
state: .init(
|
|
equipmentType: .furnaceAndCoil,
|
|
sharedSettings: Shared(SharedPressureEstimationState())
|
|
),
|
|
expectsValid: false
|
|
)
|
|
]
|
|
)
|
|
func validation(container: ValidationContainer) {
|
|
#expect(container.state.isValid == container.expectsValid)
|
|
}
|
|
}
|
|
|
|
final class EquipmentSettingsFormTests: XCTestCase {
|
|
|
|
@MainActor
|
|
func testStaticPressureBindings() async throws {
|
|
let store = TestStore(
|
|
initialState: EquipmentSettingsForm.State(sharedSettings: Shared(SharedPressureEstimationState()))
|
|
) {
|
|
EquipmentSettingsForm()
|
|
}
|
|
|
|
await store.send(.binding(.set(\.maxStaticPressure, nil))) {
|
|
$0.maxStaticPressure = nil
|
|
$0.sharedSettings.ratedStaticPressures.maximum = 0
|
|
}
|
|
|
|
await store.send(.binding(.set(\.minStaticPressure, nil))) {
|
|
$0.minStaticPressure = nil
|
|
$0.sharedSettings.ratedStaticPressures.minimum = 0
|
|
}
|
|
|
|
await store.send(.binding(.set(\.ratedStaticPressure, nil))) {
|
|
$0.ratedStaticPressure = nil
|
|
$0.sharedSettings.ratedStaticPressures.rated = 0
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
func testViewActions() async throws {
|
|
let store = TestStore(
|
|
initialState: EquipmentSettingsForm.State(
|
|
equipmentType: .furnaceAndCoil,
|
|
sharedSettings: Shared(SharedPressureEstimationState(heatingCapacity: 20_000))
|
|
)
|
|
) {
|
|
EquipmentSettingsForm()
|
|
}
|
|
|
|
await store.send(.view(.resetButtonTapped)) {
|
|
$0.sharedSettings.heatingCapacity = nil
|
|
}
|
|
await store.send(.view(.submitField))
|
|
|
|
for infoView in EquipmentSettingsForm.InfoView.allCases {
|
|
await store.send(.view(.infoButtonTapped(infoView))) {
|
|
$0.destination = .infoView(.init(view: infoView))
|
|
}
|
|
await store.send(.destination(.dismiss)) {
|
|
$0.destination = nil
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
extension Tag {
|
|
@Tag static var equipmentSettingsForm: Self
|
|
}
|