146 lines
6.3 KiB
Swift
146 lines
6.3 KiB
Swift
import HelderCore
|
|
import Testing
|
|
|
|
@Suite struct TerminalContextMenuTests {
|
|
private func labels(_ target: ContextTarget) -> [String] {
|
|
ContextActions.entries(for: target).compactMap { entry in
|
|
guard case let .action(_, label) = entry else { return nil }
|
|
return label
|
|
}
|
|
}
|
|
|
|
@Test func copyAppearsOnlyWithASelection() {
|
|
#expect(labels(.terminal(.agent, hasSelection: true)) == ["Copy", "Paste", "Wait what?"])
|
|
#expect(labels(.terminal(.shell, hasSelection: false)) == ["Paste"])
|
|
}
|
|
|
|
@Test func waitWhatAppearsOnlyForASelectionInTheAgentPane() {
|
|
#expect(!labels(.terminal(.agent, hasSelection: false)).contains("Wait what?"))
|
|
#expect(!labels(.terminal(.shell, hasSelection: true)).contains("Wait what?"))
|
|
}
|
|
|
|
@Test func theActionsNameTheirPane() {
|
|
#expect(ContextActions.entries(for: .terminal(.shell, hasSelection: true)) == [
|
|
.action(.copyTerminalSelection(.shell), label: "Copy"),
|
|
.action(.pasteIntoTerminal(.shell), label: "Paste"),
|
|
])
|
|
}
|
|
|
|
@Test func theMenuHasNoHeader() {
|
|
#expect(ContextActions.header(for: .terminal(.agent, hasSelection: false), projectName: "app").isEmpty)
|
|
#expect(ContextActions.header(for: .directory(path: "src"), projectName: "app").isEmpty)
|
|
}
|
|
}
|
|
|
|
@Suite struct EditorContextMenuTests {
|
|
private let reference = AgentReference(path: "src/a.php", startLine: 12)
|
|
|
|
@Test func theEditorMenuHasNoHeader() {
|
|
#expect(ContextActions.header(for: .editor(reference: reference, code: nil), projectName: "app").isEmpty)
|
|
#expect(ContextActions.header(for: .editor(reference: reference, code: "x", showDiffLine: 12), projectName: "app").isEmpty)
|
|
}
|
|
|
|
@Test func fileGitRowAndRootMenusKeepTheirHeader() {
|
|
#expect(ContextActions.header(for: .file(path: "src/a.php"), projectName: "app") == "src/a.php")
|
|
#expect(ContextActions.header(for: .gitRow(path: "src/a.php", staged: false), projectName: "app") == "src/a.php")
|
|
#expect(ContextActions.header(for: .projectRoot, projectName: "app") == "app/")
|
|
}
|
|
|
|
@Test func aMarkedLineEndsWithShowDiffAtThatLine() {
|
|
#expect(ContextActions.entries(for: .editor(reference: reference, code: nil, showDiffLine: 12)) == [
|
|
.action(.passOnReference("src/a.php:12", code: nil), label: "Pass on reference"),
|
|
.action(.copyReference("src/a.php:12"), label: "Copy reference"),
|
|
.separator,
|
|
.action(.showDiff("src/a.php", line: 12), label: "Show diff"),
|
|
])
|
|
}
|
|
|
|
@Test func anUnchangedLineHasNoShowDiff() {
|
|
#expect(ContextActions.entries(for: .editor(reference: reference, code: nil)) == [
|
|
.action(.passOnReference("src/a.php:12", code: nil), label: "Pass on reference"),
|
|
.action(.copyReference("src/a.php:12"), label: "Copy reference"),
|
|
])
|
|
}
|
|
}
|
|
|
|
@Suite struct BouwenContextMenuTests {
|
|
private func hasBouwen(_ target: ContextTarget) -> Bool {
|
|
ContextActions.entries(for: target).contains { entry in
|
|
guard case .action(.bouwen, _) = entry else { return false }
|
|
return true
|
|
}
|
|
}
|
|
|
|
@Test func anOntwikkelingFolderStartsWithBouwen() {
|
|
let entries = ContextActions.entries(for: .directory(path: "ontwikkelingen/2026-10-02-001-x"))
|
|
#expect(Array(entries.prefix(3)) == [
|
|
.action(.bouwen("2026-10-02-001-x"), label: "Bouwen"),
|
|
.separator,
|
|
.action(.passOnReference("ontwikkelingen/2026-10-02-001-x/", code: nil), label: "Pass on reference"),
|
|
])
|
|
}
|
|
|
|
@Test func otherPathsHaveNoBouwen() {
|
|
#expect(!hasBouwen(.directory(path: "ontwikkelingen")))
|
|
#expect(!hasBouwen(.directory(path: "ontwikkelingen/ontwikkeld")))
|
|
#expect(!hasBouwen(.directory(path: "ontwikkelingen/a/b")))
|
|
#expect(!hasBouwen(.directory(path: "src/ontwikkelingen/a")))
|
|
#expect(!hasBouwen(.file(path: "ontwikkelingen/a")))
|
|
}
|
|
}
|
|
|
|
@Suite struct ReadAloudContextMenuTests {
|
|
private func readAloud(_ target: ContextTarget) -> [ContextMenuEntry] {
|
|
ContextActions.entries(for: target).filter { entry in
|
|
switch entry {
|
|
case .action(.readAloudFile, _), .action(.readAloudText, _): true
|
|
default: false
|
|
}
|
|
}
|
|
}
|
|
|
|
@Test func aMarkdownFileCanBeReadAloud() {
|
|
let entries = ContextActions.entries(for: .file(path: "docs/guide.md"))
|
|
#expect(Array(entries[4...6]) == [
|
|
.separator,
|
|
.action(.readAloudFile("docs/guide.md"), label: "Read aloud"),
|
|
.separator,
|
|
])
|
|
#expect(readAloud(.gitRow(path: "README.md", staged: true)) == [.action(.readAloudFile("README.md"), label: "Read aloud")])
|
|
}
|
|
|
|
@Test func otherFilesCannot() {
|
|
#expect(readAloud(.file(path: "src/app.php")).isEmpty)
|
|
#expect(readAloud(.gitRow(path: "src/app.php", staged: false)).isEmpty)
|
|
#expect(readAloud(.directory(path: "docs")).isEmpty)
|
|
}
|
|
|
|
@Test func aSelectionCanBeReadAloudAfterCopyReference() {
|
|
let reference = AgentReference(path: "src/a.php", startLine: 3, endLine: 4)
|
|
#expect(ContextActions.entries(for: .editor(reference: reference, code: "$a = 1;", showDiffLine: 3)) == [
|
|
.action(.passOnReference("src/a.php:3-4", code: "$a = 1;"), label: "Pass on selection"),
|
|
.action(.copyReference("src/a.php:3-4"), label: "Copy reference"),
|
|
.separator,
|
|
.action(.readAloudText("$a = 1;"), label: "Read aloud selection"),
|
|
.separator,
|
|
.action(.showDiff("src/a.php", line: 3), label: "Show diff"),
|
|
])
|
|
}
|
|
|
|
@Test func noSelectionNoReadAloud() {
|
|
let reference = AgentReference(path: "README.md", startLine: 1)
|
|
#expect(readAloud(.editor(reference: reference, code: nil)).isEmpty)
|
|
#expect(readAloud(.editor(reference: reference, code: "")).isEmpty)
|
|
}
|
|
|
|
@Test func selectedMarkdownIsReadAsProse() {
|
|
let reference = AgentReference(path: "README.md", startLine: 1)
|
|
#expect(readAloud(.editor(reference: reference, code: "## Setup\nRun **this**")) == [
|
|
.action(.readAloudText("Setup.\nRun this."), label: "Read aloud selection"),
|
|
])
|
|
#expect(readAloud(.editor(reference: reference, code: "```\nls\n```")) == [
|
|
.action(.readAloudText("```\nls\n```"), label: "Read aloud selection"),
|
|
])
|
|
}
|
|
}
|