Browse Source

idk

pull/438/head
JT 11 months ago
parent
commit
552af92943
  1. 22
      StabilityMatrix.UITests/Extensions/WindowExtensions.cs
  2. 49
      StabilityMatrix.UITests/MainWindowTests.cs
  3. 26
      StabilityMatrix.UITests/ModelBrowser/CivitAiBrowserTests.cs
  4. BIN
      StabilityMatrix.UITests/Snapshots/MainWindowTests.MainWindow_ShouldOpen.verified.png
  5. 12
      StabilityMatrix.UITests/StabilityMatrix.UITests.csproj
  6. 27
      StabilityMatrix.UITests/TestBase.cs

22
StabilityMatrix.UITests/Extensions/WindowExtensions.cs

@ -19,16 +19,12 @@ public static class WindowExtensions
}
if (targetVisualRoot.Equals(topLevel))
{
throw new ArgumentException(
"Target is not part of the same visual tree as the top level"
);
throw new ArgumentException("Target is not part of the same visual tree as the top level");
}
var point =
target.TranslatePoint(
new Point(target.Bounds.Width / 2, target.Bounds.Height / 2),
topLevel
) ?? throw new NullReferenceException("Point is null");
target.TranslatePoint(new Point(target.Bounds.Width / 2, target.Bounds.Height / 2), topLevel)
?? throw new NullReferenceException("Point is null");
topLevel.MouseMove(point);
topLevel.MouseDown(point, MouseButton.Left);
@ -48,16 +44,12 @@ public static class WindowExtensions
}
if (!targetVisualRoot.Equals(topLevel))
{
throw new ArgumentException(
"Target is not part of the same visual tree as the top level"
);
throw new ArgumentException("Target is not part of the same visual tree as the top level");
}
var point =
target.TranslatePoint(
new Point(target.Bounds.Width / 2, target.Bounds.Height / 2),
topLevel
) ?? throw new NullReferenceException("Point is null");
target.TranslatePoint(new Point(target.Bounds.Width / 2, target.Bounds.Height / 2), topLevel)
?? throw new NullReferenceException("Point is null");
topLevel.MouseMove(point);
topLevel.MouseDown(point, MouseButton.Left);
@ -68,6 +60,6 @@ public static class WindowExtensions
// Return mouse to outside of window
topLevel.MouseMove(new Point(-50, -50));
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.RunJobs());
await Task.Delay(300);
}
}

49
StabilityMatrix.UITests/MainWindowTests.cs

@ -1,9 +1,9 @@
using Avalonia.Controls;
using Avalonia.Threading;
using Avalonia.VisualTree;
using FluentAvalonia.UI.Controls;
using Microsoft.Extensions.DependencyInjection;
using StabilityMatrix.Avalonia.ViewModels;
using StabilityMatrix.Avalonia.Views.Dialogs;
using StabilityMatrix.Avalonia.Views;
using StabilityMatrix.UITests.Extensions;
namespace StabilityMatrix.UITests;
@ -19,30 +19,9 @@ public class MainWindowTests : TestBase
var (window, _) = GetMainWindow();
window.Show();
await Task.Delay(300);
Dispatcher.UIThread.RunJobs();
// Find the select data directory dialog
var selectDataDirectoryDialog = await WaitHelper.WaitForNotNullAsync(() => GetWindowDialog(window));
Assert.NotNull(selectDataDirectoryDialog);
// Click continue button
var continueButton = selectDataDirectoryDialog
.GetVisualDescendants()
.OfType<Button>()
.First(b => b.Content as string == "Continue");
await window.ClickTargetAsync(continueButton);
await Task.Delay(300);
Dispatcher.UIThread.RunJobs();
// Find the one click install dialog
var oneClickDialog = await WaitHelper.WaitForConditionAsync(
() => GetWindowDialog(window),
d => d?.Content is OneClickInstallDialog
);
Assert.NotNull(oneClickDialog);
await DoInitialSetup();
await Task.Delay(1000);
await Verify(window, Settings);
@ -54,4 +33,26 @@ public class MainWindowTests : TestBase
var viewModel = Services.GetRequiredService<MainWindowViewModel>();
await Verify(viewModel, Settings);
}
[AvaloniaFact, TestPriority(3)]
public async Task NavigateToModelBrowser_ShouldWork()
{
var (window, viewModel) = GetMainWindow();
await DoInitialSetup();
var y = window
.FindDescendantOfType<NavigationView>()
.GetVisualDescendants()
.OfType<NavigationViewItem>()
.FirstOrDefault(i => i.Content.ToString() == "Model Browser");
await window.ClickTargetAsync(y);
var frame = window.FindControl<Frame>("FrameView");
Assert.IsType<CheckpointBrowserPage>(frame.Content);
await Task.Delay(1000);
SaveScreenshot(window);
await Verify(window, Settings);
}
}

26
StabilityMatrix.UITests/ModelBrowser/CivitAiBrowserTests.cs

@ -10,28 +10,4 @@ namespace StabilityMatrix.UITests.ModelBrowser;
[UsesVerify]
[Collection("TempDir")]
public class CivitAiBrowserTests : TestBase
{
[AvaloniaFact]
public async Task NavigateToModelBrowser_ShouldWork()
{
var (window, viewModel) = GetMainWindow();
await DoInitialSetup();
var y = window
.FindDescendantOfType<NavigationView>()
.GetVisualDescendants()
.OfType<NavigationViewItem>()
.FirstOrDefault(i => i.Content.ToString() == "Model Browser");
await window.ClickTargetAsync(y);
await Task.Delay(300);
Dispatcher.UIThread.RunJobs();
var frame = window.FindControl<Frame>("FrameView");
Assert.IsType<CheckpointBrowserPage>(frame.Content);
await Task.Delay(1000);
await Verify(window, Settings);
}
}
public class CivitAiBrowserTests : TestBase { }

BIN
StabilityMatrix.UITests/Snapshots/MainWindowTests.MainWindow_ShouldOpen.verified.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 203 KiB

After

Width:  |  Height:  |  Size: 18 KiB

12
StabilityMatrix.UITests/StabilityMatrix.UITests.csproj

@ -10,21 +10,21 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia.Headless.XUnit" Version="11.0.5" />
<PackageReference Include="Avalonia.Headless.XUnit" Version="11.0.6" />
<PackageReference Include="DotNet.Bundle" Version="0.9.13" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="Verify" Version="22.4.1" />
<PackageReference Include="Verify" Version="22.11.1" />
<PackageReference Include="Verify.CommunityToolkit.Mvvm" Version="0.1.0" />
<PackageReference Include="Verify.Avalonia" Version="1.0.1" />
<PackageReference Include="Verify.Phash" Version="3.1.0" />
<PackageReference Include="Verify.Xunit" Version="22.4.1" />
<PackageReference Include="xunit" Version="2.6.1"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PackageReference Include="Verify.Xunit" Version="22.11.1" />
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

27
StabilityMatrix.UITests/TestBase.cs

@ -1,5 +1,6 @@
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using Avalonia.VisualTree;
using FluentAvalonia.UI.Controls;
@ -72,6 +73,8 @@ public class TestBase
Dispatcher.UIThread.RunJobs();
}
try
{
var dialog = await WaitHelper.WaitForNotNullAsync(() => GetWindowDialog(window));
if (dialog.Content is SelectDataDirectoryDialog selectDataDirectoryDialog)
@ -114,6 +117,11 @@ public class TestBase
Dispatcher.UIThread.RunJobs();
}
}
catch (TimeoutException)
{
// ignored
}
}
internal static async Task CloseUpdateDialog()
{
@ -166,4 +174,23 @@ public class TestBase
return (contentDialog, contentDialog.Content as T)!;
}
internal void SaveScreenshot(Visual visual)
{
var rect = new Rect(visual!.Bounds.Size);
var pixelSize = new PixelSize((int)rect.Width, (int)rect.Height);
var dpiVector = new Vector(96, 96);
using var bitmap = new RenderTargetBitmap(pixelSize, dpiVector);
using var fs = File.Open(
$"C:\\StabilityMatrix\\StabilityMatrix-avalonia\\StabilityMatrix.UITests\\"
+ Guid.NewGuid().ToString()
+ ".png",
FileMode.OpenOrCreate
);
bitmap.Render(visual);
bitmap.Save(fs);
fs.Flush();
}
}

Loading…
Cancel
Save