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.Input; using System.Windows.Shell; using System.Windows.Threading; using Chronos.App.Editor; using Chronos.App.Infrastructure; using Chronos.App.Library; using Chronos.App.Sections; using Chronos.App.Settings; using Chronos.App.Shell; using Chronos.App.Tests.Editor; using Chronos.Core.Export; using Chronos.Core.Localization; using Chronos.Core.Model; using Chronos.Data.Repositories; using Chronos.Testing; using Chronos.Ui.Controls; using Chronos.Ui.Mvvm; using Chronos.Ui.Visuals; namespace Chronos.App.Tests.Windows; /// /// The shell's ways of telling what happens outside the screen in front: the taskbar button (UI-05), Windows /// notifications (UI-06), section shortcuts (UI-07), job toasts (UI-08), rail badges (UI-10), and the General settings /// that drive them; the usage counts consent stays hidden in builds without monetization (RF-3). /// [WindowsOnly] [Serial] [Timeout(300_000)] public sealed class ShellNotificationTests { [Test] public Task TheTaskbarButtonMirrorsTheJobBar() => ScreenHost.RunAsync(async () => { await using var app = await ScreenSmokeTests.SampleApp.StartAsync(); var shell = app.Shell; await JobsLoadedAsync(shell); var taskbar = Assert.NotNull(app.Window.TaskbarItemInfo); shell.SetJob("Render · Harbour sunset", 0.25, name: "Render: Harbour sunset"); Assert.Equal(TaskbarItemProgressState.Normal, taskbar.ProgressState); Assert.Approximately(0.25, taskbar.ProgressValue, 1e-9); shell.SetJob("Scan · Archive", 0, indeterminate: true); Assert.Equal(TaskbarItemProgressState.Indeterminate, taskbar.ProgressState); shell.SetJob(null, 0); Assert.Equal(TaskbarItemProgressState.None, taskbar.ProgressState); // A failure nobody has seen on the Jobs screen turns the idle button red. shell.SetUnseenFailures(1); Assert.Equal(TaskbarItemProgressState.Error, taskbar.ProgressState); Assert.Approximately(1, taskbar.ProgressValue, 1e-9); shell.SetJob("Render · Harbour sunset", 0.5); Assert.Equal(TaskbarItemProgressState.Normal, taskbar.ProgressState, "a running job comes first"); shell.SetUnseenFailures(0); shell.SetJob(null, 0); Assert.Equal(TaskbarItemProgressState.None, taskbar.ProgressState); }); [Test] public Task TheRailShortcutsOfTheTooltipsNavigate() => ScreenHost.RunAsync(async () => { await using var app = await ScreenSmokeTests.SampleApp.StartAsync(firstRun: true); var shell = app.Shell; var bindings = app.Window.InputBindings.OfType().ToList(); var expected = new (Key Key, SectionKey Section)[] { (Key.D1, SectionKey.Library), (Key.D2, SectionKey.Import), (Key.D3, SectionKey.Edit), (Key.D4, SectionKey.Archive), (Key.D5, SectionKey.Jobs), (Key.D6, SectionKey.Server), (Key.OemComma, SectionKey.Settings), }; // The first-run dialog keeps the shell behind it: no shortcut moves it, nor folds its rail. var library = bindings.Single(b => b.Key == Key.D1 && b.Modifiers == ModifierKeys.Control); Assert.False(library.Command.CanExecute(library.CommandParameter), "no navigation behind the first-run dialog"); var rail = bindings.Single(b => b.Key == Key.B && b.Modifiers == ModifierKeys.Control); Assert.False(rail.Command.CanExecute(rail.CommandParameter), "Ctrl+B waits for the first-run dialog too"); shell.CompleteWelcome(); Assert.True(rail.Command.CanExecute(rail.CommandParameter)); foreach (var (key, section) in expected) { var binding = bindings.Single(b => b.Key == key && b.Modifiers == ModifierKeys.Control); Assert.True(binding.Command.CanExecute(binding.CommandParameter), $"Ctrl+{key}"); binding.Command.Execute(binding.CommandParameter); Assert.Equal(section, shell.Current.Key, $"Ctrl+{key}"); // The rail tooltip lists the shortcut it answers to. var shortcut = key == Key.OemComma ? "Ctrl+," : "Ctrl+" + (char)('1' + (key - Key.D1)); Assert.True(shell.Current.ToolTip.EndsWith(shortcut, StringComparison.Ordinal), $"{section} tooltip ends with {shortcut}"); } // The editor's 1:1 view no longer takes Ctrl+1 from the Library. var gestures = PreviewViewport.ActualSizeCommand.InputGestures.OfType().ToList(); Assert.True(gestures.All(g => g is not { Key: Key.D1, Modifiers: ModifierKeys.Control }), "the preview keeps away from Ctrl+1"); Assert.Contains(gestures, g => g is { Key: Key.D1, Modifiers: ModifierKeys.Control | ModifierKeys.Shift }); Assert.Contains("Ctrl+Shift+1", Loc.L("Tooltips.Editor.Preview.OneToOne")); }); [Test] public Task TheRailCollapsesToIconsThatNameTheirSectionByCtrlB() => ScreenHost.RunAsync(async () => { // Owner review 1: 200 px with names, 48 px of icons whose tooltips name their section, by the button or Ctrl+B. var saves = 0; await using var app = await ScreenSmokeTests.SampleApp.StartAsync(saveSettings: () => saves++); var shell = app.Shell; var rail = (FrameworkElement)app.Window.FindName("Rail"); var toggle = app.Window.InputBindings.OfType().Single(b => b.Key == Key.B && b.Modifiers == ModifierKeys.Control); Assert.False(shell.IsRailCollapsed); app.Window.UpdateLayout(); Assert.Approximately(200, rail.ActualWidth, 0.5); var buttons = app.FindAll().Where(b => b.IsVisible).ToList(); Assert.Count(shell.AllSections.Count(), buttons); foreach (var button in buttons) Assert.Equal(((SectionViewModel)button.DataContext).ToolTip, button.ToolTip); toggle.Command.Execute(toggle.CommandParameter); app.Window.UpdateLayout(); Assert.True(shell.IsRailCollapsed); Assert.True(shell.Services.Settings.RailCollapsed); Assert.Equal(1, saves, "the choice is written at once"); Assert.Approximately(48, rail.ActualWidth, 0.5); foreach (var button in buttons) { var section = (SectionViewModel)button.DataContext; // The icon's tooltip names the section; screen readers hear the name once (the name, then what it is for). Assert.Equal($"{section.Label} · {section.ToolTip}", button.ToolTip); Assert.Equal(section.Label, AutomationProperties.GetName(button)); Assert.Equal(section.ToolTip, AutomationProperties.GetHelpText(button)); } Assert.Contains("Ctrl+B", shell.RailToggleToolTip); // The ≡ button does the same, and the choice is written again. var menu = app.FindAll