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