restores Helder in all its glory
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
import CoreGraphics
|
||||
import Foundation
|
||||
import HelderCore
|
||||
@testable import HelderUI
|
||||
import Testing
|
||||
|
||||
@Suite struct ShortcutCatalogTests {
|
||||
@Test func theGroupsAreNavigateAgentGitFileInThatOrder() {
|
||||
#expect(ShortcutCatalog.groups.map(\.title) == ["Navigate", "Agent", "Git", "File"])
|
||||
}
|
||||
|
||||
@Test func everyShortcutTheAppHandlesIsListed() {
|
||||
let listed = Set(ShortcutCatalog.groups.flatMap(\.rows).map { $0.keys.joined() })
|
||||
let handled = ["⌘F", "⌘↑↓", "↵", "⌘←→", "↑↓", "⇧⌘O", "⌘O", "⌘→", "⌘N", "⌘P",
|
||||
"⌘C", "⌘↵", "⌘G", "⌘M", "⌘S", "⌘.", "⌘A", "⌘L", "Esc",
|
||||
"⌘W", "⌘R", "⇧⌘N", "?", "⌘click", "⌘0", "⌘+", "⌘−"]
|
||||
#expect(Set(handled).subtracting(listed).isEmpty)
|
||||
}
|
||||
|
||||
@Test func theNewRowsKeepTheOldFourGroups() {
|
||||
func group(of keys: String) -> String? {
|
||||
ShortcutCatalog.groups.first { $0.rows.contains { $0.keys.joined() == keys } }?.title
|
||||
}
|
||||
#expect(group(of: "⇧⌘N") == "Navigate")
|
||||
#expect(group(of: "⌘click") == "Navigate")
|
||||
#expect(group(of: "?") == "Navigate")
|
||||
#expect(group(of: "⌘W") == "File")
|
||||
#expect(group(of: "⌘R") == "File")
|
||||
#expect(["⌘0", "⌘+", "⌘−"].allSatisfy { group(of: $0) == "File" })
|
||||
}
|
||||
|
||||
@Test func everyRowHasKeysAndADescription() {
|
||||
for row in ShortcutCatalog.groups.flatMap(\.rows) {
|
||||
#expect(!row.keys.isEmpty && row.keys.allSatisfy { !$0.isEmpty })
|
||||
#expect(!row.label.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func theNotePassOnSitsInTheAgentGroup() {
|
||||
let agent = ShortcutCatalog.groups.first { $0.title == "Agent" }
|
||||
#expect(agent?.rows.contains(ShortcutRow(keys: ["⌘", "P"], label: "Pass on the whole note")) == true)
|
||||
}
|
||||
}
|
||||
|
||||
@Suite struct ListCursorTests {
|
||||
@Test func movesStopAtBothEnds() {
|
||||
#expect(ListCursor.step(0, by: -1, count: 3) == 0)
|
||||
#expect(ListCursor.step(2, by: 1, count: 3) == 2)
|
||||
#expect(ListCursor.step(1, by: 1, count: 3) == 2)
|
||||
#expect(ListCursor.step(4, by: 0, count: 0) == 0)
|
||||
}
|
||||
|
||||
@Test func commandDownStartsOnThePreviousFileAndCommandUpOnTheCurrentOne() {
|
||||
#expect(ListCursor.recentFilesStart(movingDown: true, count: 5) == 1)
|
||||
#expect(ListCursor.recentFilesStart(movingDown: true, count: 1) == 0)
|
||||
#expect(ListCursor.recentFilesStart(movingDown: false, count: 5) == 0)
|
||||
}
|
||||
}
|
||||
|
||||
@Suite struct MenuCursorTests {
|
||||
private let entries: [ContextMenuEntry] = [
|
||||
.action(.copyReference("a"), label: "Copy reference"),
|
||||
.separator,
|
||||
.action(.rename("a", isDirectory: false), label: "Rename file"),
|
||||
.action(.delete("a", isDirectory: false), label: "Delete file"),
|
||||
]
|
||||
|
||||
@Test func theFirstItemIsPreHighlighted() {
|
||||
#expect(MenuCursor.first(in: [.separator] + entries) == 1)
|
||||
}
|
||||
|
||||
@Test func arrowsSkipSeparatorsAndWrapAround() {
|
||||
#expect(MenuCursor.step(0, by: 1, in: entries) == 2)
|
||||
#expect(MenuCursor.step(2, by: -1, in: entries) == 0)
|
||||
#expect(MenuCursor.step(3, by: 1, in: entries) == 0)
|
||||
#expect(MenuCursor.step(0, by: -1, in: entries) == 3)
|
||||
}
|
||||
}
|
||||
|
||||
@Suite struct NamePromptTextTests {
|
||||
@Test func aNewFilePreviewsItsPathInTheFolder() {
|
||||
let text = NamePromptText(NamePromptRequest(purpose: .newFile(inDirectory: "src"), anchor: .zero))
|
||||
#expect(text.title == "New file")
|
||||
#expect(text.preview(for: " a.php ") == "src/a.php")
|
||||
#expect(text.preview(for: "") == "…")
|
||||
#expect(!text.canSubmit(" "))
|
||||
}
|
||||
|
||||
@Test func aNewFolderPreviewEndsInASlash() {
|
||||
let text = NamePromptText(NamePromptRequest(purpose: .newFolder(inDirectory: ""), anchor: .zero))
|
||||
#expect(text.title == "New folder")
|
||||
#expect(text.preview(for: "docs") == "docs/")
|
||||
}
|
||||
|
||||
@Test func aRenameSelectsTheStemAndRefusesTheSameName() {
|
||||
let request = NamePromptRequest(purpose: .rename(path: "docs/notes.md", isDirectory: false),
|
||||
initialName: "notes.md", anchor: .zero)
|
||||
let text = NamePromptText(request)
|
||||
#expect(text.title == "Rename file")
|
||||
#expect(text.previewLabel == "renames to")
|
||||
#expect(text.initialSelection == NSRange(location: 0, length: 5))
|
||||
#expect(!text.canSubmit("notes.md"))
|
||||
#expect(text.canSubmit("todo.md"))
|
||||
#expect(text.preview(for: "todo.md") == "docs/todo.md")
|
||||
}
|
||||
|
||||
@Test func aDotfileRenameSelectsTheWholeName() {
|
||||
let request = NamePromptRequest(purpose: .rename(path: ".env", isDirectory: false), initialName: ".env", anchor: .zero)
|
||||
#expect(NamePromptText(request).initialSelection == NSRange(location: 0, length: 4))
|
||||
}
|
||||
}
|
||||
|
||||
@Suite struct SearchHighlightTests {
|
||||
@Test func theMatchRunCoversTheQueryLengthFromTheHitOffset() {
|
||||
let hit = ContentHit(line: 6, text: "use App\\UserRepository;", matchOffset: 8)
|
||||
let line = SearchHighlight.line(hit, length: 4, selected: true)
|
||||
let runs = line.runs.map { String(line[$0.range].characters) }
|
||||
#expect(runs == ["use App\\", "User", "Repository;"])
|
||||
}
|
||||
|
||||
@Test func anOffsetPastTheLineIsClamped() {
|
||||
let hit = ContentHit(line: 1, text: "abc", matchOffset: 99)
|
||||
let line = SearchHighlight.line(hit, length: 4, selected: false)
|
||||
#expect(String(line.characters) == "abc")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user