86 lines
3.7 KiB
Swift
86 lines
3.7 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"])
|
|
#expect(labels(.terminal(.shell, hasSelection: false)) == ["Paste"])
|
|
}
|
|
|
|
@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")))
|
|
}
|
|
}
|