From 3f4e6bdf4e72c94545841ec12f0ec01cb704f0d5 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Wed, 8 Oct 2025 10:57:50 -0500 Subject: [PATCH] another test --- .../RecentCommandsTests.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/modules/cmdpal/Tests/Microsoft.CmdPal.UI.ViewModels.UnitTests/RecentCommandsTests.cs b/src/modules/cmdpal/Tests/Microsoft.CmdPal.UI.ViewModels.UnitTests/RecentCommandsTests.cs index 8c7f35c1b9..7e62c578b6 100644 --- a/src/modules/cmdpal/Tests/Microsoft.CmdPal.UI.ViewModels.UnitTests/RecentCommandsTests.cs +++ b/src/modules/cmdpal/Tests/Microsoft.CmdPal.UI.ViewModels.UnitTests/RecentCommandsTests.cs @@ -299,6 +299,8 @@ public partial class RecentCommandsTests : CommandPaletteUnitTestBase private sealed record ScoredItem(ListItemMock Item, int Score) { public string Title => Item.Title; + + public override string ToString() => $"[{Score}]{Title}"; } private static IEnumerable TieScoresToMatches(List items, List scores) @@ -414,4 +416,29 @@ public partial class RecentCommandsTests : CommandPaletteUnitTestBase Assert.AreEqual("Visual Studio Code", weightedMatches[1].Title, "VsCode does fuzzy match, but is less relevant than Terminal"); Assert.AreEqual("Run commands", weightedMatches[2].Title, "run only matches on the subtitle"); } + + [TestMethod] + public void ValidateUsageEventuallyHelps() + { + var items = CreateMockHistoryItems(); + var emptyHistory = CreateMockHistoryService(new()); + var history = CreateMockHistoryService(items); + + // We're gonna run this test and keep adding more uses of VS Code till + // it breaks past Command Prompt + var vsCodeId = items[1].Id; + for (var i = 0; i < 10; i++) + { + history.AddHistoryItem(vsCodeId); + + var weightedScores = items.Select(item => MainListPage.ScoreTopLevelItem("C", item, history)).ToList(); + var weightedMatches = GetMatches(items, weightedScores).ToList(); + Assert.AreEqual(4, weightedMatches.Count); + + var expectedCmdIndex = i < 5 ? 0 : 1; + var expectedCodeIndex = i < 5 ? 1 : 0; + Assert.AreEqual("Command Prompt", weightedMatches[expectedCmdIndex].Title); + Assert.AreEqual("Visual Studio Code", weightedMatches[expectedCodeIndex].Title); + } + } }