feat: Begins adding html snapshot tests.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import Dependencies
|
||||
import Elementary
|
||||
import HTMLSnapshotTesting
|
||||
import Logging
|
||||
import OrderedCollections
|
||||
import Routes
|
||||
import SnapshotTesting
|
||||
import Testing
|
||||
@testable import ViewController
|
||||
|
||||
@Suite("ViewControllerTests")
|
||||
struct ViewControllerTests {
|
||||
|
||||
let record = SnapshotTestingConfiguration.Record.missing
|
||||
let logger = Logger(label: "ViewControllerTests")
|
||||
|
||||
@Test
|
||||
func snapShotTests() async throws {
|
||||
try await withSnapshotTesting(record: record) {
|
||||
try await withDependencies {
|
||||
$0.viewController = .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
|
||||
))))
|
||||
])
|
||||
|
||||
for route in arguments {
|
||||
let html = try await viewController.render(route, logger: logger)
|
||||
assertSnapshot(of: html, as: .html)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user