restores Helder in all its glory
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import CoreGraphics
|
||||
import HelderCore
|
||||
@testable import HelderUI
|
||||
import Testing
|
||||
|
||||
@Suite struct ContextMenuTintTests {
|
||||
@Test func addingActionsAreTeal() {
|
||||
#expect(ContextMenuOverlay.tint(for: .newFile(inDirectory: "")) == .add)
|
||||
#expect(ContextMenuOverlay.tint(for: .newFolder(inDirectory: "src")) == .add)
|
||||
#expect(ContextMenuOverlay.tint(for: .stage("a.php")) == .add)
|
||||
}
|
||||
|
||||
@Test func finderUnstageAndCopyFileNameAreAmberSoft() {
|
||||
#expect(ContextMenuOverlay.tint(for: .revealInFinder("a.php")) == .modify)
|
||||
#expect(ContextMenuOverlay.tint(for: .unstage("a.php")) == .modify)
|
||||
#expect(ContextMenuOverlay.tint(for: .copyFileName("a.php")) == .modify)
|
||||
}
|
||||
|
||||
@Test func passOnOpenDiffAndRenameAreGrey() {
|
||||
#expect(ContextMenuOverlay.tint(for: .passOnReference("a.php", code: nil)) == .rename)
|
||||
#expect(ContextMenuOverlay.tint(for: .passOnFileName("a.php")) == .rename)
|
||||
#expect(ContextMenuOverlay.tint(for: .openDiff("a.php")) == .rename)
|
||||
#expect(ContextMenuOverlay.tint(for: .rename("a.php", isDirectory: false)) == .rename)
|
||||
}
|
||||
|
||||
@Test func copyReferenceKeepsThePlainIconThatTurnsAmberOnHighlight() {
|
||||
#expect(ContextMenuOverlay.tint(for: .copyReference("a.php")) == .plain)
|
||||
#expect(MenuIconTint.plain.color == nil)
|
||||
}
|
||||
|
||||
@Test func destructiveActionsAreAmberDeep() {
|
||||
#expect(ContextMenuOverlay.tint(for: .discard("a.php")) == .danger)
|
||||
#expect(ContextMenuOverlay.tint(for: .delete("a", isDirectory: true)) == .danger)
|
||||
}
|
||||
}
|
||||
|
||||
@Suite struct MenuDismissalTests {
|
||||
private let menu = CGRect(x: 100, y: 100, width: 320, height: 200)
|
||||
|
||||
@Test func aClickOutsideTheMenuClosesIt() {
|
||||
#expect(MenuDismissal.closes(clickAt: CGPoint(x: 20, y: 20), menuBounds: menu, sameWindow: true))
|
||||
}
|
||||
|
||||
@Test func aClickOnTheMenuLeavesItOpen() {
|
||||
#expect(!MenuDismissal.closes(clickAt: CGPoint(x: 150, y: 150), menuBounds: menu, sameWindow: true))
|
||||
}
|
||||
|
||||
@Test func aClickInAnotherWindowLeavesItOpen() {
|
||||
#expect(!MenuDismissal.closes(clickAt: CGPoint(x: 20, y: 20), menuBounds: menu, sameWindow: false))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import HelderUI
|
||||
import Testing
|
||||
|
||||
@MainActor
|
||||
@Suite struct NoteStoreTests {
|
||||
@Test func loadsTheNoteThatIsAlreadyOnDisk() async {
|
||||
let store = NoteStore(notes: FakeNotes("earlier thoughts\n"))
|
||||
await store.load()
|
||||
#expect(store.text == "earlier thoughts\n")
|
||||
#expect(!store.isDirty)
|
||||
}
|
||||
|
||||
@Test func nothingIsWrittenWhileTyping() async {
|
||||
let notes = FakeNotes()
|
||||
let store = NoteStore(notes: notes)
|
||||
await store.load()
|
||||
store.text = "buy milk"
|
||||
#expect(notes.writes.isEmpty)
|
||||
#expect(store.isDirty)
|
||||
}
|
||||
|
||||
@Test func savingOnFocusLossWritesTheEditedText() async {
|
||||
let notes = FakeNotes()
|
||||
let store = NoteStore(notes: notes)
|
||||
await store.load()
|
||||
store.text = "buy milk"
|
||||
await store.save()
|
||||
#expect(notes.writes == ["buy milk"])
|
||||
#expect(notes.onDisk == "buy milk")
|
||||
#expect(!store.isDirty)
|
||||
}
|
||||
|
||||
@Test func anUnchangedNoteIsNeverRewritten() async {
|
||||
let notes = FakeNotes("unchanged")
|
||||
let store = NoteStore(notes: notes)
|
||||
await store.load()
|
||||
await store.save()
|
||||
await store.save()
|
||||
#expect(notes.writes.isEmpty)
|
||||
}
|
||||
|
||||
@Test func aFailedWriteLeavesTheNoteDirtyForTheNextTry() async {
|
||||
let notes = FakeNotes()
|
||||
notes.failWrites = true
|
||||
let store = NoteStore(notes: notes)
|
||||
store.text = "keep me"
|
||||
await store.save()
|
||||
#expect(store.isDirty)
|
||||
}
|
||||
|
||||
@Test func passableTextIsTheTrimmedNote() {
|
||||
let store = NoteStore(notes: FakeNotes())
|
||||
store.text = " refactor the policy\n\n"
|
||||
#expect(store.passableText == "refactor the policy")
|
||||
}
|
||||
|
||||
@Test func anEmptyNoteHasNothingToPass() {
|
||||
let store = NoteStore(notes: FakeNotes())
|
||||
store.text = " \n "
|
||||
#expect(store.passableText == nil)
|
||||
}
|
||||
|
||||
@Test func aFailedWriteRaisesAToast() async {
|
||||
let notes = FakeNotes()
|
||||
notes.failWrites = true
|
||||
let store = NoteStore(notes: notes)
|
||||
var toasts: [String?] = []
|
||||
store.notify = { title, detail in toasts.append(title + " " + (detail ?? "")) }
|
||||
store.text = "keep me"
|
||||
#expect(await store.save() == false)
|
||||
#expect(toasts == ["Save failed .notes.txt"])
|
||||
}
|
||||
|
||||
@Test func anOutsideEditReplacesACleanNote() async {
|
||||
let notes = FakeNotes("old")
|
||||
let store = NoteStore(notes: notes)
|
||||
await store.load()
|
||||
notes.setOnDisk("new from the agent")
|
||||
await store.reloadIfClean()
|
||||
#expect(store.text == "new from the agent")
|
||||
#expect(!store.isDirty)
|
||||
}
|
||||
|
||||
@Test func anOutsideEditNeverReplacesUnsavedTyping() async {
|
||||
let notes = FakeNotes("old")
|
||||
let store = NoteStore(notes: notes)
|
||||
await store.load()
|
||||
store.text = "typing"
|
||||
notes.setOnDisk("new from the agent")
|
||||
await store.reloadIfClean()
|
||||
#expect(store.text == "typing")
|
||||
}
|
||||
|
||||
@Test func theFooterCountsCharacters() {
|
||||
let store = NoteStore(notes: FakeNotes())
|
||||
store.text = "héllo"
|
||||
#expect(store.characterCount == 5)
|
||||
}
|
||||
}
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
import Foundation
|
||||
import HelderCore
|
||||
@testable import HelderUI
|
||||
import Testing
|
||||
|
||||
/// Counts how often the file-name ranking runs.
|
||||
@MainActor
|
||||
private final class CountingRanker {
|
||||
var calls = 0
|
||||
|
||||
func rank(_ query: String, _ paths: [String], _ showHidden: Bool) -> [FileNameMatch] {
|
||||
calls += 1
|
||||
return Fuzzy.rankFileNames(query: query, paths: paths, showHidden: showHidden)
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Suite struct SearchComputeOnceTests {
|
||||
private func makeModel(_ ranker: CountingRanker, results: [String: [ContentGroup]] = [:],
|
||||
files: [String] = []) -> SearchModel {
|
||||
let service = FakeSearch(results: results, files: files)
|
||||
return SearchModel(search: service, activePath: "a.php", activeText: "user\nnone",
|
||||
debounce: .milliseconds(20), ranker: { ranker.rank($0, $1, $2) })
|
||||
}
|
||||
|
||||
@Test func aQueryChangeRanksTheFileNamesOnceHoweverOftenTheResultsAreRead() async {
|
||||
let ranker = CountingRanker()
|
||||
let model = makeModel(ranker, files: ["user.php", "user.js", "readme.md"])
|
||||
await model.start()
|
||||
ranker.calls = 0
|
||||
model.setQuery("user")
|
||||
for _ in 0..<5 {
|
||||
_ = model.summary
|
||||
_ = model.extensionChips
|
||||
_ = model.fileMatches
|
||||
_ = model.shownFileMatches
|
||||
_ = model.emptyMessage(for: .files)
|
||||
_ = model.target()
|
||||
}
|
||||
#expect(ranker.calls == 1)
|
||||
}
|
||||
|
||||
@Test func choosingATypeFiltersWithoutRankingAgain() async {
|
||||
let ranker = CountingRanker()
|
||||
let model = makeModel(ranker, files: ["user.php", "user.js"])
|
||||
await model.start()
|
||||
model.setQuery("user")
|
||||
ranker.calls = 0
|
||||
model.toggleExtension("js")
|
||||
#expect(model.fileMatches.map(\.path) == ["user.js"])
|
||||
#expect(ranker.calls == 0)
|
||||
}
|
||||
|
||||
@Test func arrivingContentResultsDoNotRankTheFileNamesAgain() async {
|
||||
let ranker = CountingRanker()
|
||||
let model = makeModel(ranker, results: ["user": [ContentGroup(path: "b.js", hits: [ContentHit(line: 1, text: "user", matchOffset: 0)])]],
|
||||
files: ["user.php"])
|
||||
await model.start()
|
||||
model.setQuery("user")
|
||||
ranker.calls = 0
|
||||
await model.pendingSearch?.value
|
||||
#expect(model.groups.map(\.path) == ["b.js"])
|
||||
#expect(ranker.calls == 0)
|
||||
}
|
||||
|
||||
@Test func theHiddenToggleRanksAgainOnce() async {
|
||||
let ranker = CountingRanker()
|
||||
let model = makeModel(ranker, files: [".env", "env.php"])
|
||||
await model.start()
|
||||
model.setQuery("env")
|
||||
ranker.calls = 0
|
||||
model.showHidden = true
|
||||
#expect(ranker.calls == 1)
|
||||
#expect(Set(model.fileMatches.map(\.path)) == [".env", "env.php"])
|
||||
}
|
||||
|
||||
@Test func theThisFileHitsFollowTheQuery() {
|
||||
let model = makeModel(CountingRanker())
|
||||
model.setQuery("user")
|
||||
#expect(model.inFileHits.map(\.line) == [1])
|
||||
model.setQuery("zzz")
|
||||
#expect(model.inFileHits.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
@Suite struct SearchChipTooltipTests {
|
||||
@Test func aChipSaysHowManyResultsItHasAndWhatAClickDoes() {
|
||||
#expect(SearchModel.chipTooltip(count: 3, isChosen: false) == "3 results · click to show only this type")
|
||||
#expect(SearchModel.chipTooltip(count: 1, isChosen: false) == "1 result · click to show only this type")
|
||||
}
|
||||
|
||||
@Test func theChosenChipOffersEveryTypeBack() {
|
||||
#expect(SearchModel.chipTooltip(count: 2, isChosen: true) == "2 results · click to show every type")
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Test func chipsCarryTheirResultCounts() async {
|
||||
let service = FakeSearch(results: ["user": [ContentGroup(path: "a.php", hits: [ContentHit(line: 1, text: "user", matchOffset: 0)])]],
|
||||
files: ["user.php", "user.js"])
|
||||
let model = SearchModel(search: service, debounce: .milliseconds(20))
|
||||
await model.start()
|
||||
model.setQuery("user")
|
||||
await model.pendingSearch?.value
|
||||
#expect(model.chips == [SearchModel.ExtensionChip(ext: "php", count: 2), SearchModel.ExtensionChip(ext: "js", count: 1)])
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
import Foundation
|
||||
import HelderCore
|
||||
@testable import HelderUI
|
||||
import Testing
|
||||
|
||||
private func group(_ path: String, lines: ClosedRange<Int>) -> ContentGroup {
|
||||
ContentGroup(path: path, hits: lines.map { ContentHit(line: $0, text: "let user = \($0)", matchOffset: 4) })
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func makeModel(results: [String: [ContentGroup]] = [:], delays: [String: Duration] = [:],
|
||||
files: [String] = [], seed: String = "", activePath: String? = nil,
|
||||
activeText: String = "", showHidden: Bool = false) -> (SearchModel, FakeSearch) {
|
||||
let service = FakeSearch(results: results, delays: delays, files: files)
|
||||
let model = SearchModel(search: service, seed: seed, activePath: activePath, activeText: activeText,
|
||||
showHidden: showHidden, debounce: .milliseconds(20))
|
||||
return (model, service)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Suite struct SearchModelTests {
|
||||
@Test func keystrokesWithinTheDebounceRunOnlyTheLastSearch() async {
|
||||
let (model, service) = makeModel(results: ["user": [group("a.php", lines: 1...2)]])
|
||||
model.setQuery("us")
|
||||
model.setQuery("use")
|
||||
model.setQuery("user")
|
||||
await model.pendingSearch?.value
|
||||
#expect(service.contentQueries == ["user"])
|
||||
#expect(model.content.map(\.path) == ["a.php"])
|
||||
}
|
||||
|
||||
@Test func aSlowStaleSearchNeverOverwritesTheNewerResult() async {
|
||||
let (model, service) = makeModel(
|
||||
results: ["ab": [group("old.php", lines: 1...1)], "abc": [group("new.php", lines: 1...1)]],
|
||||
delays: ["ab": .milliseconds(300)]
|
||||
)
|
||||
model.setQuery("ab")
|
||||
#expect(await eventually { service.contentQueries == ["ab"] })
|
||||
model.setQuery("abc")
|
||||
await model.pendingSearch?.value
|
||||
#expect(await eventually { service.answeredQueries.contains("ab") })
|
||||
await Task.yield()
|
||||
#expect(model.content.map(\.path) == ["new.php"])
|
||||
}
|
||||
|
||||
@Test func contentSearchStartsAtTwoCharacters() async {
|
||||
let (model, service) = makeModel()
|
||||
model.setQuery("u")
|
||||
await model.pendingSearch?.value
|
||||
#expect(service.contentQueries.isEmpty)
|
||||
#expect(model.emptyMessage(for: .project) == "Type at least two characters.")
|
||||
}
|
||||
|
||||
@Test func shorteningTheQueryBelowTwoCharactersClearsTheResults() async {
|
||||
let (model, _) = makeModel(results: ["us": [group("a.php", lines: 1...1)]])
|
||||
model.setQuery("us")
|
||||
await model.pendingSearch?.value
|
||||
model.setQuery("u")
|
||||
#expect(model.content.isEmpty)
|
||||
}
|
||||
|
||||
@Test func theSeedIsSearchedWhenTheOverlayStartsAndTheFileListLoads() async {
|
||||
let (model, service) = makeModel(results: ["user": [group("a.php", lines: 1...1)]],
|
||||
files: ["src/UserController.php", "public/store.js"], seed: "user")
|
||||
await model.start()
|
||||
await model.pendingSearch?.value
|
||||
#expect(service.contentQueries == ["user"])
|
||||
#expect(model.shownFileMatches.map(\.path) == ["src/UserController.php"])
|
||||
}
|
||||
|
||||
@Test func eachGroupShowsTwelveLinesButCountsEveryHit() async {
|
||||
let (model, _) = makeModel(results: ["user": [group("a.php", lines: 1...18), group("b.js", lines: 5...7)]])
|
||||
model.setQuery("user")
|
||||
await model.pendingSearch?.value
|
||||
#expect(model.groups.map(\.hitCount) == [18, 3])
|
||||
#expect(model.groups.map(\.rows.count) == [12, 3])
|
||||
#expect(model.hitRows.map(\.index) == Array(0..<15))
|
||||
#expect(model.totalHits == 21)
|
||||
}
|
||||
|
||||
@Test func dotfileHitsStayHiddenUntilTheToggleIsOn() async {
|
||||
let results = ["key": [group(".env", lines: 1...1), group("config/app.php", lines: 2...2)]]
|
||||
let (model, _) = makeModel(results: results, files: [".env", "config/app.php"])
|
||||
await model.start()
|
||||
model.setQuery("key")
|
||||
await model.pendingSearch?.value
|
||||
#expect(model.groups.map(\.path) == ["config/app.php"])
|
||||
model.showHidden = true
|
||||
#expect(model.groups.map(\.path) == [".env", "config/app.php"])
|
||||
}
|
||||
|
||||
@Test func aTypeChipFiltersBothColumnsAndAClickOnItAgainShowsEveryType() async {
|
||||
let results = ["user": [group("a.php", lines: 1...1), group("b.js", lines: 1...1)]]
|
||||
let (model, _) = makeModel(results: results, files: ["user.php", "user.js"])
|
||||
await model.start()
|
||||
model.setQuery("user")
|
||||
await model.pendingSearch?.value
|
||||
#expect(Set(model.extensionChips) == ["php", "js"])
|
||||
model.toggleExtension("js")
|
||||
#expect(model.groups.map(\.path) == ["b.js"])
|
||||
#expect(model.fileMatches.map(\.path) == ["user.js"])
|
||||
model.toggleExtension("js")
|
||||
#expect(model.extensionFilter == nil)
|
||||
#expect(model.groups.count == 2)
|
||||
}
|
||||
|
||||
@Test func aChosenTypeTheNewResultsNoLongerCarryFallsBackToEveryType() async {
|
||||
let results = ["user": [group("a.php", lines: 1...1), group("b.js", lines: 1...1)],
|
||||
"users": [group("a.php", lines: 1...1), group("c.py", lines: 1...1)]]
|
||||
let (model, _) = makeModel(results: results)
|
||||
model.setQuery("user")
|
||||
await model.pendingSearch?.value
|
||||
model.toggleExtension("js")
|
||||
model.setQuery("users")
|
||||
await model.pendingSearch?.value
|
||||
#expect(model.extensionFilter == nil)
|
||||
}
|
||||
|
||||
@Test func thereAreNoChipsForASingleFileType() async {
|
||||
let (model, _) = makeModel(results: ["user": [group("a.php", lines: 1...1)]])
|
||||
model.setQuery("user")
|
||||
await model.pendingSearch?.value
|
||||
#expect(model.extensionChips.isEmpty)
|
||||
}
|
||||
|
||||
@Test func theSummaryCountsThisFileHitsAndFiles() async {
|
||||
let (model, _) = makeModel(results: ["user": [group("a.php", lines: 1...2)]], files: ["User.php"],
|
||||
activePath: "README.md", activeText: "no match here")
|
||||
await model.start()
|
||||
model.setQuery("user")
|
||||
await model.pendingSearch?.value
|
||||
#expect(model.summary == "0 here · 2 hits · 1 file")
|
||||
}
|
||||
|
||||
@Test func withoutAnOpenFileThereIsNoThisFileColumn() {
|
||||
let (model, _) = makeModel()
|
||||
#expect(model.columns == [.project, .files])
|
||||
#expect(!model.summary.contains("here"))
|
||||
}
|
||||
|
||||
@Test func columnMovesStopAtTheEdgesAndStartOnProject() {
|
||||
let (model, _) = makeModel(activePath: "a.php")
|
||||
#expect(model.column == .project)
|
||||
model.moveColumn(by: -1)
|
||||
model.moveColumn(by: -1)
|
||||
#expect(model.column == .thisFile)
|
||||
model.moveColumn(by: 1)
|
||||
model.moveColumn(by: 1)
|
||||
model.moveColumn(by: 1)
|
||||
#expect(model.column == .files)
|
||||
}
|
||||
|
||||
@Test func rowMovesStayInsideTheFocusedColumn() async {
|
||||
let (model, _) = makeModel(results: ["user": [group("a.php", lines: 1...3)]], files: ["user.php", "users.php"])
|
||||
await model.start()
|
||||
model.setQuery("user")
|
||||
await model.pendingSearch?.value
|
||||
model.moveRow(by: 5)
|
||||
#expect(model.projectSelection == 2)
|
||||
model.moveRow(by: -9)
|
||||
#expect(model.projectSelection == 0)
|
||||
model.moveColumn(by: 1)
|
||||
model.moveRow(by: 1)
|
||||
#expect(model.fileSelection == 1)
|
||||
#expect(model.projectSelection == 0)
|
||||
}
|
||||
|
||||
@Test func enterOpensTheSelectedHitAtItsLine() async {
|
||||
let (model, _) = makeModel(results: ["user": [group("a.php", lines: 4...6)]])
|
||||
model.setQuery("user")
|
||||
await model.pendingSearch?.value
|
||||
model.moveRow(by: 1)
|
||||
#expect(model.target() == SearchModel.Target(path: "a.php", line: 5))
|
||||
}
|
||||
|
||||
@Test func enterInTheFilesColumnOpensTheFileWithoutALine() async {
|
||||
let (model, _) = makeModel(files: ["src/UserController.php"])
|
||||
await model.start()
|
||||
model.setQuery("usercon")
|
||||
model.moveColumn(by: 1)
|
||||
#expect(model.target() == SearchModel.Target(path: "src/UserController.php", line: nil))
|
||||
}
|
||||
|
||||
@Test func enterInAnEmptyProjectColumnFallsBackToTheFirstFileName() async {
|
||||
let (model, _) = makeModel(files: ["user.php"])
|
||||
await model.start()
|
||||
model.setQuery("user")
|
||||
await model.pendingSearch?.value
|
||||
#expect(model.target() == SearchModel.Target(path: "user.php", line: nil))
|
||||
}
|
||||
|
||||
@Test func enterInThisFileJumpsToTheLineInTheOpenFile() {
|
||||
let (model, _) = makeModel(seed: "", activePath: "notes.md", activeText: "one\nuser two\nthree user")
|
||||
model.setQuery("user")
|
||||
model.moveColumn(by: -1)
|
||||
model.moveRow(by: 1)
|
||||
#expect(model.inFileHits.map(\.line) == [2, 3])
|
||||
#expect(model.target() == SearchModel.Target(path: "notes.md", line: 3))
|
||||
}
|
||||
|
||||
@Test func aNewQueryResetsEverySelection() async {
|
||||
let (model, _) = makeModel(results: ["user": [group("a.php", lines: 1...3)]])
|
||||
model.setQuery("user")
|
||||
await model.pendingSearch?.value
|
||||
model.moveRow(by: 2)
|
||||
model.setQuery("users")
|
||||
#expect(model.projectSelection == 0)
|
||||
}
|
||||
|
||||
@Test func emptyColumnsSayOnePlainSentence() async {
|
||||
let (model, _) = makeModel(activePath: "a.php", activeText: "nothing")
|
||||
#expect(model.emptyMessage(for: .thisFile) == "Type to search this file.")
|
||||
#expect(model.emptyMessage(for: .files) == "Type to search file names.")
|
||||
model.setQuery("zzz")
|
||||
await model.pendingSearch?.value
|
||||
#expect(model.emptyMessage(for: .thisFile) == "No matches in this file.")
|
||||
#expect(model.emptyMessage(for: .project) == "No content matches.")
|
||||
#expect(model.emptyMessage(for: .files) == "No file names match.")
|
||||
}
|
||||
|
||||
@Test func theFocusedColumnTakesSeventyPercentAndTheSidesKeepTheirMinimum() {
|
||||
let three: [SearchModel.Column] = [.thisFile, .project, .files]
|
||||
let resting = SearchModel.widths(total: 1000, columns: three, focused: .project)
|
||||
#expect(resting[.thisFile] == 230)
|
||||
#expect(resting[.files] == 250)
|
||||
#expect(resting[.project] == 520)
|
||||
let files = SearchModel.widths(total: 1000, columns: three, focused: .files)
|
||||
#expect(files[.files] == 700)
|
||||
#expect(files[.thisFile] == 180)
|
||||
#expect(files[.project] == 120)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user