Cotton code
44 lines · 3.1 KB · SwiftRaw
import CottonValuesimport XCTest@testable import CottonUI/// RULE: a conversation's own screen mounts its composer only where the thread takes words from here (`takesWords`, as the record page does), because an email archive said "Nothing is sent from here" over a composer offering to send (real-data walk, 23 Oct 2026).final class ArchiveHasNoComposerTests: XCTestCase {    func testTheChatScreenGatesItsComposer() throws {        let route = SourceSweep.withoutComments(            try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Surfaces/ConversationRoute.swift", ownedBy: "faces"))            .filter { !$0.isWhitespace }        // Two composers since Cotton chat (978909fec): a Cotton thread's own        // CottonChatComposer and every other thread's ConversationComposer,        // each behind its own gate.        let gated = route.components(separatedBy: "takesWords(definition,layout,record){").dropFirst()        XCTAssertEqual(gated.count, 2, "one gate per composer")        for composer in ["CottonChatComposer(", "ConversationComposer("] {            XCTAssertEqual(gated.filter { $0.hasPrefix(composer) }.count, 1, "\(composer) stands behind the gate")            XCTAssertEqual(route.components(separatedBy: composer).count, 2, "one \(composer), the gated one")        }        XCTAssertTrue(route.contains("record.said?.readOnly!=true&&layout.takesWords(on:record)"), "the gate is the record page's")        XCTAssertTrue(route.contains("navigator?.carries(composer:true,on:screenRoute)"), "every chat puts Home's command mic away, including archives")    }    func testTheHeaderUsesTheShellTitleAndAnEmptyMessageHasNoBubble() throws {        let route = SourceSweep.withoutComments(try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Surfaces/ConversationRoute.swift", ownedBy: "faces"))        XCTAssertTrue(route.contains("PaperScreen(title: record.flatMap"))        XCTAssertTrue(route.contains("showsTitle: false"))        XCTAssertFalse(route.contains("NavCircle("), "the shell owns Close")        let page = SourceSweep.withoutComments(try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Surfaces/PageStyles/ConversationPage.swift", ownedBy: "faces"))        XCTAssertTrue(page.contains("let wordless = item.words.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty"))        XCTAssertFalse(page.contains("Divider("))    }    /// RULE: a message keeps its time: in its note when it has words and no    /// media, on its own line after the media, and on its own line under its    /// name when it holds no words — media or not (an empty message without    /// media lost its time, a9f2712af1).    func testEveryMessageKeepsItsTime() {        XCTAssertFalse(ConversationPage.timeStandsAlone(wordless: false, media: false), "the note carries it")        XCTAssertTrue(ConversationPage.timeStandsAlone(wordless: false, media: true), "after the media")        XCTAssertTrue(ConversationPage.timeStandsAlone(wordless: true, media: true), "after the media")        XCTAssertTrue(ConversationPage.timeStandsAlone(wordless: true, media: false), "under the name, with no media to follow")    }}