mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Robust.UnitTesting was both ALL tests for RT, and also API surface for content tests. Tests are now split into separate projects as appropriate, and the API side has also been split off.
75 lines
2.5 KiB
C#
75 lines
2.5 KiB
C#
using System.Numerics;
|
|
using NUnit.Framework;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Shared.Maths;
|
|
|
|
namespace Robust.UnitTesting.Client.UserInterface.Controls
|
|
{
|
|
[TestFixture]
|
|
[TestOf(typeof(PopupContainer))]
|
|
public sealed class PopupContainerTest : RobustUnitTest
|
|
{
|
|
public override UnitTestProject Project => UnitTestProject.Client;
|
|
|
|
[Test]
|
|
public void Test()
|
|
{
|
|
var container = new PopupContainer {MinSize = new Vector2(100, 100)};
|
|
|
|
container.Arrange(new UIBox2(0, 0, 100, 100));
|
|
|
|
var popup = new Control {MinSize = new Vector2(50, 50)};
|
|
|
|
container.AddChild(popup);
|
|
|
|
PopupContainer.SetPopupOrigin(popup, new Vector2(25, 25));
|
|
|
|
container.InvalidateArrange();
|
|
container.Arrange(new UIBox2(0, 0, 100, 100));
|
|
|
|
Assert.That(popup.Position, Is.EqualTo(new Vector2(25, 25)));
|
|
Assert.That(popup.Size, Is.EqualTo(new Vector2(50, 50)));
|
|
|
|
// Test that pos gets pushed back to the top left if the size + offset is too large to fit.
|
|
PopupContainer.SetPopupOrigin(popup, new Vector2(75, 75));
|
|
|
|
container.InvalidateArrange();
|
|
container.Arrange(new UIBox2(0, 0, 100, 100));
|
|
|
|
Assert.That(popup.Position, Is.EqualTo(new Vector2(50, 50)));
|
|
Assert.That(popup.Size, Is.EqualTo(new Vector2(50, 50)));
|
|
|
|
// Test that pos = 0 if the popup is too large to fit.
|
|
popup.MinSize = new Vector2(150, 150);
|
|
|
|
container.InvalidateArrange();
|
|
container.Arrange(new UIBox2(0, 0, 100, 100));
|
|
|
|
Assert.That(popup.Position, Is.EqualTo(new Vector2(0, 0)));
|
|
Assert.That(popup.Size, Is.EqualTo(new Vector2(150, 150)));
|
|
}
|
|
|
|
[Test]
|
|
public void TestAltPos()
|
|
{
|
|
var container = new PopupContainer {MinSize = new Vector2(100, 100)};
|
|
|
|
container.Arrange(new UIBox2(0, 0, 100, 100));
|
|
|
|
var popup = new Control {MinSize = new Vector2(50, 50)};
|
|
|
|
container.AddChild(popup);
|
|
|
|
PopupContainer.SetPopupOrigin(popup, new Vector2(75, 75));
|
|
PopupContainer.SetAltOrigin(popup, new Vector2(65, 25));
|
|
|
|
container.InvalidateArrange();
|
|
container.Arrange(new UIBox2(0, 0, 100, 100));
|
|
|
|
Assert.That(popup.Position, Is.EqualTo(new Vector2(15, 25)));
|
|
Assert.That(popup.Size, Is.EqualTo(new Vector2(50, 50)));
|
|
}
|
|
}
|
|
}
|