2020-08-06 05:06:55 +08:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2020-07-21 02:22:03 +08:00
|
|
|
|
using PowerLauncher.ViewModel;
|
2020-07-03 09:29:39 +08:00
|
|
|
|
|
|
|
|
|
namespace Wox.Test
|
|
|
|
|
{
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestClass]
|
|
|
|
|
public class MainViewModelTest
|
2020-07-03 09:29:39 +08:00
|
|
|
|
{
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MainViewModelGetAutoCompleteTextReturnsEmptyStringWhenInputIsNull()
|
2020-07-03 09:29:39 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
int index = 0;
|
|
|
|
|
string input = null;
|
2020-08-11 06:49:36 +08:00
|
|
|
|
string query = "M";
|
2020-07-03 09:29:39 +08:00
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
string autoCompleteText = MainViewModel.GetAutoCompleteText(index, input, query);
|
2020-07-23 04:27:17 +08:00
|
|
|
|
|
2020-07-03 09:29:39 +08:00
|
|
|
|
// Assert
|
2020-10-08 04:12:59 +08:00
|
|
|
|
Assert.AreEqual(string.Empty, autoCompleteText);
|
2020-07-03 09:29:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MainViewModelGetAutoCompleteTextReturnsEmptyStringWhenInputIsEmpty()
|
2020-07-03 09:29:39 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
int index = 0;
|
|
|
|
|
string input = string.Empty;
|
2020-08-11 06:49:36 +08:00
|
|
|
|
string query = "M";
|
2020-07-03 09:29:39 +08:00
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
string autoCompleteText = MainViewModel.GetAutoCompleteText(index, input, query);
|
|
|
|
|
|
|
|
|
|
// Assert
|
2020-10-08 04:12:59 +08:00
|
|
|
|
Assert.AreEqual(string.Empty, autoCompleteText);
|
2020-07-03 09:29:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MainViewModelGetAutoCompleteTextReturnsEmptyStringWhenQueryIsNull()
|
2020-07-03 09:29:39 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
int index = 0;
|
|
|
|
|
string input = "M";
|
2020-08-11 06:49:36 +08:00
|
|
|
|
string query = null;
|
2020-07-03 09:29:39 +08:00
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
string autoCompleteText = MainViewModel.GetAutoCompleteText(index, input, query);
|
|
|
|
|
|
|
|
|
|
// Assert
|
2020-10-08 04:12:59 +08:00
|
|
|
|
Assert.AreEqual(string.Empty, autoCompleteText);
|
2020-07-03 09:29:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MainViewModelGetAutoCompleteTextReturnsEmptyStringWhenQueryIsEmpty()
|
2020-07-03 09:29:39 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
int index = 0;
|
|
|
|
|
string input = "M";
|
2020-08-11 06:49:36 +08:00
|
|
|
|
string query = string.Empty;
|
2020-07-03 09:29:39 +08:00
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
string autoCompleteText = MainViewModel.GetAutoCompleteText(index, input, query);
|
|
|
|
|
|
|
|
|
|
// Assert
|
2020-10-08 04:12:59 +08:00
|
|
|
|
Assert.AreEqual(string.Empty, autoCompleteText);
|
2020-07-03 09:29:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MainViewModelGetAutoCompleteTextReturnsEmptyStringWhenIndexIsNonZero()
|
2020-07-03 09:29:39 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
int index = 2;
|
|
|
|
|
string input = "Visual";
|
2020-08-11 06:49:36 +08:00
|
|
|
|
string query = "Vis";
|
2020-07-03 09:29:39 +08:00
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
string autoCompleteText = MainViewModel.GetAutoCompleteText(index, input, query);
|
|
|
|
|
|
|
|
|
|
// Assert
|
2020-10-08 04:12:59 +08:00
|
|
|
|
Assert.AreEqual(string.Empty, autoCompleteText);
|
2020-07-03 09:29:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MainViewModelGetAutoCompleteTextReturnsMatchingStringWhenIndexIsZeroAndMatch()
|
2020-07-03 09:29:39 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
int index = 0;
|
|
|
|
|
string input = "VISUAL";
|
2020-08-11 06:49:36 +08:00
|
|
|
|
string query = "VIs";
|
|
|
|
|
string expectedAutoCompleteText = "VIsUAL";
|
2020-07-03 09:29:39 +08:00
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
string autoCompleteText = MainViewModel.GetAutoCompleteText(index, input, query);
|
|
|
|
|
|
|
|
|
|
// Assert
|
2020-10-08 04:12:59 +08:00
|
|
|
|
Assert.AreEqual(expectedAutoCompleteText, autoCompleteText);
|
2020-07-03 09:29:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MainViewModelGetAutoCompleteTextReturnsEmptyStringWhenIndexIsZeroAndNoMatch()
|
2020-07-03 09:29:39 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
int index = 0;
|
|
|
|
|
string input = "VISUAL";
|
2020-08-11 06:49:36 +08:00
|
|
|
|
string query = "Vim";
|
|
|
|
|
string expectedAutoCompleteText = string.Empty;
|
2020-07-03 09:29:39 +08:00
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
string autoCompleteText = MainViewModel.GetAutoCompleteText(index, input, query);
|
|
|
|
|
|
|
|
|
|
// Assert
|
2020-10-08 04:12:59 +08:00
|
|
|
|
Assert.AreEqual(expectedAutoCompleteText, autoCompleteText);
|
2020-07-03 09:29:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MainViewModelGetSearchTextReturnsEmptyStringWhenInputIsNull()
|
2020-07-03 09:29:39 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
int index = 0;
|
|
|
|
|
string input = null;
|
2020-08-11 06:49:36 +08:00
|
|
|
|
string query = "M";
|
2020-07-03 09:29:39 +08:00
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
string autoCompleteText = MainViewModel.GetSearchText(index, input, query);
|
|
|
|
|
|
|
|
|
|
// Assert
|
2020-10-08 04:12:59 +08:00
|
|
|
|
Assert.AreEqual(string.Empty, autoCompleteText);
|
2020-07-03 09:29:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MainViewModelGetSearchTextReturnsEmptyStringWhenInputIsEmpty()
|
2020-07-03 09:29:39 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
int index = 0;
|
|
|
|
|
string input = string.Empty;
|
2020-08-11 06:49:36 +08:00
|
|
|
|
string query = "M";
|
2020-07-03 09:29:39 +08:00
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
string autoCompleteText = MainViewModel.GetSearchText(index, input, query);
|
|
|
|
|
|
|
|
|
|
// Assert
|
2020-10-08 04:12:59 +08:00
|
|
|
|
Assert.AreEqual(string.Empty, autoCompleteText);
|
2020-07-03 09:29:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MainViewModelGetSearchTextReturnsInputStringWhenQueryIsNull()
|
2020-07-03 09:29:39 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
int index = 0;
|
|
|
|
|
string input = "Visual";
|
2020-08-11 06:49:36 +08:00
|
|
|
|
string query = null;
|
2020-07-03 09:29:39 +08:00
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
string autoCompleteText = MainViewModel.GetSearchText(index, input, query);
|
|
|
|
|
|
|
|
|
|
// Assert
|
2020-10-08 04:12:59 +08:00
|
|
|
|
Assert.AreEqual(input, autoCompleteText);
|
2020-07-03 09:29:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MainViewModelGetSearchTextReturnsInputStringWhenQueryIsEmpty()
|
2020-07-03 09:29:39 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
int index = 0;
|
|
|
|
|
string input = "Visual";
|
2020-08-11 06:49:36 +08:00
|
|
|
|
string query = string.Empty;
|
2020-07-03 09:29:39 +08:00
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
string autoCompleteText = MainViewModel.GetSearchText(index, input, query);
|
|
|
|
|
|
|
|
|
|
// Assert
|
2020-10-08 04:12:59 +08:00
|
|
|
|
Assert.AreEqual(input, autoCompleteText);
|
2020-07-03 09:29:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MainViewModelGetSearchTextReturnsMatchingStringWithCaseWhenIndexIsZeroAndMatch()
|
2020-07-03 09:29:39 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
int index = 0;
|
|
|
|
|
string input = "VISUAL";
|
2020-08-11 06:49:36 +08:00
|
|
|
|
string query = "VIs";
|
|
|
|
|
string expectedAutoCompleteText = "VIsUAL";
|
2020-07-03 09:29:39 +08:00
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
string autoCompleteText = MainViewModel.GetSearchText(index, input, query);
|
|
|
|
|
|
|
|
|
|
// Assert
|
2020-10-08 04:12:59 +08:00
|
|
|
|
Assert.AreEqual(expectedAutoCompleteText, autoCompleteText);
|
2020-07-03 09:29:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MainViewModelGetSearchTextReturnsInputWhenIndexIsZeroAndNoMatch()
|
2020-07-03 09:29:39 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
int index = 0;
|
|
|
|
|
string input = "VISUAL";
|
2020-08-11 06:49:36 +08:00
|
|
|
|
string query = "Vim";
|
2020-07-03 09:29:39 +08:00
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
string autoCompleteText = MainViewModel.GetSearchText(index, input, query);
|
|
|
|
|
|
|
|
|
|
// Assert
|
2020-10-08 04:12:59 +08:00
|
|
|
|
Assert.AreEqual(input, autoCompleteText);
|
2020-07-03 09:29:39 +08:00
|
|
|
|
}
|
2020-10-21 05:53:32 +08:00
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void ShouldAutoCompleteTextBeEmptyShouldReturnFalseWhenAutoCompleteTextIsEmpty()
|
2020-10-21 05:53:32 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
string queryText = "Te";
|
|
|
|
|
string autoCompleteText = string.Empty;
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
bool result = MainViewModel.ShouldAutoCompleteTextBeEmpty(queryText, autoCompleteText);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.AreEqual(false, result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void ShouldAutoCompleteTextBeEmptyShouldReturnTrueWhenQueryTextMatchAutoCompleteText()
|
2020-10-21 05:53:32 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
string queryText = "Te";
|
|
|
|
|
string autoCompleteText = "Teams";
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
bool result = MainViewModel.ShouldAutoCompleteTextBeEmpty(queryText, autoCompleteText);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.AreEqual(false, result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void ShouldAutoCompleteTextBeEmptyShouldReturnTrueWhenQueryTextIsEmpty()
|
2020-10-21 05:53:32 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
string queryText = string.Empty;
|
|
|
|
|
string autoCompleteText = "Teams";
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
bool result = MainViewModel.ShouldAutoCompleteTextBeEmpty(queryText, autoCompleteText);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.AreEqual(true, result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void ShouldAutoCompleteTextBeEmptyShouldReturnTrueWhenQueryTextDoesNotMatchAutoCompleteText()
|
2020-10-21 05:53:32 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
string queryText = "TE";
|
|
|
|
|
string autoCompleteText = "Teams";
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
bool result = MainViewModel.ShouldAutoCompleteTextBeEmpty(queryText, autoCompleteText);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.AreEqual(true, result);
|
|
|
|
|
}
|
2020-07-03 09:29:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|