Update the template screen to use the new(ish) Observation framework. (#4077)

* Update the template screen to use the new(ish) Observation framework.

* Add a variant of deferFulfillment that supports observables.

* Update snapshot fulfilment to work with either a publisher or a stream.
This commit is contained in:
Doug
2025-04-30 16:49:23 +01:00
committed by GitHub
parent 0620bd45fc
commit 61a427b8e5
12 changed files with 297 additions and 25 deletions
@@ -22,13 +22,31 @@ class TemplateScreenViewModelTests: XCTestCase {
}
func testInitialState() {
XCTAssertFalse(context.viewState.placeholder.isEmpty)
XCTAssertFalse(context.composerText.isEmpty)
XCTAssertEqual(context.viewState.counter, 0)
}
func testCounter() async throws {
func testTextField() async throws {
context.composerText = "123"
context.send(viewAction: .textChanged)
XCTAssertEqual(context.composerText, "123")
}
func testCounter() async throws {
var deferred = deferFulfillment(context.observe(\.viewState.counter)) { $0 == 1 }
context.send(viewAction: .incrementCounter)
try await deferred.fulfill()
XCTAssertEqual(context.viewState.counter, 1)
deferred = deferFulfillment(context.observe(\.viewState.counter)) { $0 == 3 }
context.send(viewAction: .incrementCounter)
context.send(viewAction: .incrementCounter)
try await deferred.fulfill()
XCTAssertEqual(context.viewState.counter, 3)
deferred = deferFulfillment(context.observe(\.viewState.counter)) { $0 == 2 }
context.send(viewAction: .decrementCounter)
try await deferred.fulfill()
XCTAssertEqual(context.viewState.counter, 2)
}
}