Backgrounds: one locked Background per screen + mini rule (TASK 25)

This commit is contained in:
2026-08-23 13:33:33 -07:00
parent b400ab59c5
commit 7dd140a4c0
13 changed files with 554 additions and 309 deletions
+49 -15
View File
@@ -46,31 +46,65 @@ public class SceneCatalogTests
}
[Fact]
public void EnforceBackgroundPolicy_Sets_Flag_For_All_Scenes()
public void NormalizeBackgrounds_Heals_Dirty_Layouts_To_The_Locked_Model()
{
var chat = new Scene { Name = "Chat", HasBackground = false };
// Pre-TASK-25 rot: static Background + stray Game Capture duplicates,
// wrong names, wrong z-order, stale flags on non-canonical scenes.
var starting = new Scene { Name = "Starting", HasBackground = false };
var image = new Source { Name = "Image 1", Type = SourceType.Image };
starting.Elements.Add(new Source { Name = "Background", Type = SourceType.Background, IsBackground = true, Width = 10 });
starting.Elements.Add(image);
starting.Elements.Add(new Source { Name = "Game Capture", Type = SourceType.DisplayCapture, IsBackground = true });
var live = new Scene { Name = "Live", HasBackground = false };
var chatBackground = MainViewModel.EnsureBackground(chat)!;
var liveBackground = MainViewModel.EnsureBackground(live)!;
live.Elements.Add(new Source { Name = "Game Capture", Type = SourceType.Background, IsBackground = true });
MainViewModel.EnforceBackgroundPolicy(new[] { chat, live });
MainViewModel.NormalizeBackgrounds(new[] { starting, live });
Assert.True(starting.HasBackground);
var startingBackgrounds = starting.Elements.OfType<Source>().Where(s => s.IsBackground).ToList();
var kept = Assert.Single(startingBackgrounds);
Assert.Equal("Background", kept.Name);
Assert.Equal(SourceType.Background, kept.Type); // correct flavor preferred over the stray capture row
Assert.Same(image, starting.Elements[1]); // regular layers untouched
Assert.Equal(0, starting.Elements.IndexOf(kept));
Assert.True(chat.HasBackground);
Assert.Contains(chat.Elements, e => ReferenceEquals(e, chatBackground));
Assert.True(live.HasBackground);
Assert.Contains(live.Elements, e => ReferenceEquals(e, liveBackground));
var liveKept = Assert.Single(live.Elements.OfType<Source>(), s => s.IsBackground);
Assert.Equal("Background", liveKept.Name);
Assert.Equal(SourceType.DisplayCapture, liveKept.Type); // flavor corrected to capture
Assert.Equal(0, live.Elements.IndexOf(liveKept));
}
[Fact]
public void EnforceBackgroundPolicy_Normalizes_All_Canonical_Scenes()
public void NormalizeBackgrounds_Strips_Backgrounds_From_NonCanonical_Scenes()
{
var starting = new Scene { Name = "Starting", HasBackground = false };
MainViewModel.EnsureBackground(starting);
var live = new Scene { Name = "Live", HasBackground = false };
var custom = new Scene { Name = "My Scene", HasBackground = true };
custom.Elements.Add(new Source { Name = "Background", Type = SourceType.Background, IsBackground = true });
var layer = new Source { Name = "Image 1", Type = SourceType.Image };
custom.Elements.Add(layer);
MainViewModel.EnforceBackgroundPolicy(new[] { starting, live });
MainViewModel.NormalizeBackgrounds(new[] { custom });
Assert.True(starting.HasBackground);
Assert.True(live.HasBackground);
Assert.False(custom.HasBackground);
Assert.DoesNotContain(custom.Elements, e => e is Source { IsBackground: true });
Assert.Contains(custom.Elements, e => ReferenceEquals(e, layer));
}
[Fact]
public void EnsureBackground_Seeds_The_Right_Flavor_Per_Scene()
{
var starting = new Scene { Name = "Starting", HasBackground = true };
var startingBackground = MainViewModel.EnsureBackground(starting)!;
Assert.Equal(SourceType.Background, startingBackground.Type);
Assert.Equal("Background", startingBackground.Name);
var live = new Scene { Name = "Live", HasBackground = true };
var liveBackground = MainViewModel.EnsureBackground(live)!;
Assert.Equal(SourceType.DisplayCapture, liveBackground.Type);
var noBackgroundScene = new Scene { Name = "My Scene", HasBackground = false };
Assert.Null(MainViewModel.EnsureBackground(noBackgroundScene));
Assert.Empty(noBackgroundScene.Elements);
}
}