154 lines
4.8 KiB
Swift
154 lines
4.8 KiB
Swift
import Dependencies
|
|
import Elementary
|
|
import HTMLSnapshotTesting
|
|
import Logging
|
|
import OrderedCollections
|
|
import PsychrometricClientLive
|
|
import Routes
|
|
import SnapshotTesting
|
|
import Testing
|
|
@testable import ViewController
|
|
|
|
@Suite("ViewControllerTests")
|
|
struct ViewControllerTests {
|
|
|
|
let record = SnapshotTestingConfiguration.Record.missing
|
|
let logger = Logger(label: "ViewControllerTests")
|
|
|
|
// swiftlint:disable function_body_length
|
|
@Test
|
|
func snapShotTests() async throws {
|
|
try await withSnapshotTesting(record: record) {
|
|
try await withDependencies {
|
|
$0.viewController = .liveValue
|
|
$0.psychrometricClient = .liveValue
|
|
} operation: {
|
|
@Dependency(\.viewController) var viewController
|
|
|
|
let arguments = OrderedSet([
|
|
// Attic ventilation
|
|
SiteRoute.View.atticVentilation(.index),
|
|
.atticVentilation(.submit(.init(
|
|
pressureDifferential: 1,
|
|
outdoorTemperature: 76,
|
|
outdoorDewpoint: 67,
|
|
atticTemperature: 76,
|
|
atticDewpoint: 76,
|
|
atticFloorArea: 1234
|
|
))),
|
|
|
|
// Capacitor
|
|
.capacitor(.index),
|
|
.capacitor(.index(mode: .size)),
|
|
.capacitor(.index(mode: .test)),
|
|
.capacitor(.submit(.size(.init(runningAmps: 10.7, lineVoltage: 243, powerFactor: 0.86)))),
|
|
.capacitor(.submit(.test(.init(startWindingAmps: 4.3, runToCommonVoltage: 343)))),
|
|
|
|
// Dehumidifier Sizing
|
|
.dehumidifierSize(.index),
|
|
.dehumidifierSize(.submit(.init(latentLoad: 3443, temperature: 76, humidity: 67))),
|
|
|
|
// Filter Pressure Drop
|
|
.filterPressureDrop(.index),
|
|
.filterPressureDrop(.index(mode: .basic)),
|
|
.filterPressureDrop(.index(mode: .fanLaw)),
|
|
.filterPressureDrop(.submit(.basic(.init(
|
|
systemSize: 2,
|
|
climateZone: .hotHumid,
|
|
filterType: .pleatedBest,
|
|
filterWidth: 20,
|
|
filterHeight: 25
|
|
)))),
|
|
.filterPressureDrop(.submit(.fanLaw(.init(
|
|
filterWidth: 20,
|
|
filterHeight: 25,
|
|
filterDepth: 4,
|
|
ratedAirflow: 800,
|
|
ratedPressureDrop: 0.1,
|
|
designAirflow: 900
|
|
)))),
|
|
|
|
// Heating Balance Point
|
|
.heatingBalancePoint(.index),
|
|
.heatingBalancePoint(.heatLossFields(mode: .estimated)),
|
|
.heatingBalancePoint(.heatLossFields(mode: .known)),
|
|
.heatingBalancePoint(.submit(.economic(.init(
|
|
fuelType: .propane,
|
|
fuelCostPerUnit: 2.43,
|
|
fuelAFUE: 90,
|
|
costPerKW: 0.13
|
|
)))),
|
|
.heatingBalancePoint(.submit(.thermal(.init(
|
|
systemSize: 2,
|
|
capacityAt47: 24600,
|
|
capacityAt17: 15100,
|
|
heatingDesignTemperature: 5,
|
|
buildingHeatLoss: .known(btu: 45667),
|
|
climateZone: .five
|
|
)))),
|
|
|
|
// HVAC System Performance
|
|
.hvacSystemPerformance(.index),
|
|
.hvacSystemPerformance(.submit(.init(
|
|
altitude: 800,
|
|
airflow: 800,
|
|
returnAirTemperature: 76,
|
|
returnAirHumidity: 67,
|
|
supplyAirTemperature: 56,
|
|
supplyAirHumidity: 89,
|
|
systemSize: 2
|
|
))),
|
|
|
|
// Mold risk
|
|
.moldRisk(.index),
|
|
.moldRisk(.submit(.init(temperature: 76, humidity: 67))),
|
|
|
|
// Psychrometrics
|
|
.psychrometrics(.index),
|
|
.psychrometrics(.submit(.init(temperature: 76, humidity: 67, altitude: 800))),
|
|
|
|
// Room pressures
|
|
.roomPressure(.index),
|
|
.roomPressure(.index(mode: .measuredPressure)),
|
|
.roomPressure(.submit(.knownAirflow(.init(
|
|
targetRoomPressure: 3,
|
|
doorWidth: 30,
|
|
doorHeight: 86,
|
|
doorUndercut: 1,
|
|
supplyAirflow: 200,
|
|
preferredGrilleHeight: .fourteen
|
|
)))),
|
|
.roomPressure(.submit(.measuredPressure(.init(
|
|
measuredRoomPressure: 4,
|
|
doorWidth: 30,
|
|
doorHeight: 86,
|
|
doorUndercut: 1,
|
|
preferredGrilleHeight: .fourteen
|
|
)))),
|
|
|
|
// Hydronic system pressure
|
|
.hydronicSystemPressure(.index),
|
|
.hydronicSystemPressure(.submit(.init(height: 12, waterTemperature: 60)))
|
|
|
|
])
|
|
|
|
for route in arguments {
|
|
let html = try await viewController.render(route, logger: logger)
|
|
assertSnapshot(of: html, as: .html)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// swiftlint:enable function_body_length
|
|
|
|
}
|
|
|
|
private extension ViewController {
|
|
|
|
func render(_ route: SiteRoute.View, logger: Logger) async throws -> String {
|
|
let html = try await view(.init(route, isHtmxRequest: true, logger: logger))
|
|
return html.renderFormatted()
|
|
}
|
|
}
|