mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-08-19 06:43:25 +08:00
feat: implement AirAppRuntimeBridge for managing runtime lifecycle and add corresponding unit tests for launcher window and runtime orchestration
This commit is contained in:
77
LanMountainDesktop.Tests/SplashWindowLifecycleTests.cs
Normal file
77
LanMountainDesktop.Tests/SplashWindowLifecycleTests.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Headless.XUnit;
|
||||
using Avalonia.Threading;
|
||||
using LanMountainDesktop.Launcher.Shell;
|
||||
using LanMountainDesktop.Launcher.Views;
|
||||
using Xunit;
|
||||
|
||||
namespace LanMountainDesktop.Tests;
|
||||
|
||||
public sealed class SplashWindowLifecycleTests
|
||||
{
|
||||
[AvaloniaFact]
|
||||
public async Task DismissAsync_WhenCalledConcurrentlyOffUiThread_ClosesExactlyOnce()
|
||||
{
|
||||
var window = new SplashWindow();
|
||||
var closedCount = 0;
|
||||
window.Closed += (_, _) => Interlocked.Increment(ref closedCount);
|
||||
window.Show();
|
||||
|
||||
var dismissTasks = await Task.Run(() =>
|
||||
Enumerable.Range(0, 8)
|
||||
.Select(_ => window.DismissAsync())
|
||||
.ToArray());
|
||||
|
||||
Assert.All(dismissTasks, task => Assert.Same(dismissTasks[0], task));
|
||||
await Task.WhenAll(dismissTasks);
|
||||
|
||||
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
Assert.False(window.IsVisible);
|
||||
Assert.False(window.IsHitTestVisible);
|
||||
Assert.Equal(1, closedCount);
|
||||
});
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public async Task CloseWindowsAsync_WaitsUntilSplashIsNoLongerVisible()
|
||||
{
|
||||
var window = new SplashWindow();
|
||||
var closed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
window.Closed += (_, _) => closed.TrySetResult();
|
||||
window.Show();
|
||||
|
||||
await Task.Run(() => LaunchUiPresenter.CloseWindowsAsync(window, loadingDetailsWindow: null));
|
||||
|
||||
Assert.True(closed.Task.IsCompleted);
|
||||
await Dispatcher.UIThread.InvokeAsync(() => Assert.False(window.IsVisible));
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public async Task DismissAsync_WhenCloseIsCancelled_LeavesWindowHiddenAndNonHitTestable()
|
||||
{
|
||||
var window = new SplashWindow();
|
||||
var closeWasCancelled = false;
|
||||
|
||||
void CancelClose(object? sender, WindowClosingEventArgs args)
|
||||
{
|
||||
closeWasCancelled = true;
|
||||
args.Cancel = true;
|
||||
}
|
||||
|
||||
window.Closing += CancelClose;
|
||||
window.Show();
|
||||
|
||||
await Task.Run(() => window.DismissAsync());
|
||||
|
||||
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
Assert.True(closeWasCancelled);
|
||||
Assert.False(window.IsVisible);
|
||||
Assert.False(window.IsHitTestVisible);
|
||||
|
||||
window.Closing -= CancelClose;
|
||||
window.Close();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user