Cleanup prompt tests (#1635)

* Move Should_Search_In_Remapped_Result into the SelectionPromptTests class where it belongs
* Use file sealed class for CustomItem, like it's done with CustomSelectionItem in the selection prompt tests
This commit is contained in:
Cédric Luthi 2024-09-07 16:19:55 +02:00 committed by GitHub
parent b9d2d2df6d
commit 32361d3f15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 60 additions and 60 deletions

View File

@ -2,25 +2,6 @@ namespace Spectre.Console.Tests.Unit;
public sealed class MultiSelectionPromptTests
{
private class CustomItem
{
public int X { get; set; }
public int Y { get; set; }
public class Comparer : IEqualityComparer<CustomItem>
{
public bool Equals(CustomItem x, CustomItem y)
{
return x.X == y.X && x.Y == y.Y;
}
public int GetHashCode(CustomItem obj)
{
throw new NotSupportedException();
}
}
}
[Fact]
public void Should_Not_Mark_Item_As_Selected_By_Default()
{
@ -147,3 +128,22 @@ public sealed class MultiSelectionPromptTests
action.ShouldThrow<ArgumentOutOfRangeException>();
}
}
file sealed class CustomItem
{
public int X { get; set; }
public int Y { get; set; }
public class Comparer : IEqualityComparer<CustomItem>
{
public bool Equals(CustomItem x, CustomItem y)
{
return x.X == y.X && x.Y == y.Y;
}
public int GetHashCode(CustomItem obj)
{
throw new NotSupportedException();
}
}
}

View File

@ -85,4 +85,45 @@ public sealed class SelectionPromptTests
// Then
console.Output.ShouldContain($"{ESC}[38;5;12m> Item {ESC}[0m{ESC}[1;38;5;12;48;5;11m1{ESC}[0m");
}
[Fact]
public void Should_Search_In_Remapped_Result()
{
// Given
var console = new TestConsole();
console.Profile.Capabilities.Interactive = true;
console.EmitAnsiSequences();
console.Input.PushText("2");
console.Input.PushKey(ConsoleKey.Enter);
var choices = new List<CustomSelectionItem>
{
new(33, "Item 1"),
new(34, "Item 2"),
};
var prompt = new SelectionPrompt<CustomSelectionItem>()
.Title("Select one")
.EnableSearch()
.UseConverter(o => o.Name)
.AddChoices(choices);
// When
var selection = prompt.Show(console);
// Then
selection.ShouldBe(choices[1]);
}
}
file sealed class CustomSelectionItem
{
public int Value { get; }
public string Name { get; }
public CustomSelectionItem(int value, string name)
{
Value = value;
Name = name ?? throw new ArgumentNullException(nameof(name));
}
}

View File

@ -410,45 +410,4 @@ public sealed class TextPromptTests
// Then
return Verifier.Verify(console.Output);
}
[Fact]
public void Should_Search_In_Remapped_Result()
{
// Given
var console = new TestConsole();
console.Profile.Capabilities.Interactive = true;
console.EmitAnsiSequences();
console.Input.PushText("2");
console.Input.PushKey(ConsoleKey.Enter);
var choices = new List<CustomSelectionItem>
{
new(33, "Item 1"),
new(34, "Item 2"),
};
var prompt = new SelectionPrompt<CustomSelectionItem>()
.Title("Select one")
.EnableSearch()
.UseConverter(o => o.Name)
.AddChoices(choices);
// When
var selection = prompt.Show(console);
// Then
selection.ShouldBe(choices[1]);
}
}
file sealed class CustomSelectionItem
{
public int Value { get; }
public string Name { get; }
public CustomSelectionItem(int value, string name)
{
Value = value;
Name = name ?? throw new ArgumentNullException(nameof(name));
}
}