feat: working on tests for pressure estimation feature to resolve filter drop bugs
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import ComposableArchitecture
|
||||
import SharedModels
|
||||
import Testing
|
||||
import XCTest
|
||||
@testable import PressureEstimationsFeature
|
||||
|
||||
struct FlaggedMeasurementListTests {
|
||||
struct FlaggedMeasurementListStateTests {
|
||||
|
||||
@Test(
|
||||
"Ensure Estimation Has Changes",
|
||||
@@ -20,9 +22,159 @@ struct FlaggedMeasurementListTests {
|
||||
)
|
||||
#expect(result != nil)
|
||||
}
|
||||
|
||||
@Test(
|
||||
"Handle Estimation Form",
|
||||
.tags(.flaggedMeasurementList)
|
||||
)
|
||||
func handleEstimationForm() async throws {
|
||||
try await withDependencies {
|
||||
$0.estimatedPressuresClient = .liveValue
|
||||
$0.uuid = .incrementing
|
||||
} operation: {
|
||||
@Dependency(\.estimatedPressuresClient) var client
|
||||
|
||||
let reducer = FlaggedMeasurementsList()
|
||||
let result = try await reducer._handleEstimationForm(
|
||||
form: .init(
|
||||
existingMeasurement: SharedReader(Shared(.mock(type: .airHandler))),
|
||||
cfmTextField: 350,
|
||||
name: "Test"
|
||||
),
|
||||
state: .init(sharedSettings: Shared(.init(
|
||||
budgets: .init(equipmentType: .airHandler, fanType: .constantSpeed),
|
||||
equipmentMeasurement: .mock(type: .airHandler),
|
||||
flaggedEquipmentMeasurement: .init(
|
||||
budgets: .init(equipmentType: .airHandler, fanType: .constantSpeed),
|
||||
measurement: .mock(type: .airHandler),
|
||||
ratedPressures: .init(),
|
||||
tons: .three
|
||||
)
|
||||
)))
|
||||
)
|
||||
|
||||
let measurement = try await client.estimatedPressure(
|
||||
equipmentMeasurement: .mock(type: .airHandler),
|
||||
airflow: 1050,
|
||||
filterPressureDrop: 0.1
|
||||
)
|
||||
|
||||
#expect(result != nil)
|
||||
#expect(result?.estimationState == .init(
|
||||
cfm: .cfmPerTon(350, .three),
|
||||
filterPressureDrop: 0.1,
|
||||
name: "Test"
|
||||
))
|
||||
|
||||
#expect(result?.flaggedMeasurement == .init(
|
||||
budgets: .init(equipmentType: .airHandler, fanType: .constantSpeed),
|
||||
measurement: measurement,
|
||||
ratedPressures: .init(),
|
||||
tons: .three)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final class FlaggedMeasurementListReducerTests: XCTestCase {
|
||||
|
||||
override func invokeTest() {
|
||||
withDependencies {
|
||||
$0.uuid = .incrementing
|
||||
$0.estimatedPressuresClient = .liveValue
|
||||
} operation: {
|
||||
super.invokeTest()
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func testFlaggedMeasurementListReducer() async throws {
|
||||
@Dependency(\.estimatedPressuresClient) var estimatedPressuresClient
|
||||
|
||||
let store = TestStore(
|
||||
initialState: FlaggedMeasurementsList.State(
|
||||
sharedSettings: Shared(SharedPressureEstimationState(
|
||||
budgets: nil,
|
||||
equipmentMeasurement: .mock(type: .airHandler),
|
||||
equipmentMetadata: .init(
|
||||
coolingCapacity: .three,
|
||||
fanType: .constantSpeed,
|
||||
ratedStaticPressures: .init()
|
||||
)
|
||||
))
|
||||
)
|
||||
) {
|
||||
FlaggedMeasurementsList()
|
||||
}
|
||||
|
||||
let budgets = BudgetedPercentEnvelope(
|
||||
equipmentType: .airHandler,
|
||||
fanType: .constantSpeed
|
||||
)
|
||||
|
||||
let flaggedMeasurement = EquipmentMeasurement.FlaggedMeasurement.init(
|
||||
budgets: budgets,
|
||||
measurement: .mock(type: .airHandler),
|
||||
ratedPressures: .init(),
|
||||
tons: .three
|
||||
)
|
||||
|
||||
await store.send(.view(.onAppear)) {
|
||||
$0.sharedSettings.budgets = budgets
|
||||
$0.sharedSettings.flaggedEquipmentMeasurement = flaggedMeasurement
|
||||
}
|
||||
|
||||
await store.send(.view(.addButtonTapped)) {
|
||||
$0.destination = .estimationForm(.init(
|
||||
existingMeasurement: $0.$sharedSettings.equipmentMeasurement,
|
||||
coolingCapacity: $0.sharedSettings.equipmentMetadata.coolingCapacity
|
||||
))
|
||||
}
|
||||
|
||||
store.exhaustivity = .off
|
||||
|
||||
await store.send(.destination(.presented(.estimationForm(.binding(.set(\.cfmTextField, 350))))))
|
||||
await store.send(.destination(.presented(.estimationForm(.binding(.set(\.name, "Test"))))))
|
||||
await store.send(.destination(.presented(.estimationForm(.binding(.set(\.filterPressureDrop, 0.1))))))
|
||||
|
||||
// store.exhaustivity = .on
|
||||
let pressureResult = try await estimatedPressuresClient.estimatedPressure(
|
||||
equipmentMeasurement: .mock(type: .airHandler),
|
||||
airflow: 1050,
|
||||
filterPressureDrop: 0.1
|
||||
)
|
||||
let flaggedResult = EquipmentMeasurement.FlaggedMeasurement(
|
||||
budgets: budgets,
|
||||
measurement: pressureResult,
|
||||
ratedPressures: .init(),
|
||||
tons: .three
|
||||
)
|
||||
|
||||
store.exhaustivity = .off(showSkippedAssertions: true)
|
||||
// store.exhaustivity = .on
|
||||
|
||||
await store.send(.view(.destination(.doneButtonTapped))) {
|
||||
$0.destination = nil
|
||||
}
|
||||
// await store.receive(\.receive.failure, timeout: 10)
|
||||
// await store.receive(\.receive.success.estimatedFlaggedMeasurement, timeout: 10) {
|
||||
// $0.sharedSettings.flaggedEstimations[id: UUID(0)] = .init(
|
||||
// id: UUID(0),
|
||||
// estimationState: .init(
|
||||
// cfm: .cfmPerTon(350, .three),
|
||||
// filterPressureDrop: 0.1,
|
||||
// name: "Test"
|
||||
// ),
|
||||
// flaggedMeasurement: flaggedResult
|
||||
// )
|
||||
// }
|
||||
//
|
||||
await store.finish()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
extension Tag {
|
||||
@Tag static var flaggedMeasurementList: Self
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user