Browse Source

Added failing tests for #3796.

pull/3797/head
Steven Kirk 7 years ago
parent
commit
908eef0b0d
  1. 63
      tests/Avalonia.Controls.UnitTests/Primitives/PopupRootTests.cs
  2. 26
      tests/Avalonia.Controls.UnitTests/WindowTests.cs
  3. 6
      tests/Avalonia.UnitTests/MockWindowingPlatform.cs

63
tests/Avalonia.Controls.UnitTests/Primitives/PopupRootTests.cs

@ -2,12 +2,14 @@ using System;
using System.Linq;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Primitives.PopupPositioning;
using Avalonia.Controls.Templates;
using Avalonia.LogicalTree;
using Avalonia.Platform;
using Avalonia.Styling;
using Avalonia.UnitTests;
using Avalonia.VisualTree;
using Moq;
using Xunit;
namespace Avalonia.Controls.UnitTests.Primitives
@ -216,12 +218,10 @@ namespace Avalonia.Controls.UnitTests.Primitives
var window = new Window();
var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl);
popupImpl.Setup(x => x.ClientSize).Returns(new Size(400, 480));
var child = new Canvas
{
Width = 400,
Height = 800,
Height = 1344,
};
var target = CreateTarget(window, popupImpl.Object);
@ -229,7 +229,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
target.Show();
Assert.Equal(new Size(400, 480), target.Bounds.Size);
Assert.Equal(new Size(400, 1024), target.Bounds.Size);
// Issue #3784 causes this to be (0, 160) which makes no sense as Window has no
// parent control to be offset against.
@ -237,6 +237,61 @@ namespace Avalonia.Controls.UnitTests.Primitives
}
}
[Fact]
public void MinWidth_MinHeight_Should_Be_Respected()
{
// Issue #3796
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var window = new Window();
var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl);
var target = CreateTarget(window, popupImpl.Object);
target.MinWidth = 400;
target.MinHeight = 800;
target.Content = new Border
{
Width = 100,
Height = 100,
};
target.Show();
Assert.Equal(new Rect(0, 0, 400, 800), target.Bounds);
Assert.Equal(new Size(400, 800), target.ClientSize);
Assert.Equal(new Size(400, 800), target.PlatformImpl.ClientSize);
}
}
[Fact]
public void Setting_Width_Should_Resize_WindowImpl()
{
// Issue #3796
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var window = new Window();
var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl);
var positioner = new Mock<IPopupPositioner>();
popupImpl.Setup(x => x.PopupPositioner).Returns(positioner.Object);
var target = CreateTarget(window, popupImpl.Object);
target.Width = 400;
target.Height = 800;
target.Show();
Assert.Equal(400, target.Width);
Assert.Equal(800, target.Height);
target.Width = 410;
target.LayoutManager.ExecuteLayoutPass();
positioner.Verify(x =>
x.Update(It.Is<PopupPositionerParameters>(x => x.Size.Width == 410)));
Assert.Equal(410, target.Width);
}
}
private PopupRoot CreateTarget(TopLevel popupParent, IPopupImpl impl = null)
{
impl ??= popupParent.PlatformImpl.CreatePopup();

26
tests/Avalonia.Controls.UnitTests/WindowTests.cs

@ -514,6 +514,32 @@ namespace Avalonia.Controls.UnitTests
}
}
[Fact]
public void Setting_Width_Should_Resize_WindowImpl()
{
// Issue #3796
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var target = new Window()
{
Width = 400,
Height = 800,
};
target.Show();
Assert.Equal(400, target.Width);
Assert.Equal(800, target.Height);
target.Width = 410;
target.LayoutManager.ExecuteLayoutPass();
var windowImpl = Mock.Get(target.PlatformImpl);
windowImpl.Verify(x => x.Resize(new Size(410, 800)));
Assert.Equal(410, target.Width);
}
}
private IWindowImpl CreateImpl(Mock<IRenderer> renderer)
{
return Mock.Of<IWindowImpl>(x =>

6
tests/Avalonia.UnitTests/MockWindowingPlatform.cs

@ -66,15 +66,19 @@ namespace Avalonia.UnitTests
public static Mock<IPopupImpl> CreatePopupMock(IWindowBaseImpl parent)
{
var popupImpl = new Mock<IPopupImpl>();
var clientSize = new Size();
var positionerHelper = new ManagedPopupPositionerPopupImplHelper(parent, (pos, size, scale) =>
{
clientSize = size.Constrain(s_screenSize);
popupImpl.Object.PositionChanged?.Invoke(pos);
popupImpl.Object.Resized?.Invoke(size);
popupImpl.Object.Resized?.Invoke(clientSize);
});
var positioner = new ManagedPopupPositioner(positionerHelper);
popupImpl.SetupAllProperties();
popupImpl.Setup(x => x.ClientSize).Returns(() => clientSize);
popupImpl.Setup(x => x.Scaling).Returns(1);
popupImpl.Setup(x => x.PopupPositioner).Returns(positioner);

Loading…
Cancel
Save