| 1 | using CascadeIDE.Cockpit.DataBus; |
| 2 | using CascadeIDE.Features.SolutionWarmup.Application; |
| 3 | using CascadeIDE.Models; |
| 4 | using Xunit; |
| 5 | |
| 6 | namespace CascadeIDE.Tests; |
| 7 | |
| 8 | public sealed class PfdBackgroundStatusPresentationTests |
| 9 | { |
| 10 | private const string Ws = @"D:\repo"; |
| 11 | private const string Sln = @"D:\repo\app.sln"; |
| 12 | |
| 13 | private static readonly HybridIndexSettings EnabledAuto = new() |
| 14 | { |
| 15 | Enabled = true, |
| 16 | AutoReindexOnSolutionOpen = true, |
| 17 | }; |
| 18 | |
| 19 | [Fact] |
| 20 | public void Compute_whenWarmupRunningAndHciPending_showsPreparing() |
| 21 | { |
| 22 | var warmup = new SolutionWarmupStateChanged(Ws, Sln, SolutionWarmupLifecycle.Running, null); |
| 23 | var snap = PfdBackgroundStatusPresentation.Compute(Ws, Sln, warmup, null, hciReindexPending: true, EnabledAuto); |
| 24 | |
| 25 | Assert.True(snap.Show); |
| 26 | Assert.False(snap.IsCaution); |
| 27 | Assert.Equal("Preparing workspace…", snap.Text); |
| 28 | } |
| 29 | |
| 30 | [Fact] |
| 31 | public void Compute_whenStaleHciFromOtherSolution_stillShowsIndexing() |
| 32 | { |
| 33 | var oldHci = new HybridIndexStateChanged(Ws, @"D:\repo\other.sln", "", 10, null, null, null); |
| 34 | var snap = PfdBackgroundStatusPresentation.Compute(Ws, Sln, null, oldHci, hciReindexPending: true, EnabledAuto); |
| 35 | |
| 36 | Assert.True(snap.Show); |
| 37 | Assert.Equal("Indexing workspace…", snap.Text); |
| 38 | } |
| 39 | |
| 40 | [Fact] |
| 41 | public void Compute_whenHciError_showsCaution() |
| 42 | { |
| 43 | var hci = new HybridIndexStateChanged(Ws, Sln, "", 0, null, "disk full", null); |
| 44 | var snap = PfdBackgroundStatusPresentation.Compute(Ws, Sln, null, hci, hciReindexPending: false, EnabledAuto); |
| 45 | |
| 46 | Assert.True(snap.Show); |
| 47 | Assert.True(snap.IsCaution); |
| 48 | Assert.Contains("Index error", snap.Text, StringComparison.Ordinal); |
| 49 | } |
| 50 | |
| 51 | [Fact] |
| 52 | public void Compute_whenCancelledScopeChange_doesNotShowCaution() |
| 53 | { |
| 54 | var warmup = new SolutionWarmupStateChanged(Ws, Sln, SolutionWarmupLifecycle.Cancelled, "scope_changed"); |
| 55 | var snap = PfdBackgroundStatusPresentation.Compute(Ws, Sln, warmup, null, hciReindexPending: true, EnabledAuto); |
| 56 | |
| 57 | Assert.True(snap.Show); |
| 58 | Assert.False(snap.IsCaution); |
| 59 | Assert.Equal("Indexing workspace…", snap.Text); |
| 60 | } |
| 61 | |
| 62 | [Fact] |
| 63 | public void Compute_whenIdleAndIndexed_hides() |
| 64 | { |
| 65 | var warmup = new SolutionWarmupStateChanged(Ws, Sln, SolutionWarmupLifecycle.Ready, null); |
| 66 | var hci = new HybridIndexStateChanged(Ws, Sln, "", 42, null, null, null); |
| 67 | var snap = PfdBackgroundStatusPresentation.Compute(Ws, Sln, warmup, hci, hciReindexPending: false, EnabledAuto); |
| 68 | |
| 69 | Assert.False(snap.Show); |
| 70 | Assert.Null(snap.Text); |
| 71 | } |
| 72 | } |
| 73 | |