using System; using System.IO; using System.Linq; using Microsoft.Data.Sqlite; using Xunit; using ytLive.Models; using ytLive.ViewModels; namespace ytLive.Tests; [Collection("RealApp")] public sealed class LayoutResetIntegrationTests { private readonly RealAppHost _app; public LayoutResetIntegrationTests(RealAppHost app) => _app = app; [Fact] public void SettingsRestoreAll_ReplacesEditedScenesWithFactoryLayout() => _app.Run(() => { var tempDb = Path.Combine(Path.GetTempPath(), $"ytLlive-layout-reset-{Guid.NewGuid():N}.db"); MainViewModel.LayoutPathOverride = tempDb; MainViewModel? vm = null; try { vm = new MainViewModel(); var starting = vm.Scenes.Single(scene => SceneCatalog.Is(scene.Name, SceneCatalog.Starting)); starting.Elements.Add(new Source { Name = "Creator-only layer", Type = SourceType.TextOverlay, TextContent = "Not in factory layout", }); vm.SaveLayoutNow(); Assert.True(vm.RestoreAllLayoutDefaultsCommand.CanExecute(null)); vm.RestoreAllLayoutDefaultsCommand.Execute(null); Assert.DoesNotContain(vm.Scenes.SelectMany(scene => scene.Elements).OfType(), source => source.Name == "Creator-only layer"); var settingsXaml = SourceAssert.Text("Controls", "SettingsDrawer.xaml"); Assert.Contains("Content=\"Restore all scenes\"", settingsXaml); Assert.Contains("Command=\"{Binding RestoreAllLayoutDefaultsCommand}\"", settingsXaml); } finally { vm?.Shutdown(); MainViewModel.LayoutPathOverride = null; SqliteConnection.ClearAllPools(); try { File.Delete(tempDb); } catch { /* best-effort cleanup */ } } }); }