207 lines
9.1 KiB
Swift
207 lines
9.1 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", "Read aloud selection", "Plak", "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"),
|
|
.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)
|
|
}
|
|
}
|
|
|
|
@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", isDeleted: 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,
|
|
])
|
|
}
|
|
|
|
@Test func otherFilesCannot() {
|
|
#expect(readAloud(.file(path: "src/app.php")).isEmpty)
|
|
#expect(readAloud(.directory(path: "docs")).isEmpty)
|
|
}
|
|
|
|
@Test func aGitRowOpensInTheEditorThenPassesOnItsPath() {
|
|
#expect(ContextActions.entries(for: .gitRow(path: "src/a.php", isDeleted: false)) == [
|
|
.action(.openFile("src/a.php"), label: "Open in editor"),
|
|
.separator,
|
|
.action(.passOnReference("src/a.php", code: nil), label: "Pass on reference"),
|
|
.action(.copyReference("src/a.php"), label: "Copy reference"),
|
|
])
|
|
#expect(ContextActions.entries(for: .gitRow(path: "gone.php", isDeleted: true)) == [
|
|
.action(.passOnReference("gone.php", code: nil), label: "Pass on reference"),
|
|
.action(.copyReference("gone.php"), label: "Copy reference"),
|
|
])
|
|
#expect(ContextAction.openFile("src/a.php").isEmphasized)
|
|
}
|
|
|
|
@Test func theCommitMenuOffersCommitAndABoldCommitAndPush() {
|
|
#expect(ContextActions.header(for: .commitMenu, projectName: "app") == "")
|
|
#expect(ContextActions.entries(for: .commitMenu) == [
|
|
.action(.commit(andPush: false), label: "Commit"),
|
|
.action(.commit(andPush: true), label: "Commit and push"),
|
|
])
|
|
#expect(ContextAction.commit(andPush: true).isEmphasized)
|
|
#expect(!ContextAction.commit(andPush: false).isEmphasized)
|
|
}
|
|
|
|
@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(.plak("$a = 1;"), label: "Plak"),
|
|
.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"),
|
|
])
|
|
}
|
|
}
|
|
|
|
@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)
|
|
}
|
|
}
|