Skip to content

Commit 3f2b741

Browse files
committed
add unit tests for get autocomplete result
1 parent f64ebdc commit 3f2b741

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

Flow.Launcher.Test/Plugins/ExplorerTest.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,5 +329,69 @@ public void GivenFileResult_WhenGetPath_ThenPathShouldBeExpectedString(
329329
// Then
330330
Assert.AreEqual(result, expectedResult);
331331
}
332+
333+
[TestCase("somefolder", "c:\\somefolder\\", ResultType.Folder, "q", false, false, "q somefolder")]
334+
[TestCase("somefolder", "c:\\somefolder\\", ResultType.Folder, "i", true, false, "p c:\\somefolder\\")]
335+
[TestCase("somefolder", "c:\\somefolder\\", ResultType.Folder, "irrelevant", true, true, "c:\\somefolder\\")]
336+
public void GivenQueryWithFolderTypeResult_WhenGetAutoComplete_ThenResultShouldBeExpectedString(
337+
string title,
338+
string path,
339+
ResultType resultType,
340+
string actionKeyword,
341+
bool pathSearchKeywordEnabled,
342+
bool searchActionKeywordEnabled,
343+
string expectedResult)
344+
{
345+
// Given
346+
var query = new Query() { ActionKeyword = actionKeyword };
347+
var settings = new Settings()
348+
{
349+
PathSearchKeywordEnabled = pathSearchKeywordEnabled,
350+
PathSearchActionKeyword = "p",
351+
SearchActionKeywordEnabled = searchActionKeywordEnabled,
352+
SearchActionKeyword = Query.GlobalPluginWildcardSign,
353+
QuickAccessActionKeyword = "q",
354+
IndexSearchActionKeyword = "i"
355+
};
356+
ResultManager.Init(new PluginInitContext(), settings);
357+
358+
// When
359+
var result = ResultManager.GetAutoCompleteText(title, query, path, resultType);
360+
361+
// Then
362+
Assert.AreEqual(result, expectedResult);
363+
}
364+
365+
[TestCase("somefile", "c:\\somefolder\\somefile", ResultType.File, "q", false, false, "q somefile")]
366+
[TestCase("somefile", "c:\\somefolder\\somefile", ResultType.File, "i", true, false, "p c:\\somefolder\\somefile")]
367+
[TestCase("somefile", "c:\\somefolder\\somefile", ResultType.File, "irrelevant", true, true, "c:\\somefolder\\somefile")]
368+
public void GivenQueryWithFileTypeResult_WhenGetAutoComplete_ThenResultShouldBeExpectedString(
369+
string title,
370+
string path,
371+
ResultType resultType,
372+
string actionKeyword,
373+
bool pathSearchKeywordEnabled,
374+
bool searchActionKeywordEnabled,
375+
string expectedResult)
376+
{
377+
// Given
378+
var query = new Query() { ActionKeyword = actionKeyword };
379+
var settings = new Settings()
380+
{
381+
QuickAccessActionKeyword = "q",
382+
IndexSearchActionKeyword = "i",
383+
PathSearchActionKeyword = "p",
384+
PathSearchKeywordEnabled = pathSearchKeywordEnabled,
385+
SearchActionKeywordEnabled = searchActionKeywordEnabled,
386+
SearchActionKeyword = Query.GlobalPluginWildcardSign
387+
};
388+
ResultManager.Init(new PluginInitContext(), settings);
389+
390+
// When
391+
var result = ResultManager.GetAutoCompleteText(title, query, path, resultType);
392+
393+
// Then
394+
Assert.AreEqual(result, expectedResult);
395+
}
332396
}
333397
}

Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static string GetPathWithActionKeyword(string path, ResultType type, stri
4646
return $"{keyword}{formatted_path}";
4747
}
4848

49-
private static string GetAutoCompleteText(string title, Query query, string path, ResultType resultType)
49+
public static string GetAutoCompleteText(string title, Query query, string path, ResultType resultType)
5050
{
5151
return !Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled
5252
? $"{query.ActionKeyword} {title}" // Only Quick Access action keyword is used in this scenario

0 commit comments

Comments
 (0)