feat: Begins equipment settings form tests.
This commit is contained in:
@@ -91,15 +91,15 @@ public struct EquipmentSettingsForm {
|
|||||||
switch action {
|
switch action {
|
||||||
|
|
||||||
case .binding(\.maxStaticPressure):
|
case .binding(\.maxStaticPressure):
|
||||||
handleStaticPressure(\.maximum, \.maxStaticPressure, &state)
|
state.sharedSettings.handleStaticPressure(\.maximum, state.maxStaticPressure)
|
||||||
return .none
|
return .none
|
||||||
|
|
||||||
case .binding(\.minStaticPressure):
|
case .binding(\.minStaticPressure):
|
||||||
handleStaticPressure(\.minimum, \.minStaticPressure, &state)
|
state.sharedSettings.handleStaticPressure(\.maximum, state.minStaticPressure)
|
||||||
return .none
|
return .none
|
||||||
|
|
||||||
case .binding(\.ratedStaticPressure):
|
case .binding(\.ratedStaticPressure):
|
||||||
handleStaticPressure(\.rated, \.ratedStaticPressure, &state)
|
state.sharedSettings.handleStaticPressure(\.rated, state.ratedStaticPressure)
|
||||||
return .none
|
return .none
|
||||||
|
|
||||||
case .binding:
|
case .binding:
|
||||||
@@ -133,16 +133,15 @@ public struct EquipmentSettingsForm {
|
|||||||
.ifLet(\.$destination, action: \.destination)
|
.ifLet(\.$destination, action: \.destination)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleStaticPressure(
|
|
||||||
_ staticKeyPath: WritableKeyPath<RatedStaticPressures, Double>,
|
|
||||||
_ stateKeyPath: KeyPath<State, Double?>,
|
|
||||||
_ state: inout State
|
|
||||||
) {
|
|
||||||
let value = state[keyPath: stateKeyPath]
|
|
||||||
state.sharedSettings.equipmentMetadata.ratedStaticPressures[keyPath: staticKeyPath] = value ?? 0
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension SharedPressureEstimationState {
|
||||||
|
mutating func handleStaticPressure(
|
||||||
|
_ keyPath: WritableKeyPath<RatedStaticPressures, Double>,
|
||||||
|
_ value: Double?
|
||||||
|
) {
|
||||||
|
equipmentMetadata.ratedStaticPressures[keyPath: keyPath] = value ?? 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewAction(for: EquipmentSettingsForm.self)
|
@ViewAction(for: EquipmentSettingsForm.self)
|
||||||
@@ -256,12 +255,6 @@ public struct EquipmentSettingsFormView: View {
|
|||||||
|
|
||||||
Section {
|
Section {
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
// HStack {
|
|
||||||
// TextLabel("Includes Filter Drop")
|
|
||||||
// Spacer()
|
|
||||||
// Toggle("Includes Filter Drop", isOn: $store.includesFilterDrop)
|
|
||||||
// }
|
|
||||||
// if store.includesFilterDrop {
|
|
||||||
HStack {
|
HStack {
|
||||||
TextLabel("Filter Drop")
|
TextLabel("Filter Drop")
|
||||||
Spacer()
|
Spacer()
|
||||||
@@ -273,7 +266,6 @@ public struct EquipmentSettingsFormView: View {
|
|||||||
.decimalPad()
|
.decimalPad()
|
||||||
.padding(.leading, 40)
|
.padding(.leading, 40)
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
} header: {
|
} header: {
|
||||||
header(infoView: .manufacturersIncludedFilterPressureDrop) {
|
header(infoView: .manufacturersIncludedFilterPressureDrop) {
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final class EquipmentSettingsFormTests: XCTestCase {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Tag {
|
||||||
|
@Tag static var equipmentSettingsForm: Self
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user