| 1 | using System.Globalization; |
| 2 | using CascadeIDE.Cockpit.DataBus; |
| 3 | using CascadeIDE.Features.HybridIndex.Application; |
| 4 | using CascadeIDE.Models; |
| 5 | using Xunit; |
| 6 | |
| 7 | namespace CascadeIDE.Tests; |
| 8 | |
| 9 | public sealed class HybridIndexHisPresentationProjectionTests |
| 10 | { |
| 11 | [Fact] |
| 12 | public void Lamp_empty_state_is_no_data() => |
| 13 | Assert.Equal("NO DATA", HybridIndexHisPresentationProjection.LampText(null)); |
| 14 | |
| 15 | [Fact] |
| 16 | public void Lamp_item_null_is_advisory_no_data_yet() |
| 17 | { |
| 18 | var item = HybridIndexHisPresentationProjection.LampItem(null); |
| 19 | Assert.Equal("hci", item.Id); |
| 20 | Assert.Equal(AnnunciatorLampLevel.Advisory, item.Level); |
| 21 | Assert.Contains("No data", item.Detail, StringComparison.Ordinal); |
| 22 | } |
| 23 | |
| 24 | [Theory] |
| 25 | [InlineData("", AnnunciatorLampLevel.Ok, "OK")] |
| 26 | [InlineData(" ", AnnunciatorLampLevel.Ok, "OK")] |
| 27 | [InlineData("fail", AnnunciatorLampLevel.Caution, "fail")] |
| 28 | public void Lamp_item_follows_last_error(string lastError, AnnunciatorLampLevel level, string detailContains) |
| 29 | { |
| 30 | var item = HybridIndexHisPresentationProjection.LampItem(Make(lastError)); |
| 31 | Assert.Equal(level, item.Level); |
| 32 | Assert.Contains(detailContains, item.Detail, StringComparison.Ordinal); |
| 33 | } |
| 34 | |
| 35 | [Fact] |
| 36 | public void State_empty_is_dash() => |
| 37 | Assert.Equal("—", HybridIndexHisPresentationProjection.StateShort(null)); |
| 38 | |
| 39 | [Theory] |
| 40 | [InlineData("", "OK", "IDLE")] |
| 41 | [InlineData(" ", "OK", "IDLE")] |
| 42 | [InlineData("oops", "CAUTION", "ERROR")] |
| 43 | public void Lamp_and_state_follow_last_error(string lastError, string lamp, string state) |
| 44 | { |
| 45 | var evt = Make(lastError); |
| 46 | Assert.Equal(lamp, HybridIndexHisPresentationProjection.LampText(evt)); |
| 47 | Assert.Equal(state, HybridIndexHisPresentationProjection.StateShort(evt)); |
| 48 | } |
| 49 | |
| 50 | private static HybridIndexStateChanged Make(string? lastError) => |
| 51 | new("/", null, ":memory:", 0, null, lastError, null); |
| 52 | |
| 53 | [Theory] |
| 54 | [InlineData("", "NO FAILURES")] |
| 55 | [InlineData("—", "NO FAILURES")] |
| 56 | [InlineData("disk full", "disk full")] |
| 57 | public void Second_line_for_failures_row(string banner, string expect) => |
| 58 | Assert.Equal(expect, HybridIndexHisPresentationProjection.SecondMessageLine(banner)); |
| 59 | |
| 60 | [Fact] |
| 61 | public void Freshness_minutes_rounded_and_ecam_under_one_hour() |
| 62 | { |
| 63 | Assert.Equal("0", HybridIndexHisPresentationProjection.FreshnessMinutesRoundedText(0.2)); |
| 64 | Assert.Equal("12m", HybridIndexHisPresentationProjection.FreshnessEcamText(12.8)); |
| 65 | } |
| 66 | |
| 67 | [Fact] |
| 68 | public void Freshness_colon_line_uses_wall_clock() |
| 69 | { |
| 70 | var iso = DateTimeOffset.Parse("2020-01-01T12:00:00Z").ToString("o", CultureInfo.InvariantCulture); |
| 71 | var now = DateTimeOffset.Parse("2020-01-02T12:00:00Z"); |
| 72 | Assert.Contains("freshness:", HybridIndexHisPresentationProjection.FreshnessColonLine(iso, now)); |
| 73 | Assert.Contains("d", HybridIndexHisPresentationProjection.FreshnessColonLine(iso, now)); |
| 74 | } |
| 75 | |
| 76 | [Theory] |
| 77 | [InlineData(-1, 0)] |
| 78 | [InlineData(0, 0)] |
| 79 | [InlineData(1500, 0.5)] |
| 80 | [InlineData(3000, 1)] |
| 81 | public void Docs_gauge_docs_count(int docs, double expect01) |
| 82 | { |
| 83 | Assert.Equal(expect01, HybridIndexHisPresentationProjection.DocsGauge01(docs)); |
| 84 | } |
| 85 | } |
| 86 | |