Cotton code
59 lines · 3.8 KB · SwiftRaw
import XCTest@testable import CottonUI/// Every toast in a redesigned app is drawn in that app's own look, once (22 Nov 2026). On the/// owner's iPhone, approving a device in Comms drew "Approved. … is signing in." twice at once: the window's receipt/// overlay hung outside the app look and drew the old paper strip, while the stack's, inside it, drew the look.final class AppToastTests: XCTestCase {    private func source(_ path: String) throws -> String {        SourceSweep.withoutComments(try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/" + path, ownedBy: "chat-warm-ios"))    }    /// RULE: Words, Days, Story and Comms draw the shell's lines in their own toast; every other app has none of its own.    func testTheRedesignedAppsDrawTheirOwnToast() {        XCTAssertEqual(AppToast.of(flavour: "notes"), .words)        XCTAssertEqual(AppToast.of(flavour: "notes-dev"), .words)        XCTAssertEqual(AppToast.of(flavour: "days"), .days)        XCTAssertEqual(AppToast.of(flavour: "story"), .story)        XCTAssertEqual(AppToast.of(flavour: "messages"), .comms)        for paper in ["books", "music", "cinemas", "keys", "health", "photos", "", nil] as [String?] {            XCTAssertNil(AppToast.of(flavour: paper), "\(paper ?? "nil") keeps its own receipt")        }        XCTAssertEqual(Set(AppToast.allCases.map(\.identifier)), ["toast-words", "toast-days", "toast-story", "toast-comms"])    }    /// RULE: one overlay per presentation draws a line: the window's, and a cover's over its cover; one beneath another stays quiet.    func testALineIsDrawnByOneOverlayAPresentation() {        XCTAssertTrue(ToastKnobs.draws(cover: false, hungAbove: false), "the window's overlay draws")        XCTAssertFalse(ToastKnobs.draws(cover: false, hungAbove: true), "the stack's, beneath it, stays quiet")        XCTAssertTrue(ToastKnobs.draws(cover: true, hungAbove: true), "a cover's draws over the cover the window's stands under")    }    /// RULE: the receipt overlay hands an app with a toast of its own the words before anything else is asked, so the    /// paper strip is never built there; the root says which app it is beside the look.    func testTheOverlayHandsTheAppItsWords() throws {        let toast = try source("Chrome/Toast.swift")        let own = try XCTUnwrap(toast.range(of: "if let appToast {"))        let strip = try XCTUnwrap(toast.range(of: "ToastStrip(toast: toast"))        XCTAssertLessThan(own.lowerBound, strip.lowerBound, "the app's toast is asked for first")        let root = try source("Boot/RootView.swift")        XCTAssertTrue(root.contains(".environment(\\.appToast, AppToast.standing)"), "the root says which app draws its own toast")        let window = try XCTUnwrap(root.range(of: ".cottonToasts(toasts)"))        let app = try XCTUnwrap(root.range(of: ".environment(\\.appToast, AppToast.standing)"))        XCTAssertLessThan(window.lowerBound, app.lowerBound, "the window's overlay stands inside it")    }    /// RULE: a whole-screen cover in Comms and Words (a conversation, a note) draws the shell's lines over itself:    /// the window's overlay stands under the cover, where nobody sees it.    func testCoversDrawTheLinesOverThemselves() throws {        for path in ["Chat/ChatList.swift", "Chat/ChatThread.swift", "Chat/ChatNew.swift", "Chat/ChatGroup.swift", "Notes/NotesHome.swift"] {            let text = try source(path)            let covers = text.components(separatedBy: ".fullScreenCover(").count - 1            let drawn = text.components(separatedBy: ".receiptsOverCover()").count - 1            XCTAssertGreaterThan(covers, 0, path)            XCTAssertEqual(drawn, covers, "\(path): every cover draws the shell's lines over itself")        }        XCTAssertTrue(try source("Chrome/WholeScreen.swift").contains("cottonToastsOverCover(toasts)"))    }}