updates plak menu item

This commit is contained in:
2026-10-28 16:18:03 +01:00
parent 92b90c0e13
commit 9bdda896af
13 changed files with 339 additions and 8 deletions
@@ -10,7 +10,7 @@ import Testing
}
@Test func copyAppearsOnlyWithASelection() {
#expect(labels(.terminal(.agent, hasSelection: true)) == ["Copy", "Paste", "Wait what?"])
#expect(labels(.terminal(.agent, hasSelection: true)) == ["Copy", "Paste", "Read aloud selection", "Plak", "Wait what?"])
#expect(labels(.terminal(.shell, hasSelection: false)) == ["Paste"])
}
@@ -23,9 +23,25 @@ import Testing
#expect(ContextActions.entries(for: .terminal(.shell, hasSelection: true)) == [
.action(.copyTerminalSelection(.shell), label: "Copy"),
.action(.pasteIntoTerminal(.shell), label: "Paste"),
.separator,
.action(.readAloudTerminalSelection(.shell), label: "Read aloud selection"),
.separator,
.action(.plakTerminalSelection(.shell), label: "Plak"),
])
}
@Test func plakAppearsOnlyWithASelectionInBothPanes() {
#expect(labels(.terminal(.agent, hasSelection: true)).contains("Plak"))
#expect(labels(.terminal(.shell, hasSelection: true)).contains("Plak"))
#expect(!labels(.terminal(.agent, hasSelection: false)).contains("Plak"))
#expect(!labels(.terminal(.shell, hasSelection: false)).contains("Plak"))
}
@Test func readAloudAppearsOnlyWithASelection() {
#expect(!labels(.terminal(.agent, hasSelection: false)).contains("Read aloud selection"))
#expect(!labels(.terminal(.shell, hasSelection: false)).contains("Read aloud selection"))
}
@Test func theMenuHasNoHeader() {
#expect(ContextActions.header(for: .terminal(.agent, hasSelection: false), projectName: "app").isEmpty)
#expect(ContextActions.header(for: .directory(path: "src"), projectName: "app").isEmpty)
@@ -123,6 +139,8 @@ import Testing
.separator,
.action(.readAloudText("$a = 1;"), label: "Read aloud selection"),
.separator,
.action(.plak("$a = 1;"), label: "Plak"),
.separator,
.action(.showDiff("src/a.php", line: 3), label: "Show diff"),
])
}
@@ -143,3 +161,24 @@ import Testing
])
}
}
@Suite struct PlakContextMenuTests {
private func plak(_ target: ContextTarget) -> [ContextMenuEntry] {
ContextActions.entries(for: target).filter { entry in
if case .action(.plak, _) = entry { true } else { false }
}
}
@Test func anEditorSelectionIsSentAsRawCode() {
let reference = AgentReference(path: "README.md", startLine: 1)
#expect(plak(.editor(reference: reference, code: "## Setup\nRun **this**")) == [
.action(.plak("## Setup\nRun **this**"), label: "Plak"),
])
}
@Test func noSelectionNoPlak() {
let reference = AgentReference(path: "src/a.php", startLine: 1)
#expect(plak(.editor(reference: reference, code: nil)).isEmpty)
#expect(plak(.editor(reference: reference, code: "")).isEmpty)
}
}
@@ -0,0 +1,35 @@
import Foundation
import HelderCore
import Testing
@Suite struct PlakTests {
private func query(_ text: String) -> String? {
Plak.appendURL(text)?.absoluteString.replacingOccurrences(of: "plak://append?text=", with: "")
}
@Test func spacesAndNewlinesArePercentEncoded() {
#expect(query("a b\nc") == "a%20b%0Ac")
}
@Test func ampersandPlusAndHashAreEncoded() {
#expect(query("a&b+c#d") == "a%26b%2Bc%23d")
}
@Test func theURLTargetsAppend() {
#expect(Plak.appendURL("x")?.absoluteString == "plak://append?text=x")
#expect(Plak.pasteURL.absoluteString == "plak://paste")
}
@Test func shortTextIsAppended() {
#expect(Plak.delivery(for: "hi") == .append(URL(string: "plak://append?text=hi")!))
#expect(Plak.delivery(for: String(repeating: "a", count: Plak.appendLimit)) != .paste)
}
@Test func textOverTheLimitGoesThroughThePasteboard() {
#expect(Plak.delivery(for: String(repeating: "a", count: Plak.appendLimit + 1)) == .paste)
}
@Test func theLimitCountsUTF8Bytes() {
#expect(Plak.delivery(for: String(repeating: "é", count: Plak.appendLimit / 2 + 1)) == .paste)
}
}
@@ -625,7 +625,7 @@ import Testing
Issue.record("no context menu")
return
}
#expect(menuLabels(menu) == ["Copy", "Paste", "Wait what?"])
#expect(menuLabels(menu) == ["Copy", "Paste", "Read aloud selection", "Plak", "Wait what?"])
#expect(menu.header.isEmpty)
#expect(menu.anchor == CGPoint(x: 900, y: 300))
}
@@ -645,6 +645,68 @@ import Testing
#expect(harness.toastTitles == ["Passed to agent"])
}
@Test func readAloudSelectionReadsTheSelectionAsProse() async {
let harness = WorkspaceHarness()
harness.agent.selectedText = " Run **npm test** first.\n"
await harness.perform(.context(.readAloudTerminalSelection(.agent)))
#expect(harness.speech.spoken == ["Run npm test first."])
#expect(harness.model.readAloud.isReading)
}
@Test func readAloudSelectionReadsTheShellSelection() async {
let harness = WorkspaceHarness()
let shell = FakeTerminal()
harness.model.terminal.attach(shell, as: .shell)
shell.selectedText = "```\nls -la\n```"
await harness.perform(.context(.readAloudTerminalSelection(.shell)))
#expect(harness.speech.spoken == ["```\nls -la\n```"])
}
@Test func readAloudSelectionWithBlankTextSaysSo() async {
let harness = WorkspaceHarness()
harness.agent.selectedText = " \n"
await harness.perform(.context(.readAloudTerminalSelection(.agent)))
#expect(harness.speech.spoken.isEmpty)
#expect(harness.toastTitles == ["Nothing to read"])
}
@Test func plakSendsTheTrimmedSelection() async {
let harness = WorkspaceHarness()
harness.agent.selectedText = " npm test\n"
await harness.perform(.context(.plakTerminalSelection(.agent)))
#expect(harness.system.plakked == ["npm test"])
}
@Test func plakSendsTheShellSelection() async {
let harness = WorkspaceHarness()
let shell = FakeTerminal()
harness.model.terminal.attach(shell, as: .shell)
shell.selectedText = "ls -la"
await harness.perform(.context(.plakTerminalSelection(.shell)))
#expect(harness.system.plakked == ["ls -la"])
}
@Test func plakWithBlankSelectionSaysSo() async {
let harness = WorkspaceHarness()
harness.agent.selectedText = " \n"
await harness.perform(.context(.plakTerminalSelection(.agent)))
#expect(harness.system.plakked.isEmpty)
#expect(harness.toastTitles == ["Nothing to send"])
}
@Test func plakSendsTheEditorSelection() async {
let harness = WorkspaceHarness()
await harness.perform(.context(.plak("\n $a = 1;\n")))
#expect(harness.system.plakked == ["$a = 1;"])
}
@Test func plakWithBlankEditorTextSaysSo() async {
let harness = WorkspaceHarness()
await harness.perform(.context(.plak(" \n ")))
#expect(harness.system.plakked.isEmpty)
#expect(harness.toastTitles == ["Nothing to send"])
}
@Test func pasteSendsThePasteboardToThatTerminal() async {
let harness = WorkspaceHarness()
let shell = FakeTerminal()
@@ -660,6 +722,12 @@ import Testing
#expect(ContextMenuOverlay.tint(for: .pasteIntoTerminal(.shell)) == .plain)
#expect(ContextMenuOverlay.symbol(for: .copyTerminalSelection(.agent)) == "doc.on.doc")
#expect(ContextMenuOverlay.symbol(for: .pasteIntoTerminal(.agent)) == "doc.on.clipboard")
#expect(ContextMenuOverlay.tint(for: .readAloudTerminalSelection(.agent)) == .plain)
#expect(ContextMenuOverlay.symbol(for: .readAloudTerminalSelection(.shell)) == "speaker.wave.2")
#expect(ContextMenuOverlay.tint(for: .plakTerminalSelection(.agent)) == .plain)
#expect(ContextMenuOverlay.tint(for: .plak("x")) == .plain)
#expect(ContextMenuOverlay.symbol(for: .plakTerminalSelection(.shell)) == "note.text.badge.plus")
#expect(ContextMenuOverlay.symbol(for: .plak("x")) == "note.text.badge.plus")
}
@Test func aProjectSwitchKeepsTheTerminalMenuWired() async {
@@ -10,6 +10,7 @@ final class FakeSystem: SystemActing {
var clipboard: String?
private(set) var copied: [String] = []
private(set) var revealed: [URL] = []
private(set) var plakked: [String] = []
private(set) var unsavedCloseQuestions: [String] = []
/// Each `openNewInstance` call's folder; nil for the launcher.
private(set) var newInstances: [URL?] = []
@@ -18,6 +19,7 @@ final class FakeSystem: SystemActing {
func copy(_ text: String) { copied.append(text) }
func pasteboardText() -> String? { clipboard }
func revealInFinder(_ url: URL) { revealed.append(url) }
func sendToPlak(_ text: String) { plakked.append(text) }
func confirmUnsavedClose(_ path: String) -> UnsavedCloseChoice {
unsavedCloseQuestions.append(path)