using System.Globalization;
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.Advice;
using Titano.Core.Export;
using Titano.Core.Localization;
using Titano.Core.Model;
using Titano.Core.Project;
using Titano.Testing;
using Titano.Ui.Controls;
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];
/// Here rather than with the other texts: it switches the UI language, which only a serial class may do.
[Test]
public void AnOptimiseLinePointsFromTheOldValueToTheNewOneInEitherReadingDirection()
{
var change = new SettingChange(AdvisorParameters.DeflickerWindow, 21, 41, "reason", []);
try
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
Assert.Equal("Deflicker window: 21 frames → 41 frames", EditorText.Change(change));
Loc.SetCulture(CultureInfo.GetCultureInfo("ar"));
Assert.Equal(Loc.L("Editor.Optimise.ChangeRtl", Loc.L("Editor.Exposure.Window"), Loc.Plural("Editor.Value.Frames", 21), Loc.Plural("Editor.Value.Frames", 41)),
EditorText.Change(change), "Arabic reads the old value first, from the right");
Assert.Contains("←", EditorText.Change(change));
}
finally
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
}
}
[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);
Assert.Equal("Titano — Harbour sunset", shell.WindowTitle, "the window title follows the open sequence");
Assert.False(shell.IsJobBarVisible, "the idle job bar gives its height to the editor");
// The Render split button can be clicked once the plan exists (its command re-reads its state).
Assert.True(await editor.WhenIdleAsync(TimeSpan.FromSeconds(60)), "the editor settled");
await SettleAsync(window);
Assert.True(editor.CanRender, editor.RenderBlockedReason ?? "renderable");
var render = Find(window).Single(b => b.IsVisible);
Assert.True(Find