Cotton code
45 lines · 2.0 KB · SwiftRaw
// A fan's pictures are drawn after the body that asked for them// (`FanPrints`): a card whose picture is not drawn yet stands empty until the// fan is drawn again. Holding This device opened a fan whose acts arrived// after it (the held card's acts, `shell.opened`): its cards were never drawn again, and the fan// stood empty with only its X (door walk, 24 Oct 2026).#if os(iOS)import Observationimport SwiftUIimport XCTest@testable import CottonUI@MainActorfinal class FanPrintsTests: XCTestCase {    /// Whether the observation's change was told.    private final class Told: @unchecked Sendable {        var told = false    }    /// RULE: A view that asked for a picture not drawn yet is drawn again once it is — a fan's cards that arrive after the fan opened (This device's acts, the Export fan's tables) are never left empty.    func testAskingForAnUndrawnPictureRedrawsTheAskerOnceItIsDrawn() {        let prints = FanPrints<String>()        let redrawn = Told()        let asked = withObservationTracking {            prints.picture("command-sync_now", "Sync now")        } onChange: {            redrawn.told = true        }        XCTAssertNil(asked)        prints.draw("command-sync_now", "Sync now", scale: 1, environment: EnvironmentValues(),                    content: Color.red.frame(width: 4, height: 4))        XCTAssertTrue(redrawn.told, "the body that found no picture is told when it is drawn")        XCTAssertNotNil(prints.picture("command-sync_now", "Sync now"))    }    /// RULE: A picture drawn for another look of its item is not shown: the card is drawn again for the look it has now.    func testAPictureOfAnotherLookIsNotShown() {        let prints = FanPrints<String>()        prints.draw("act-status", "lit", scale: 1, environment: EnvironmentValues(),                    content: Color.red.frame(width: 4, height: 4))        XCTAssertNil(prints.picture("act-status", "unlit"))        XCTAssertNotNil(prints.picture("act-status", "lit"))    }}#endif