using Avalonia; using Avalonia.Controls; using Avalonia.Headless; using Avalonia.Media; using Avalonia.Threading; using Shouldly; using Xunit; using ZB.MOM.WW.LmxOpcUa.Client.UI.Controls; namespace ZB.MOM.WW.LmxOpcUa.Client.UI.Tests.Screenshots; public class DateTimeRangePickerScreenshot { private static readonly object Lock = new(); private static bool _initialized; private static void EnsureInitialized() { lock (Lock) { if (_initialized) return; _initialized = true; AppBuilder.Configure() .UseSkia() .UseHeadless(new AvaloniaHeadlessPlatformOptions { UseHeadlessDrawing = false }) .SetupWithoutStarting(); } } [Fact] public void TextBoxes_ShowValues_WhenSetBeforeLoad() { EnsureInitialized(); Dispatcher.UIThread.Invoke(() => { var picker = new DateTimeRangePicker { StartDateTime = new DateTimeOffset(2026, 3, 31, 8, 0, 0, TimeSpan.Zero), EndDateTime = new DateTimeOffset(2026, 3, 31, 14, 0, 0, TimeSpan.Zero) }; var window = new Window { Content = picker, Width = 700, Height = 70 }; window.Show(); Dispatcher.UIThread.RunJobs(); var startInput = picker.FindControl("StartInput"); var endInput = picker.FindControl("EndInput"); startInput.ShouldNotBeNull(); endInput.ShouldNotBeNull(); startInput!.Text.ShouldBe("2026-03-31 08:00:00"); endInput!.Text.ShouldBe("2026-03-31 14:00:00"); window.Close(); }); } [Fact] public void TextBoxes_ShowValues_WhenSetAfterLoad() { EnsureInitialized(); Dispatcher.UIThread.Invoke(() => { var picker = new DateTimeRangePicker(); var window = new Window { Content = picker, Width = 700, Height = 70 }; window.Show(); Dispatcher.UIThread.RunJobs(); // Set values after the control is loaded picker.StartDateTime = new DateTimeOffset(2026, 1, 15, 10, 30, 0, TimeSpan.Zero); picker.EndDateTime = new DateTimeOffset(2026, 1, 15, 18, 45, 0, TimeSpan.Zero); Dispatcher.UIThread.RunJobs(); var startInput = picker.FindControl("StartInput"); var endInput = picker.FindControl("EndInput"); startInput!.Text.ShouldBe("2026-01-15 10:30:00"); endInput!.Text.ShouldBe("2026-01-15 18:45:00"); window.Close(); }); } [Fact] public void PresetButtons_SetCorrectRange() { EnsureInitialized(); Dispatcher.UIThread.Invoke(() => { var picker = new DateTimeRangePicker(); var window = new Window { Content = picker, Width = 700, Height = 70 }; window.Show(); Dispatcher.UIThread.RunJobs(); // Click the 1h preset var lastHourBtn = picker.FindControl