mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add methods to test for previous directory location
This commit is contained in:
parent
436cfe2e2b
commit
2d4e2f5662
3 changed files with 53 additions and 25 deletions
|
|
@ -160,5 +160,30 @@ namespace Flow.Launcher.Plugin.SharedCommands
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
///<summary>
|
||||
/// Gets the previous level directory from a path string.
|
||||
/// Checks that previous level directory exists and returns it
|
||||
/// as a path string, or empty string if doesnt exit
|
||||
///</summary>
|
||||
public static string GetPreviousExistingDirectory(Func<string, bool> locationExists, string path)
|
||||
{
|
||||
var previousDirectoryPath = "";
|
||||
int index = path.LastIndexOf('\\');
|
||||
if (index > 0 && index < (path.Length - 1))
|
||||
{
|
||||
previousDirectoryPath = path.Substring(0, index + 1);
|
||||
if (!locationExists(path))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return previousDirectoryPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@ namespace Flow.Launcher.Test.Plugins
|
|||
|
||||
private bool MethodIndexExistsReturnsFalse(string dummyString) => false;
|
||||
|
||||
private bool LocationExistsReturnsTrue(string dummyString) => true;
|
||||
private bool PreviousLocationExistsReturnsTrue(string dummyString) => true;
|
||||
|
||||
private bool LocationNotExistReturnsFalse(string dummyString) => false;
|
||||
private bool PreviousLocationNotExistReturnsFalse(string dummyString) => false;
|
||||
|
||||
[TestCase("C:\\Dropbox", "directory='file:C:\\Dropbox'")]
|
||||
public void GivenWindowsIndexSearch_WhenProvidedFolderPath_ThenQueryWhereRestrictionsShouldUseDirectoryString(string path, string expectedString)
|
||||
|
|
@ -200,17 +200,30 @@ namespace Flow.Launcher.Test.Plugins
|
|||
|
||||
}
|
||||
|
||||
[TestCase(@"C:\Dropbox\Drop", @"C:\Dropbox")]
|
||||
[TestCase(@"C:\Dropbox\Drop\App", @"C:\Dropbox\Drop")]
|
||||
public void GivenAPartialPath_WhenPreviousLevelDirectoryExists_ThenShouldReturnThePreviousDirectoryPathString()
|
||||
[TestCase(@"C:\Dropbox\Drop", true, @"C:\Dropbox\")]
|
||||
[TestCase(@"C:\Dropbox\Drop\App", true, @"C:\Dropbox\Drop\")]
|
||||
[TestCase(@"C:\Dropbox\Drop", false, "")]
|
||||
public void GivenAPartialPath_WhenPreviousLevelDirectoryExists_ThenShouldReturnThePreviousDirectoryPathString(
|
||||
string path, bool previousDirectoryExists, string expectedString)
|
||||
{
|
||||
// When
|
||||
Func<string, bool> previousLocationExists = null;
|
||||
if (previousDirectoryExists)
|
||||
{
|
||||
previousLocationExists = PreviousLocationExistsReturnsTrue;
|
||||
}
|
||||
else
|
||||
{
|
||||
previousLocationExists = PreviousLocationNotExistReturnsFalse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[TestCase(@"C:\Dropbox\Drop", "")]
|
||||
public void GivenAPartialPath_WhenPreviousLevelDirectoryNotExists_ThenShouldReturnEmptyString()
|
||||
{
|
||||
// Given
|
||||
var previousDirectoryPath = FilesFolders.GetPreviousExistingDirectory(previousLocationExists, path);
|
||||
|
||||
//Then
|
||||
Assert.IsTrue(previousDirectoryPath == expectedString,
|
||||
$"Expected path string: {expectedString} {Environment.NewLine} " +
|
||||
$"Actual path string is {previousDirectoryPath} {Environment.NewLine}");
|
||||
}
|
||||
|
||||
public void GivenWindowsIndexSearch_WhenSearchPatternHotKeyIsSearchAll_ThenQueryWhereRestrictionsShouldUseScopeString() { }
|
||||
|
|
|
|||
|
|
@ -113,22 +113,12 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
if (locationExists(querySearchString))
|
||||
return ResultManager.CreateOpenCurrentFolderResult(querySearchString, false);
|
||||
|
||||
var partialPath = "";
|
||||
int index = querySearchString.LastIndexOf('\\');
|
||||
if (index > 0 && index < (querySearchString.Length - 1))
|
||||
{
|
||||
partialPath = querySearchString.Substring(0, index + 1);
|
||||
if (!locationExists(partialPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var previousDirectoryPath = FilesFolders.GetPreviousExistingDirectory(FilesFolders.LocationExists, querySearchString);
|
||||
|
||||
return ResultManager.CreateOpenCurrentFolderResult(partialPath, true);
|
||||
if (string.IsNullOrEmpty(previousDirectoryPath))
|
||||
return null;
|
||||
|
||||
return ResultManager.CreateOpenCurrentFolderResult(previousDirectoryPath, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue