using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using Xunit; using ytLive.Models; namespace ytLive.Tests; /// TASK 62 — the creator (2026-10-21): *"the border color drop down box content /// should also include the name of the color next to the hex value as they in the drop-down /// list box."* /// /// One test: the model carries the palette's name for the current border colour /// (and nothing for a custom hex the creator typed), the name raises when the colour /// changes, and the panel shows it right next to the hex field — which keeps a fixed /// width so the name stays beside the hex instead of drifting to the far edge. public class BorderColorNameTests { [Fact] public void The_border_colour_field_shows_the_colour_name_next_to_the_hex() { // ── The model: the name of the current colour, and nothing for a custom hex ── var element = new WebcamSceneConfig { Name = "Webcam" }; var raised = new List(); element.PropertyChanged += (_, e) => raised.Add(e.PropertyName); element.BorderColor = "#e94560"; Assert.Equal("Crimson", element.BorderColorName); Assert.Contains("BorderColorName", raised); raised.Clear(); element.BorderColor = "#123456"; Assert.Equal("", element.BorderColorName); // a custom hex has no name Assert.Contains("BorderColorName", raised); // ── The panel: the name sits right next to the hex field ────────────────── var doc = XDocument.Load(SourceAssert.RepoPath("Controls", "LeftPanel.xaml")); var title = doc.Descendants().Single(e => e.Name.LocalName == "TextBlock" && (string?)e.Attribute("Text") == "Border Color"); var row = title.ElementsAfterSelf().First(e => e.Name.LocalName == "DockPanel"); var field = row.Descendants().Single(e => e.Name.LocalName == "TextBox"); var name = row.Descendants().Single(e => e.Name.LocalName == "TextBlock" && ((string?)e.Attribute("Text") ?? "").Contains("BorderColorName")); // The hex field has a fixed width, so the name stays beside the hex. Assert.False(string.IsNullOrWhiteSpace((string?)field.Attribute("Width")), "the hex field has no fixed width — the name would drift to the far edge"); // The name is in the same horizontal row as the field, after it. Assert.Equal(field.Parent, name.Parent); var order = field.Parent!.Elements().ToList(); Assert.True(order.IndexOf(field) < order.IndexOf(name), "the colour name comes before the hex field"); } }