Browse Source
Controls not attached to the visual tree should not notify the `LayoutManager` that they have had their layout invalidated. Similarly when added to the visual tree their parents and themselves should have their layout invalidated.pull/1021/head
3 changed files with 123 additions and 11 deletions
@ -0,0 +1,90 @@ |
|||
using System; |
|||
using Avalonia.Controls; |
|||
using Moq; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Layout.UnitTests |
|||
{ |
|||
public class LayoutableTests |
|||
{ |
|||
[Fact] |
|||
public void Only_Calls_LayoutManager_InvalidateMeasure_Once() |
|||
{ |
|||
var target = new Mock<ILayoutManager>(); |
|||
|
|||
using (Start(target.Object)) |
|||
{ |
|||
var control = new Decorator(); |
|||
var root = new LayoutTestRoot { Child = control }; |
|||
|
|||
root.Measure(Size.Infinity); |
|||
root.Arrange(new Rect(root.DesiredSize)); |
|||
target.ResetCalls(); |
|||
|
|||
control.InvalidateMeasure(); |
|||
control.InvalidateMeasure(); |
|||
|
|||
target.Verify(x => x.InvalidateMeasure(control), Times.Once()); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void Only_Calls_LayoutManager_InvalidateArrange_Once() |
|||
{ |
|||
var target = new Mock<ILayoutManager>(); |
|||
|
|||
using (Start(target.Object)) |
|||
{ |
|||
var control = new Decorator(); |
|||
var root = new LayoutTestRoot { Child = control }; |
|||
|
|||
root.Measure(Size.Infinity); |
|||
root.Arrange(new Rect(root.DesiredSize)); |
|||
target.ResetCalls(); |
|||
|
|||
control.InvalidateArrange(); |
|||
control.InvalidateArrange(); |
|||
|
|||
target.Verify(x => x.InvalidateArrange(control), Times.Once()); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void Attaching_Control_To_Tree_Invalidates_Parent_Measure() |
|||
{ |
|||
var target = new Mock<ILayoutManager>(); |
|||
|
|||
using (Start(target.Object)) |
|||
{ |
|||
var control = new Decorator(); |
|||
var root = new LayoutTestRoot { Child = control }; |
|||
|
|||
root.Measure(Size.Infinity); |
|||
root.Arrange(new Rect(root.DesiredSize)); |
|||
Assert.True(control.IsMeasureValid); |
|||
|
|||
root.Child = null; |
|||
root.Measure(Size.Infinity); |
|||
root.Arrange(new Rect(root.DesiredSize)); |
|||
|
|||
Assert.False(control.IsMeasureValid); |
|||
Assert.True(root.IsMeasureValid); |
|||
|
|||
target.ResetCalls(); |
|||
|
|||
root.Child = control; |
|||
|
|||
Assert.False(root.IsMeasureValid); |
|||
Assert.False(control.IsMeasureValid); |
|||
target.Verify(x => x.InvalidateMeasure(root), Times.Once()); |
|||
} |
|||
} |
|||
|
|||
private IDisposable Start(ILayoutManager layoutManager) |
|||
{ |
|||
var result = AvaloniaLocator.EnterScope(); |
|||
AvaloniaLocator.CurrentMutable.Bind<ILayoutManager>().ToConstant(layoutManager); |
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue