feat(mosstank): add VTank-style automation PoC
This commit is contained in:
parent
f6fe0f2a4f
commit
4e6e9bc9d9
212 changed files with 49462 additions and 416 deletions
132
tests/AcDream.App.Tests/UI/PluginSidePanelTests.cs
Normal file
132
tests/AcDream.App.Tests/UI/PluginSidePanelTests.cs
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
using AcDream.App.UI;
|
||||
using AcDream.Plugin.Abstractions;
|
||||
|
||||
namespace AcDream.App.Tests.UI;
|
||||
|
||||
public sealed class PluginSidePanelTests
|
||||
{
|
||||
[Fact]
|
||||
public void ManyPluginsWrapIntoReachableColumnsWithinTheLiveScreenHeight()
|
||||
{
|
||||
var root = new UiRoot { Width = 800f, Height = 260f };
|
||||
using var shelf = new PluginSidePanel(
|
||||
root.WindowManager,
|
||||
_ => (0u, 0, 0),
|
||||
font: null);
|
||||
root.AddChild(shelf);
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
var frame = new UiPanel { Width = 200f, Height = 100f };
|
||||
root.AddChild(frame);
|
||||
RetailWindowHandle handle = root.WindowManager.Register(
|
||||
$"plugin:test:{i}",
|
||||
frame);
|
||||
shelf.Add(
|
||||
new PluginUiOwner($"test.{i}", $"Plugin {i}"),
|
||||
new PluginPanelDescriptor("main", $"Plugin {i}"),
|
||||
handle);
|
||||
}
|
||||
|
||||
root.Tick(0.016d, 16L);
|
||||
|
||||
Assert.Equal(12, shelf.EntryCount);
|
||||
Assert.True(shelf.Width > 36f);
|
||||
Assert.True(shelf.Top + shelf.Height <= root.Height);
|
||||
Assert.All(
|
||||
shelf.Children,
|
||||
child => Assert.True(child.Top + child.Height <= shelf.Height));
|
||||
Assert.Equal(root.Width - shelf.Width - 4f, shelf.Left);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShelfAndMinimizeButtonsHideAndRestoreWithoutUnregisteringWindow()
|
||||
{
|
||||
var root = new UiRoot { Width = 1280f, Height = 720f };
|
||||
var frame = new UiPanel
|
||||
{
|
||||
Width = 320f,
|
||||
Height = 180f,
|
||||
Visible = true,
|
||||
};
|
||||
root.AddChild(frame);
|
||||
RetailWindowHandle handle = root.WindowManager.Register(
|
||||
"plugin:acdream.test:main",
|
||||
frame);
|
||||
using var shelf = new PluginSidePanel(
|
||||
root.WindowManager,
|
||||
_ => (0u, 0, 0),
|
||||
font: null);
|
||||
root.AddChild(shelf);
|
||||
|
||||
shelf.Add(
|
||||
new PluginUiOwner("acdream.test", "Test Plugin"),
|
||||
new PluginPanelDescriptor("main", "Test Plugin")
|
||||
{
|
||||
IconText = "TP",
|
||||
},
|
||||
handle);
|
||||
|
||||
Assert.True(shelf.Visible);
|
||||
Assert.Equal(1, shelf.EntryCount);
|
||||
UiSimpleButton shelfButton = Assert.IsAssignableFrom<UiSimpleButton>(
|
||||
Assert.Single(shelf.Children));
|
||||
|
||||
shelfButton.OnEvent(new UiEvent { Type = UiEventType.Click });
|
||||
Assert.False(handle.IsVisible);
|
||||
Assert.True(handle.IsRegistered);
|
||||
|
||||
shelfButton.OnEvent(new UiEvent { Type = UiEventType.Click });
|
||||
Assert.True(handle.IsVisible);
|
||||
|
||||
UiSimpleButton minimize = Assert.IsAssignableFrom<UiSimpleButton>(
|
||||
Assert.Single(frame.Children));
|
||||
minimize.OnEvent(new UiEvent { Type = UiEventType.Click });
|
||||
Assert.False(handle.IsVisible);
|
||||
Assert.True(handle.IsRegistered);
|
||||
|
||||
root.WindowManager.Unregister(handle.Name);
|
||||
Assert.Equal(0, shelf.EntryCount);
|
||||
Assert.False(shelf.Visible);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FullWidthPluginWindowStartsAndStaysReachableAtMinimumCanvas()
|
||||
{
|
||||
var root = new UiRoot { Width = 800f, Height = 600f };
|
||||
var frame = new UiPanel
|
||||
{
|
||||
Left = 28f,
|
||||
Top = 42f,
|
||||
Width = 800f,
|
||||
Height = 244f,
|
||||
Visible = true,
|
||||
};
|
||||
root.AddChild(frame);
|
||||
RetailWindowHandle handle = root.WindowManager.Register(
|
||||
"plugin:acdream.mosstank:main",
|
||||
frame);
|
||||
using var shelf = new PluginSidePanel(
|
||||
root.WindowManager,
|
||||
_ => (0u, 0, 0),
|
||||
font: null);
|
||||
root.AddChild(shelf);
|
||||
|
||||
shelf.Add(
|
||||
new PluginUiOwner("acdream.mosstank", "MossTank"),
|
||||
new PluginPanelDescriptor("main", "MossTank"),
|
||||
handle);
|
||||
|
||||
Assert.Equal(0f, handle.Left);
|
||||
Assert.Equal(42f, handle.Top);
|
||||
Assert.True(frame.ConstrainDragToParent);
|
||||
Assert.True(frame.ConstrainResizeToParent);
|
||||
|
||||
frame.Left = 700f;
|
||||
frame.Top = 590f;
|
||||
root.Tick(0.016d, 16L);
|
||||
|
||||
Assert.Equal(0f, handle.Left);
|
||||
Assert.Equal(356f, handle.Top);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue