1 changed files with 155 additions and 65 deletions
@ -1,112 +1,202 @@ |
|||||
using Moq; |
|
||||
|
|
||||
using Avalonia.Controls.Primitives; |
using Avalonia.Controls.Primitives; |
||||
using Avalonia.Input; |
using Avalonia.Input; |
||||
using Avalonia.Platform; |
using Avalonia.Platform; |
||||
using Avalonia.UnitTests; |
using Avalonia.UnitTests; |
||||
|
|
||||
|
using Moq; |
||||
|
|
||||
using Xunit; |
using Xunit; |
||||
|
|
||||
namespace Avalonia.Controls.UnitTests |
namespace Avalonia.Controls.UnitTests |
||||
{ |
{ |
||||
public class GridSplitterTests |
public class GridSplitterTests |
||||
{ |
{ |
||||
[Fact] |
public GridSplitterTests() |
||||
public void Vertical_Stays_Within_Constraints() |
|
||||
{ |
{ |
||||
var cursorFactoryImpl = new Mock<IStandardCursorFactory>(); |
var cursorFactoryImpl = new Mock<IStandardCursorFactory>(); |
||||
AvaloniaLocator.CurrentMutable.Bind<IStandardCursorFactory>().ToConstant(cursorFactoryImpl.Object); |
AvaloniaLocator.CurrentMutable.Bind<IStandardCursorFactory>().ToConstant(cursorFactoryImpl.Object); |
||||
|
} |
||||
|
|
||||
var control1 = new Border { [Grid.ColumnProperty] = 0 }; |
[Fact] |
||||
var splitter = new GridSplitter |
public void Detects_Horizontal_Orientation() |
||||
{ |
{ |
||||
[Grid.ColumnProperty] = 1, |
var grid = new Grid() |
||||
}; |
{ |
||||
var control2 = new Border { [Grid.ColumnProperty] = 2 }; |
RowDefinitions = new RowDefinitions("*,Auto,*"), |
||||
|
ColumnDefinitions = new ColumnDefinitions("*,*"), |
||||
|
Children = new Controls() |
||||
|
{ |
||||
|
new Border { [Grid.RowProperty] = 0 }, |
||||
|
new GridSplitter { [Grid.RowProperty] = 1, Name = "splitter" }, |
||||
|
new Border { [Grid.RowProperty] = 2 } |
||||
|
} |
||||
|
}; |
||||
|
|
||||
var columnDefinitions = new ColumnDefinitions() |
var root = new TestRoot { Child = grid }; |
||||
{ |
root.Measure(new Size(100, 300)); |
||||
new ColumnDefinition(1, GridUnitType.Star) {MinWidth = 10, MaxWidth = 190}, |
root.Arrange(new Rect(0, 0, 100, 300)); |
||||
new ColumnDefinition(GridLength.Auto), |
Assert.Contains(grid.FindControl<GridSplitter>("splitter").Classes, ":horizontal".Equals); |
||||
new ColumnDefinition(1, GridUnitType.Star) {MinWidth = 80, MaxWidth = 120}, |
} |
||||
}; |
|
||||
|
|
||||
|
[Fact] |
||||
|
public void Detects_Vertical_Orientation() |
||||
|
{ |
||||
var grid = new Grid() |
var grid = new Grid() |
||||
{ |
{ |
||||
ColumnDefinitions = columnDefinitions, |
ColumnDefinitions = new ColumnDefinitions("*,Auto,*"), |
||||
Children = new Controls() |
RowDefinitions = new RowDefinitions("*,*"), |
||||
{ |
Children = new Controls() |
||||
control1, splitter, control2 |
{ |
||||
} |
new Border { [Grid.ColumnProperty] = 0 }, |
||||
}; |
new GridSplitter { [Grid.ColumnProperty] = 1, Name = "splitter" }, |
||||
|
new Border { [Grid.ColumnProperty] = 2 }, |
||||
|
} |
||||
|
}; |
||||
|
|
||||
var root = new TestRoot { Child = grid }; |
var root = new TestRoot { Child = grid }; |
||||
|
root.Measure(new Size(100, 300)); |
||||
|
root.Arrange(new Rect(0, 0, 100, 300)); |
||||
|
Assert.Contains(grid.FindControl<GridSplitter>("splitter").Classes, ":vertical".Equals); |
||||
|
} |
||||
|
|
||||
root.Measure(new Size(200, 100)); |
[Fact] |
||||
root.Arrange(new Rect(0, 0, 200, 100)); |
public void Detects_With_Both_Auto() |
||||
|
{ |
||||
|
var grid = new Grid() |
||||
|
{ |
||||
|
ColumnDefinitions = new ColumnDefinitions("Auto,Auto,Auto"), |
||||
|
RowDefinitions = new RowDefinitions("Auto,Auto"), |
||||
|
Children = new Controls() |
||||
|
{ |
||||
|
new Border { [Grid.ColumnProperty] = 0 }, |
||||
|
new GridSplitter { [Grid.ColumnProperty] = 1, Name = "splitter" }, |
||||
|
new Border { [Grid.ColumnProperty] = 2 }, |
||||
|
} |
||||
|
}; |
||||
|
|
||||
splitter.RaiseEvent(new VectorEventArgs |
var root = new TestRoot { Child = grid }; |
||||
{ |
root.Measure(new Size(100, 300)); |
||||
RoutedEvent = Thumb.DragDeltaEvent, |
root.Arrange(new Rect(0, 0, 100, 300)); |
||||
Vector = new Vector(-100,0) |
Assert.Contains(grid.FindControl<GridSplitter>("splitter").Classes, ":vertical".Equals); |
||||
}); |
|
||||
Assert.Equal(columnDefinitions[0].Width, new GridLength(80,GridUnitType.Star)); |
|
||||
Assert.Equal(columnDefinitions[2].Width, new GridLength(120,GridUnitType.Star)); |
|
||||
splitter.RaiseEvent(new VectorEventArgs |
|
||||
{ |
|
||||
RoutedEvent = Thumb.DragDeltaEvent, |
|
||||
Vector = new Vector(100, 0) |
|
||||
}); |
|
||||
Assert.Equal(columnDefinitions[0].Width, new GridLength(120, GridUnitType.Star)); |
|
||||
Assert.Equal(columnDefinitions[2].Width, new GridLength(80, GridUnitType.Star)); |
|
||||
} |
} |
||||
|
|
||||
[Fact] |
[Fact] |
||||
public void Horizontal_Stays_Within_Constraints() |
public void Horizontal_Stays_Within_Constraints() |
||||
{ |
{ |
||||
var cursorFactoryImpl = new Mock<IStandardCursorFactory>(); |
|
||||
AvaloniaLocator.CurrentMutable.Bind<IStandardCursorFactory>().ToConstant(cursorFactoryImpl.Object); |
|
||||
|
|
||||
var control1 = new Border { [Grid.RowProperty] = 0 }; |
var control1 = new Border { [Grid.RowProperty] = 0 }; |
||||
var splitter = new GridSplitter |
var splitter = new GridSplitter |
||||
{ |
{ |
||||
[Grid.RowProperty] = 1, |
[Grid.RowProperty] = 1, |
||||
}; |
}; |
||||
var control2 = new Border { [Grid.RowProperty] = 2 }; |
var control2 = new Border { [Grid.RowProperty] = 2 }; |
||||
|
|
||||
var rowDefinitions = new RowDefinitions() |
var rowDefinitions = new RowDefinitions() |
||||
{ |
{ |
||||
new RowDefinition(1, GridUnitType.Star) {MinHeight = 70, MaxHeight = 110}, |
new RowDefinition(1, GridUnitType.Star) { MinHeight = 70, MaxHeight = 110 }, |
||||
new RowDefinition(GridLength.Auto), |
new RowDefinition(GridLength.Auto), |
||||
new RowDefinition(1, GridUnitType.Star) { MinHeight = 10, MaxHeight = 140}, |
new RowDefinition(1, GridUnitType.Star) { MinHeight = 10, MaxHeight = 140 }, |
||||
}; |
}; |
||||
|
|
||||
var grid = new Grid() |
var grid = new Grid() |
||||
{ |
{ |
||||
RowDefinitions = rowDefinitions, |
RowDefinitions = rowDefinitions, |
||||
Children = new Controls() |
Children = new Controls() |
||||
{ |
{ |
||||
control1, splitter, control2 |
control1, splitter, control2 |
||||
} |
} |
||||
}; |
}; |
||||
|
|
||||
var root = new TestRoot { Child = grid }; |
var root = new TestRoot { Child = grid }; |
||||
root.Measure(new Size(100, 200)); |
root.Measure(new Size(100, 200)); |
||||
root.Arrange(new Rect(0, 0, 100, 200)); |
root.Arrange(new Rect(0, 0, 100, 200)); |
||||
|
|
||||
splitter.RaiseEvent(new VectorEventArgs |
splitter.RaiseEvent(new VectorEventArgs |
||||
{ |
{ |
||||
RoutedEvent = Thumb.DragDeltaEvent, |
RoutedEvent = Thumb.DragDeltaEvent, |
||||
Vector = new Vector(0, -100) |
Vector = new Vector(0, -100) |
||||
}); |
}); |
||||
Assert.Equal(rowDefinitions[0].Height, new GridLength(70, GridUnitType.Star)); |
Assert.Equal(rowDefinitions[0].Height, new GridLength(70, GridUnitType.Star)); |
||||
Assert.Equal(rowDefinitions[2].Height, new GridLength(130, GridUnitType.Star)); |
Assert.Equal(rowDefinitions[2].Height, new GridLength(130, GridUnitType.Star)); |
||||
splitter.RaiseEvent(new VectorEventArgs |
splitter.RaiseEvent(new VectorEventArgs |
||||
{ |
{ |
||||
RoutedEvent = Thumb.DragDeltaEvent, |
RoutedEvent = Thumb.DragDeltaEvent, |
||||
Vector = new Vector(0, 100) |
Vector = new Vector(0, 100) |
||||
}); |
}); |
||||
Assert.Equal(rowDefinitions[0].Height, new GridLength(110, GridUnitType.Star)); |
Assert.Equal(rowDefinitions[0].Height, new GridLength(110, GridUnitType.Star)); |
||||
Assert.Equal(rowDefinitions[2].Height, new GridLength(90, GridUnitType.Star)); |
Assert.Equal(rowDefinitions[2].Height, new GridLength(90, GridUnitType.Star)); |
||||
} |
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void In_First_Position_Doesnt_Throw_Exception() |
||||
|
{ |
||||
|
var grid = new Grid() |
||||
|
{ |
||||
|
ColumnDefinitions = new ColumnDefinitions("Auto,*,*"), |
||||
|
RowDefinitions = new RowDefinitions("*,*"), |
||||
|
Children = new Controls() |
||||
|
{ |
||||
|
new GridSplitter { [Grid.ColumnProperty] = 0, Name = "splitter" }, |
||||
|
new Border { [Grid.ColumnProperty] = 1 }, |
||||
|
new Border { [Grid.ColumnProperty] = 2 }, |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
var root = new TestRoot { Child = grid }; |
||||
|
root.Measure(new Size(100, 300)); |
||||
|
root.Arrange(new Rect(0, 0, 100, 300)); |
||||
|
var splitter = grid.FindControl<GridSplitter>("splitter"); |
||||
|
splitter.RaiseEvent(new VectorEventArgs |
||||
|
{ |
||||
|
RoutedEvent = Thumb.DragDeltaEvent, |
||||
|
Vector = new Vector(100, 1000) |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Vertical_Stays_Within_Constraints() |
||||
|
{ |
||||
|
var control1 = new Border { [Grid.ColumnProperty] = 0 }; |
||||
|
var splitter = new GridSplitter |
||||
|
{ |
||||
|
[Grid.ColumnProperty] = 1, |
||||
|
}; |
||||
|
var control2 = new Border { [Grid.ColumnProperty] = 2 }; |
||||
|
|
||||
|
var columnDefinitions = new ColumnDefinitions() |
||||
|
{ |
||||
|
new ColumnDefinition(1, GridUnitType.Star) { MinWidth = 10, MaxWidth = 190 }, |
||||
|
new ColumnDefinition(GridLength.Auto), |
||||
|
new ColumnDefinition(1, GridUnitType.Star) { MinWidth = 80, MaxWidth = 120 }, |
||||
|
}; |
||||
|
|
||||
|
var grid = new Grid() |
||||
|
{ |
||||
|
ColumnDefinitions = columnDefinitions, |
||||
|
Children = new Controls() |
||||
|
{ |
||||
|
control1, splitter, control2 |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
var root = new TestRoot { Child = grid }; |
||||
|
|
||||
|
root.Measure(new Size(200, 100)); |
||||
|
root.Arrange(new Rect(0, 0, 200, 100)); |
||||
|
|
||||
|
splitter.RaiseEvent(new VectorEventArgs |
||||
|
{ |
||||
|
RoutedEvent = Thumb.DragDeltaEvent, |
||||
|
Vector = new Vector(-100, 0) |
||||
|
}); |
||||
|
Assert.Equal(columnDefinitions[0].Width, new GridLength(80, GridUnitType.Star)); |
||||
|
Assert.Equal(columnDefinitions[2].Width, new GridLength(120, GridUnitType.Star)); |
||||
|
splitter.RaiseEvent(new VectorEventArgs |
||||
|
{ |
||||
|
RoutedEvent = Thumb.DragDeltaEvent, |
||||
|
Vector = new Vector(100, 0) |
||||
|
}); |
||||
|
Assert.Equal(columnDefinitions[0].Width, new GridLength(120, GridUnitType.Star)); |
||||
|
Assert.Equal(columnDefinitions[2].Width, new GridLength(80, GridUnitType.Star)); |
||||
|
} |
||||
} |
} |
||||
} |
} |
||||
Loading…
Reference in new issue