Files
LlamaCasty/ytLive.Tests/BorderColorPaletteTests.cs
T
gramps 6271bf34c9 TASK 60: the border-colour drop-down names every colour
The creator: "under Live->Layers->webcam->Properties->border color: in the drop
down box, the #hex values are good, but add a corresponding color name/label next
to the value."

Each row now reads "#e94560  Crimson" - the hex stays exactly as it was, the
colour's name goes next to it (dimmed #a0a0b0 so the hex reads first), and the
tooltip becomes "Crimson (#e94560)".

The 14 colours were a hard-coded string[] inside the click handler - a list of
bare strings cannot carry a name, and a list hidden in UI code cannot be asserted
on. They now live in Models/BorderColorPalette.cs: NamedColor(Hex, Name) +
BorderColorPalette.All (the single source of truth) + NameOf(hex), which answers
case-insensitively and falls back to the hex for a colour outside the palette.
The picker builds its menu from the catalogue and no longer knows any colour by
heart.

The names are chosen not to collide - the palette has two greens, two blues and
two warm colours: #00FF00 is Lime and #22c55e Emerald, #0000FF is Blue and
#3b82f6 Azure, #FF8800 is Orange and #f59e0b Amber.

Guard: ytLive.Tests/BorderColorPaletteTests.cs - every entry valid + named, no
hex or name repeated, the 14 legacy colours all still offered, NameOf answers,
and the old list is gone from the handler. 433/433 green, 0 warnings.
2026-10-21 20:03:19 -07:00

54 lines
2.7 KiB
C#

using System;
using System.Linq;
using Xunit;
using ytLive.Models;
namespace ytLive.Tests;
/// <summary>TASK 60 — the creator (2026-10-21): *"under Live-&gt;Layers-&gt;webcam-&gt;
/// Properties-&gt;border color: in the drop down box, the #hex values are good, but add a
/// corresponding color name/label next to the value."*
///
/// <para>One test: the palette is the single source of truth for the drop-down (the
/// picker builds its menu from it and carries no list of its own), every entry has a
/// valid hex and a name, the names are unique, the colours the picker used to offer are
/// all still offered, and the lookup answers for a hex the creator typed.</para></summary>
public class BorderColorPaletteTests
{
[Fact]
public void The_border_palette_names_every_colour_the_picker_offers()
{
// 1. Every entry is a valid hex with a name, and no hex or name repeats.
Assert.NotEmpty(BorderColorPalette.All);
foreach (var colour in BorderColorPalette.All)
{
Assert.Matches("^#[0-9a-fA-F]{6}$", colour.Hex);
Assert.False(string.IsNullOrWhiteSpace(colour.Name), $"{colour.Hex} has no name");
}
Assert.Equal(BorderColorPalette.All.Count,
BorderColorPalette.All.Select(c => c.Hex).Distinct(StringComparer.OrdinalIgnoreCase).Count());
Assert.Equal(BorderColorPalette.All.Count,
BorderColorPalette.All.Select(c => c.Name).Distinct(StringComparer.OrdinalIgnoreCase).Count());
// 2. The colours the picker used to offer are all still offered.
string[] legacy = ["#FFFFFF", "#000000", "#FF0000", "#00FF00", "#0000FF", "#FFFF00",
"#FF00FF", "#00FFFF", "#FF8800", "#8800FF", "#e94560", "#22c55e",
"#3b82f6", "#f59e0b"];
foreach (var hex in legacy)
Assert.Contains(BorderColorPalette.All, c => c.Hex == hex);
// 3. The lookup answers for a hex in any case, and keeps an unknown hex as-is.
Assert.Equal("Crimson", BorderColorPalette.NameOf("#e94560"));
Assert.Equal("Crimson", BorderColorPalette.NameOf("#E94560"));
Assert.Equal("White", BorderColorPalette.NameOf(" #ffffff "));
Assert.Equal("#123456", BorderColorPalette.NameOf("#123456"));
// 4. The picker builds its menu from the catalogue — there is no second list.
var source = SourceAssert.Text("Controls", "LeftPanel.xaml.cs");
Assert.True(source.Contains("BorderColorPalette"),
"the border picker does not build its menu from the palette");
Assert.False(source.Contains("\"#FFFFFF\""),
"the border picker still carries its own list of colours");
}
}