using System.IO; using System.Windows; using System.Windows.Automation; using System.Windows.Automation.Peers; using System.Windows.Automation.Provider; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Threading; using Chronos.App.DesignTime; using Chronos.App.Infrastructure; using Chronos.App.Sections; using Chronos.App.Server; using Chronos.App.Settings; using Chronos.App.Shell; using Chronos.Core.Localization; using Chronos.Testing; using Chronos.Ui.Controls; using Chronos.Ui.Mvvm; using Chronos.Ui.Theming; using Chronos.Ui.Visuals; namespace Chronos.App.Tests.Windows; /// /// Shows the real main window off screen (section templates, client styles) on the sample data used by /// --capture and renders every screen in both themes: catches XAML, resource, template and view-model wiring /// errors that compile cleanly. Mirrors step by step. /// [WindowsOnly] [Serial] [Timeout(300_000)] public sealed class ScreenSmokeTests { [Test] public Task EveryScreenRendersWithSampleDataInBothThemes() => ScreenHost.RunAsync(async () => { await using var app = await SampleApp.StartAsync(); var shell = app.Shell; // First run: empty index, the welcome dialog over the empty Library. Assert.True(shell.Library.IsLibraryEmpty, "an empty index shows the empty Library"); Assert.False(shell.IsJobActive); shell.ShowWelcome(); shell.Welcome!.ShowDiscovered(new DiscoveredServer("Studio NAS", "https://nas.local:8443")); await app.ExpectAsync("welcome"); Assert.True(shell.Welcome.IsLocal, "a local archive is the default choice"); shell.CompleteWelcome(); Assert.False(shell.IsWelcomeOpen); await app.ExpectAsync("library-empty"); shell.Navigate(SectionKey.Server); await app.ExpectAsync("server-signedout"); Assert.False(shell.Server.IsConnected); // A populated archive, jobs in every state, a signed-in server. await app.Sample.FillAsync(); await shell.Library.RefreshAsync(); await shell.Jobs.ReloadAsync(); await shell.Services.Server.RestoreAsync(); shell.About.SetResult(null); await shell.Settings.DetectEncodersAsync(); await shell.Settings.SelfTestAsync(); shell.Navigate(SectionKey.Library); Assert.Equal(36, shell.Library.Items.Count); Assert.True(shell.Library.IsGrid); await app.ExpectAsync("library", waitForThumbnails: true); Assert.NotEmpty(app.FindAll()); // The newest sequence is a RAW: its card shows the embedded preview. Assert.Equal("Harbour sunset", shell.Library.Items[0].Title); Assert.NotNull(shell.Library.Items[0].Thumbnail, "embedded preview of the first card"); shell.Library.Items[0].IsSelected = true; Assert.True(shell.Library.IsSingleSelection); await app.ExpectAsync("library-selection", waitForThumbnails: true); shell.Library.LayoutIndex = 1; Assert.True(shell.Library.IsList); await app.ExpectAsync("library-list", waitForThumbnails: true); shell.Library.LayoutIndex = 0; shell.Library.ClearSelectionCommand.Execute(null); Assert.Equal(0, shell.Library.SelectionCount); shell.Navigate(SectionKey.Jobs); Assert.Equal(9, shell.Jobs.Rows.Count); Assert.True(shell.IsJobActive, "running jobs show in the job bar"); shell.Jobs.Rows[0].IsExpanded = true; await app.ExpectAsync("jobs"); shell.Navigate(SectionKey.Server); Assert.True(shell.Server.IsConnected, "the saved session is restored"); await app.ExpectAsync("server"); // Every Settings page, About last (owner review 2, R5). shell.Navigate(SectionKey.Settings); Assert.Equal(3, shell.Settings.PreviewNames.Count); Assert.Equal(6, shell.Settings.Encoders.Count); foreach (var page in Enum.GetValues()) { shell.Settings.Page = page; await app.ExpectAsync("settings-" + page.ToString().ToLowerInvariant()); } shell.Navigate(SectionKey.Import); await app.ExpectAsync("import"); // Edit with no sequence open: the picker lists the sequences (owner review 1, R7). shell.Navigate(SectionKey.Edit); await shell.Sequence.Picker.Loading; await app.ExpectAsync("edit-picker"); Assert.True(shell.Sequence.ShowsPicker); shell.Navigate(SectionKey.Archive); await app.ExpectAsync("archive"); }); [Test] public Task TheShellFollowsTheLanguage() => ScreenHost.RunAsync(async () => { await using var app = await SampleApp.StartAsync(); var english = app.Shell.Library.Title; UiLanguage.Apply("it"); try { Assert.NotEqual(english, app.Shell.Library.Title); await app.ExpectAsync("library-empty-it"); } finally { UiLanguage.Apply("en"); } Assert.Equal(english, app.Shell.Library.Title); }); [Test] public Task ArabicMirrorsTheShellFromStartButNotItsPicturesOrLogo() => ScreenHost.RunAsync(async () => { // The language is applied before the window exists, as at start-up with Arabic saved in the settings. await using var app = await SampleApp.StartAsync("ar", firstRun: true); try { var window = app.Window; Assert.Equal(FlowDirection.RightToLeft, window.FlowDirection, "the main window opens mirrored"); var rail = (FrameworkElement)window.FindName("Rail"); Assert.Equal(FlowDirection.RightToLeft, rail.FlowDirection, "the rail mirrors with the window"); // The window's content carries the mirror (a capture of it alone reads right to left, as on screen). Assert.Greater(rail.TranslatePoint(new Point(rail.ActualWidth / 2, 0), window).X, window.ActualWidth / 2, "the rail starts on the right"); // The first-run dialog keeps the shell behind it out of reach. Assert.True(app.Shell.IsWelcomeOpen); Assert.False(rail.IsEnabled, "the rail behind the first-run dialog takes no input"); app.Shell.CompleteWelcome(); Assert.True(rail.IsEnabled); var id = await app.Sample.FillEditorAsync(); app.Shell.OpenSequence(id); await app.Shell.Sequence.OpenAsync(id); var editor = Assert.NotNull(app.Shell.Sequence.Editor); Assert.True(await editor.WhenIdleAsync(TimeSpan.FromSeconds(60)), "the editor settled"); await app.ExpectAsync("edit-ar"); // Directional glyphs follow the reading direction; the others, the logo, the picture and the charts do not. var back = Assert.NotNull(app.FindAll