Cotton code
39 lines · 1.6 KB · SwiftRaw
// The input box, the same everywhere (Spec 7, Cotton note 708fe4fa): what its// row draws in each state, how far it grows, and the editing// row that takes its place while a field is edited. The drawing is walked on// a simulator; what is decided apart from the drawing is held here.import XCTest@testable import CottonUI@MainActorfinal class InputBoxTests: XCTestCase {    private static let lane = "the input box (ws-m5a-bar2)"    private func code(_ path: String) throws -> String {        SourceSweep.withoutComments(try SourceSweep.mustRead(path, ownedBy: Self.lane))    }    // RULE: While a text field on a record's page is edited the editing row knows that field alone, and a field that was left does not take the row from the one edited now.    func testTheEditingRowFollowsTheFieldBeingEdited() {        let editing = FieldEditing()        var title = "Milk"        var left = false        func field(_ id: String) -> FieldEditing.Field {            FieldEditing.Field(                id: id, body: { title }, setBody: { title = $0 }, selection: { nil }, done: { left = true }, speaks: true)        }        XCTAssertNil(editing.field)        editing.began(field("text-title"))        editing.began(field("longtext-notes"))        editing.ended("text-title")        XCTAssertEqual(editing.field?.id, "longtext-notes", "the field left first does not end the one edited now")        editing.field?.setBody("Oat milk")        editing.field?.done()        XCTAssertEqual(title, "Oat milk")        XCTAssertTrue(left)        editing.ended("longtext-notes")        XCTAssertNil(editing.field)    }}