Browse Source

fixes tests

pull/8224/head
daniel mayost 4 years ago
parent
commit
c77c500bcd
  1. 6
      src/Avalonia.Controls/ComboBox.cs
  2. 116
      tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs

6
src/Avalonia.Controls/ComboBox.cs

@ -432,11 +432,11 @@ namespace Avalonia.Controls
private void UpdateFlowDirection()
{
var rectangle = SelectionBoxItem as Rectangle;
if (rectangle != null)
if (SelectionBoxItem is Rectangle rectangle)
{
var content = (rectangle.Fill as VisualBrush)!.Visual as Control;
var flowDirection = (((IVisual)content!).VisualParent as Control)?.FlowDirection ?? FlowDirection.LeftToRight;
var flowDirection = (((IVisual)content!).VisualParent as Control)?.FlowDirection ??
FlowDirection.LeftToRight;
rectangle.FlowDirection = flowDirection;
}

116
tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs

@ -8,7 +8,7 @@ using Avalonia.Data;
using Avalonia.Input;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Threading;
using Avalonia.VisualTree;
using Avalonia.UnitTests;
using Xunit;
@ -340,80 +340,77 @@ namespace Avalonia.Controls.UnitTests
[Fact]
public void FlowDirection_Of_RectangleContent_Shuold_Be_LeftToRight()
{
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
var items = new[]
{
var items = new[]
{
new ComboBoxItem()
{
Content = new Control()
}
};
var target = new ComboBox
{
FlowDirection = FlowDirection.RightToLeft,
Items = items,
Template = GetTemplate()
};
new ComboBoxItem()
{
Content = new Control()
}
};
var target = new ComboBox
{
FlowDirection = FlowDirection.RightToLeft,
Items = items,
Template = GetTemplate()
};
var root = new TestRoot(target);
target.ApplyTemplate();
target.SelectedIndex = 0;
var root = new TestRoot(target);
target.ApplyTemplate();
target.SelectedIndex = 0;
var rectangle = target.GetValue(ComboBox.SelectionBoxItemProperty) as Rectangle;
var rectangle = target.GetValue(ComboBox.SelectionBoxItemProperty) as Rectangle;
Assert.Equal(FlowDirection.LeftToRight, rectangle.FlowDirection);
}
Assert.Equal(FlowDirection.LeftToRight, rectangle.FlowDirection);
}
[Fact]
public void FlowDirection_Of_RectangleContent_Updated_After_Change_ComboBox()
public void FlowDirection_Of_RectangleContent_Updated_After_InvalidateMirrorTransform()
{
using (UnitTestApplication.Start(TestServices.RealStyler))
var parentContent = new Decorator()
{
var items = new[]
{
new ComboBoxItem()
{
Content = new Control()
}
};
var target = new ComboBox
Child = new Control()
};
var items = new[]
{
new ComboBoxItem()
{
FlowDirection = FlowDirection.RightToLeft,
Items = items,
Template = GetTemplate()
};
var root = new TestRoot(target);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
target.SelectedIndex = 0;
((ContentPresenter)target.Presenter).UpdateChild();
var rectangle = target.GetValue(ComboBox.SelectionBoxItemProperty) as Rectangle;
// need help here, the 'rectangle' isn't connected to visual tree for some reason
Content = parentContent.Child
}
};
var target = new ComboBox
{
FlowDirection = FlowDirection.RightToLeft,
Items = items,
Template = GetTemplate()
};
Assert.True(rectangle.HasMirrorTransform);
var root = new TestRoot(target);
target.ApplyTemplate();
target.SelectedIndex = 0;
target.FlowDirection = FlowDirection.LeftToRight;
var rectangle = target.GetValue(ComboBox.SelectionBoxItemProperty) as Rectangle;
Assert.Equal(FlowDirection.LeftToRight, rectangle.FlowDirection);
Assert.False(rectangle.HasMirrorTransform);
}
parentContent.FlowDirection = FlowDirection.RightToLeft;
target.InvalidateMirrorTransform();
Assert.Equal(FlowDirection.RightToLeft, rectangle.FlowDirection);
}
[Fact]
public void FlowDirection_Of_RectangleContent_Updated_After_Content_In_VisualTree()
public void FlowDirection_Of_RectangleContent_Updated_After_OpenPopup()
{
using (UnitTestApplication.Start(TestServices.RealFocus))
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
Control content;
var items = new[]
var parentContent = new Decorator()
{
Child = new Control()
};
var items = new[]
{
new ComboBoxItem()
{
Content = content = new Control()
Content = parentContent.Child
}
};
var target = new ComboBox
@ -425,14 +422,17 @@ namespace Avalonia.Controls.UnitTests
var root = new TestRoot(target);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
target.SelectedIndex = 0;
// need help here how to connect 'content' to visual tree, or how to open popup
var rectangle = target.GetValue(ComboBox.SelectionBoxItemProperty) as Rectangle;
Assert.Equal(FlowDirection.LeftToRight, rectangle.FlowDirection);
parentContent.FlowDirection = FlowDirection.RightToLeft;
var popup = target.GetVisualDescendants().OfType<Popup>().First();
popup.PlacementTarget = new Window();
popup.Open();
Assert.Equal(FlowDirection.RightToLeft, rectangle.FlowDirection);
}
}

Loading…
Cancel
Save