using Explorer.Application; using Explorer.Domain; namespace Explorer.Application.Tests; public class FolderDisplayRefreshTests { [Fact] public void Pick_prefers_visible_then_largest() { var items = new[] { Dir(@"C:\a", "a", 50_000_000), Dir(@"C:\b", "b", 90_000_000), Dir(@"C:\c", "c", 5_000), Dir(@"C:\d", "d", 20_000_000) }; var picked = FolderDisplayRefresh.Pick(items, [@"C:\d", @"C:\a"]); Assert.Equal(3, picked.Count); Assert.Equal(@"C:\a", picked[0].FullPath); Assert.Equal(@"C:\d", picked[1].FullPath); Assert.Equal(@"C:\b", picked[2].FullPath); } [Fact] public void Pick_caps_and_skips_tiny_or_cloud() { var items = Enumerable.Range(0, 12) .Select(i => Dir($@"C:\f{i}", $"f{i}", (13 - i) * 2_000_000L)) .Append(Dir(@"C:\tiny", "tiny", 100)) .Append(Dir(@"C:\cloud", "cloud", 80_000_000, hydrate: true)) .ToList(); var picked = FolderDisplayRefresh.Pick(items); Assert.Equal(FolderDisplayRefresh.MaxProbes, picked.Count); Assert.Equal(@"C:\f0", picked[0].FullPath); Assert.DoesNotContain(picked, item => item.Name is "tiny" or "cloud"); } [Fact] public void NeedsVerify_compares_child_counts() { Assert.True(FolderDisplayRefresh.NeedsVerify(10, 2000)); Assert.False(FolderDisplayRefresh.NeedsVerify(10, 10)); Assert.False(FolderDisplayRefresh.NeedsVerify(-1, 2000)); } [Fact] public void HasIndexCounts_requires_index_hydration() { var live = Dir(@"C:\a", "a", 50_000_000, hydration: ItemHydrationFlags.Shell | ItemHydrationFlags.Metadata); Assert.False(FolderDisplayRefresh.HasIndexCounts(live)); Assert.True(FolderDisplayRefresh.HasIndexCounts(live.Overlay(hydration: ItemHydrationFlags.Index))); } private static FileSystemItem Dir(string path, string name, long size, bool hydrate = false, ItemHydrationFlags? hydration = null) => new() { FullPath = path, Name = name, IsDirectory = true, SizeBytes = size, IndexedChildCount = 4, Hydration = hydration ?? ItemHydrationFlags.All, Cloud = hydrate ? new CloudPresence("x", CloudAvailability.OnlineOnly, size, null, true) : null }; }