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
@@ -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)