Add regression test for command preview corpus
This commit is contained in:
parent
23910dea9a
commit
fdf2212c88
2 changed files with 55 additions and 0 deletions
|
|
@ -3434,6 +3434,25 @@ struct ContentView: View {
|
|||
return Array(matches.prefix(resultLimit))
|
||||
}
|
||||
|
||||
nonisolated static func commandPaletteCommandPreviewMatchCommandIDsForTests(
|
||||
searchCorpus: [CommandPaletteSearchCorpusEntry<String>],
|
||||
candidateCommandIDs: [String],
|
||||
searchCorpusByID: [String: CommandPaletteSearchCorpusEntry<String>],
|
||||
query: String,
|
||||
resultLimit: Int
|
||||
) -> [String] {
|
||||
let preparedQuery = CommandPaletteFuzzyMatcher.preparedQuery(query)
|
||||
return commandPalettePreviewSearchMatches(
|
||||
candidateCommandIDs: candidateCommandIDs,
|
||||
searchCorpusByID: searchCorpusByID,
|
||||
query: query,
|
||||
usageHistory: [:],
|
||||
queryIsEmpty: preparedQuery.isEmpty,
|
||||
historyTimestamp: 0,
|
||||
resultLimit: resultLimit
|
||||
).map(\.commandID)
|
||||
}
|
||||
|
||||
private func scheduleCommandPaletteResultsRefresh(forceSearchCorpusRefresh: Bool = false) {
|
||||
refreshCommandPaletteSearchCorpus(force: forceSearchCorpusRefresh)
|
||||
|
||||
|
|
|
|||
|
|
@ -219,6 +219,42 @@ final class CommandPaletteSearchEngineTests: XCTestCase {
|
|||
XCTAssertGreaterThanOrEqual(cancellationChecks, 4)
|
||||
}
|
||||
|
||||
func testCommandPreviewSearchUsesFullCommandCorpus() {
|
||||
let entries = [
|
||||
FixtureEntry(
|
||||
id: "command.find",
|
||||
rank: 0,
|
||||
title: "Find...",
|
||||
searchableTexts: ["Find...", "Search", "find", "search"]
|
||||
),
|
||||
FixtureEntry(
|
||||
id: "command.finder",
|
||||
rank: 1,
|
||||
title: "Open Current Directory in Finder",
|
||||
searchableTexts: ["Open Current Directory in Finder", "Terminal", "finder", "directory", "open"]
|
||||
),
|
||||
]
|
||||
let corpus = entries.map { entry in
|
||||
CommandPaletteSearchCorpusEntry(
|
||||
payload: entry.id,
|
||||
rank: entry.rank,
|
||||
title: entry.title,
|
||||
searchableTexts: entry.searchableTexts
|
||||
)
|
||||
}
|
||||
let corpusByID = Dictionary(uniqueKeysWithValues: corpus.map { ($0.payload, $0) })
|
||||
|
||||
let previewCommandIDs = ContentView.commandPaletteCommandPreviewMatchCommandIDsForTests(
|
||||
searchCorpus: corpus,
|
||||
candidateCommandIDs: ["command.find"],
|
||||
searchCorpusByID: corpusByID,
|
||||
query: "finde",
|
||||
resultLimit: 48
|
||||
)
|
||||
|
||||
XCTAssertEqual(previewCommandIDs.first, "command.finder")
|
||||
}
|
||||
|
||||
func testResolvedSelectionIndexPrefersAnchoredCommand() {
|
||||
let resultIDs = ["command.0", "command.1", "command.2"]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue