// What Allow sends from the card for your Claude (shared/DECISIONS.md "Your Claude asks"): Everything sends // `everything: true`; Let me choose sends the groups still ticked, in the card's order, and is refused with none; // no table list decides the grant from an app's own sheet. The card's words are read from `card.ask` whole. import CottonValues import XCTest @testable import CottonUI final class UnlockChoiceTests: XCTestCase { private let ask = UnlockAskWords(.object([ "who": .text("Asha's Claude · connected 3 days ago"), "what": .text("What it can read"), "everything": .object(["label": .text("Only what it asked for"), "line": .text("Notes, Calendar, Messages")]), "choose": .object(["label": .text("Let me choose")]), "groups": .list(["notes", "calendar", "messages"].map { .object(["id": .text($0), "label": .text($0.capitalized), "tables": .list([.text($0)]), "on": .bool(true)]) }), "howLong": .text("For how long"), "howLongLine": .text("When the time is up, it will ask you again."), "settings": .text("You can see or change this any time in Settings, under Your Claude."), ]))! func testTheWordsAreReadWhole() { XCTAssertEqual(ask.who, "Asha's Claude · connected 3 days ago") XCTAssertEqual(ask.everything?.line, "Notes, Calendar, Messages") XCTAssertNil(ask.choose?.line) XCTAssertEqual(ask.groups.map(\.id), ["notes", "calendar", "messages"]) XCTAssertEqual(ask.howLongLine, "When the time is up, it will ask you again.") } func testEverythingSendsEverything() { let request = UnlockChoice().request(ask, requestId: "r1", tables: ["note", "event", "message"], minutes: 15, key: "k") XCTAssertEqual(request.everything, true) XCTAssertNil(request.groups) XCTAssertEqual(request.minutes, 15) } func testChoosingSendsTheGroupsTicked() { var choice = UnlockChoice(choosing: true) choice.off = ["calendar"] XCTAssertTrue(choice.allows(ask)) let request = choice.request(ask, requestId: "r1", tables: ["note", "event", "message"], minutes: 60, key: "k") XCTAssertNil(request.everything) XCTAssertEqual(request.groups, ["notes", "messages"]) } func testChoosingNothingAllowsNothing() { let choice = UnlockChoice(choosing: true, off: ["notes", "calendar", "messages"]) XCTAssertFalse(choice.allows(ask)) XCTAssertTrue(UnlockChoice().allows(ask)) } func testTheRequestSaysOnlyTheChoiceMade() throws { let everything = try JSONSerialization.jsonObject(with: JSONEncoder().encode(UnlockChoice().request(ask, requestId: "r1", tables: [], minutes: 0, key: "k"))) as? [String: Any] XCTAssertEqual(everything?["everything"] as? Bool, true) XCTAssertNil(everything?["groups"], "no groups key when everything is chosen") } }