|
| 1 | +using GamerGuardian.Models; |
| 2 | +using GamerGuardian.Services; |
| 3 | +using Xunit; |
| 4 | + |
| 5 | +namespace GamerGuardian.Tests; |
| 6 | + |
| 7 | +public class NotificationHeaderTests |
| 8 | +{ |
| 9 | + private static DriftItem Item(string displayKey, string label = "x") => new( |
| 10 | + SettingId: $"{displayKey}:test", |
| 11 | + DisplayKey: displayKey, |
| 12 | + DisplayLabel: label, |
| 13 | + Description: $"{label} -- test", |
| 14 | + CurrentValue: "On", |
| 15 | + DesiredValue: "Off", |
| 16 | + AutoApply: false, |
| 17 | + Apply: () => Task.CompletedTask); |
| 18 | + |
| 19 | + [Fact] |
| 20 | + public void EmptyReport_GenericHeader() |
| 21 | + { |
| 22 | + var h = NotificationHeader.For(new DriftReport(Array.Empty<DriftItem>())); |
| 23 | + Assert.Equal("Monitored settings have drifted", h); |
| 24 | + } |
| 25 | + |
| 26 | + [Fact] |
| 27 | + public void NullReport_GenericHeader() |
| 28 | + { |
| 29 | + Assert.Equal("Monitored settings have drifted", NotificationHeader.For(null!)); |
| 30 | + } |
| 31 | + |
| 32 | + [Fact] |
| 33 | + public void SingleAiPolicy_SaysWindowsAi() |
| 34 | + { |
| 35 | + // The bug we're fixing: this used to say "Display settings have drifted" |
| 36 | + // even for an AI policy drift. Verify the AI category is named correctly. |
| 37 | + var h = NotificationHeader.For(new DriftReport(new[] { Item("ai") })); |
| 38 | + Assert.Equal("Windows AI setting has drifted", h); |
| 39 | + Assert.DoesNotContain("Display", h); |
| 40 | + } |
| 41 | + |
| 42 | + [Fact] |
| 43 | + public void MultipleAiPolicies_PluralForm() |
| 44 | + { |
| 45 | + var h = NotificationHeader.For(new DriftReport(new[] { Item("ai"), Item("ai") })); |
| 46 | + Assert.Equal("Windows AI settings have drifted", h); |
| 47 | + } |
| 48 | + |
| 49 | + [Fact] |
| 50 | + public void SingleService_SingularForm() |
| 51 | + { |
| 52 | + var h = NotificationHeader.For(new DriftReport(new[] { Item("service") })); |
| 53 | + Assert.Equal("Windows service has drifted", h); |
| 54 | + } |
| 55 | + |
| 56 | + [Fact] |
| 57 | + public void MultipleServices_PluralForm() |
| 58 | + { |
| 59 | + var h = NotificationHeader.For(new DriftReport(new[] { Item("service"), Item("service") })); |
| 60 | + Assert.Equal("Windows services have drifted", h); |
| 61 | + } |
| 62 | + |
| 63 | + [Fact] |
| 64 | + public void SingleDisplay_SingularForm() |
| 65 | + { |
| 66 | + var h = NotificationHeader.For(new DriftReport(new[] { Item("display") })); |
| 67 | + Assert.Equal("Display setting has drifted", h); |
| 68 | + } |
| 69 | + |
| 70 | + [Fact] |
| 71 | + public void GlobalGaming_KnownLabel() |
| 72 | + { |
| 73 | + var h = NotificationHeader.For(new DriftReport(new[] { Item("global") })); |
| 74 | + Assert.Equal("Global gaming setting has drifted", h); |
| 75 | + } |
| 76 | + |
| 77 | + [Fact] |
| 78 | + public void MixedCategories_GenericCountHeader() |
| 79 | + { |
| 80 | + var h = NotificationHeader.For(new DriftReport(new[] |
| 81 | + { |
| 82 | + Item("ai"), Item("service"), Item("display") |
| 83 | + })); |
| 84 | + Assert.Equal("3 monitored settings have drifted", h); |
| 85 | + } |
| 86 | + |
| 87 | + [Fact] |
| 88 | + public void UnknownCategory_FallsBackGracefully() |
| 89 | + { |
| 90 | + var h = NotificationHeader.For(new DriftReport(new[] { Item("madeup") })); |
| 91 | + Assert.Contains("drifted", h); |
| 92 | + // Doesn't crash or say "Display" |
| 93 | + Assert.DoesNotContain("Display", h); |
| 94 | + } |
| 95 | +} |
0 commit comments