using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Threading; using Titano.App.DesignTime; using Titano.App.Editor; using Titano.App.Infrastructure; using Titano.App.Sections; using Titano.App.Shell; using Titano.App.Tests.Windows; using Titano.Core.Project; using Titano.Testing; using Titano.Ui.Theming; using Titano.Ui.Visuals; namespace Titano.App.Tests.Editor; /// /// The sequence editor in the real main window, off screen at the minimum capture size, on the synthetic sunset of /// --capture (real JPEG frames, deep analysis, advised project): every section shows its measuring tool, its /// settings and preview pixels in both themes, and an edit goes through undo and redo. /// [WindowsOnly] [Serial] [Timeout(300_000)] public sealed class EditorSmokeTests { private static readonly AppTheme[] Themes = [AppTheme.Dark, AppTheme.Light]; [Test] public Task EverySectionOfTheEditorRendersInBothThemes() => ScreenHost.RunAsync(async () => { var environment = AppEnvironment.ForCapture(); UiLanguage.Apply("en"); ThemeManager.Apply(AppTheme.Dark); var services = new AppServices(environment, new AppSettings { Language = "en", FirstRunCompleted = true }, () => { }, new NoDialogs()); var sample = SampleData.Configure(services); var shell = new ShellViewModel(services); var window = new MainWindow(shell) { WindowStartupLocation = WindowStartupLocation.Manual, Left = -20000, Top = -20000, Width = 1200, Height = 788, ShowActivated = false, ShowInTaskbar = false, }; window.Show(); try { await sample.OpenEmptyAsync(); await shell.StartAsync(); var id = await sample.FillEditorAsync(); shell.OpenSequence(id); await shell.Sequence.OpenAsync(id); var editor = Assert.NotNull(shell.Sequence.Editor); Assert.Equal(96, editor.FrameCount); Assert.NotNull(editor.Session.Content.Deep, "the sample is analysed"); Assert.True(editor.Session.Project.Exposure.Deflicker.HasAdvice, "the advice is in the project"); Assert.Equal("Harbour sunset", editor.Title); foreach (var theme in Themes) { ThemeManager.Apply(theme); foreach (var tab in editor.Tabs) { editor.SelectedTab = tab; await SettleAsync(window); Assert.True(await editor.WhenIdleAsync(TimeSpan.FromSeconds(60)), $"{tab.Key}: still busy"); await SettleAsync(window); var view = Find(window).Single(v => v.IsVisible); Assert.NotNull(editor.PreviewImage, $"{tab.Key}: the preview shows pixels"); ExpectMeasure(view, tab); Assert.True(Find(view).Any(p => ReferenceEquals(p.Content, tab) && p.ActualHeight > 100), $"{tab.Key}: settings column"); Assert.Greater(Distinct(Render(window)), 40, $"{tab.Key} drew almost nothing in {theme}"); } } // An edit through the session is undone and redone (Ctrl+Z / Ctrl+Y run the same commands). ThemeManager.Apply(AppTheme.Dark); var before = editor.Session.Project.Exposure.ExposureOffsetEv; editor.Session.Edit(p => p with { Exposure = p.Exposure with { ExposureOffsetEv = 0.5 } }); editor.UndoCommand.Execute(null); Assert.Equal(before, editor.Session.Project.Exposure.ExposureOffsetEv); editor.RedoCommand.Execute(null); Assert.Equal(0.5, editor.Session.Project.Exposure.ExposureOffsetEv); await editor.Session.FlushAsync(); Assert.NotNull(editor.Plan, "the export is planned"); } finally { ThemeManager.Apply(AppTheme.Dark); window.Close(); await shell.Sequence.CloseAsync(); shell.Dispose(); await services.DisposeAsync(); environment.DeleteCaptureData(); } }); /// The measuring tool of each section has content. private static void ExpectMeasure(SequenceView view, EditorTab tab) { switch (tab) { case FramesTab frames: Assert.Equal(96, frames.Frames.Count); Assert.NotEmpty(Find(view).Where(i => i.DataContext is FrameRow && i.IsVisible)); break; case CameraTab or TimeTab: Assert.NotEmpty(Find(view).Where(c => c.IsVisible && c.ActualHeight > 50)); break; case ExportTab export: Assert.NotEmpty(export.Cards); Assert.NotEmpty(Find