LayoutBuilderElementsTests.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using Avalonia.Controls;
  2. using PixiEditor.Extensions.FlyUI.Elements;
  3. namespace PixiEditor.Extensions.Test;
  4. public class LayoutBuilderElementsTests
  5. {
  6. [Fact]
  7. public void TestThatRowLayoutIsBuildCorrectly()
  8. {
  9. Layout layout = new Layout(
  10. body: new Row(
  11. new Text("Hello"),
  12. new Text("World")));
  13. Control result = layout.BuildNative();
  14. Assert.IsType<Panel>(result);
  15. Panel grid = (Panel)result;
  16. Assert.Single(grid.Children);
  17. Assert.IsType<StackPanel>(grid.Children[0]);
  18. Panel childGrid = (StackPanel)grid.Children[0];
  19. Assert.Equal(Avalonia.Layout.HorizontalAlignment.Stretch, childGrid.HorizontalAlignment);
  20. Assert.Equal(Avalonia.Layout.VerticalAlignment.Stretch, childGrid.VerticalAlignment);
  21. Assert.Equal(2, childGrid.Children.Count);
  22. Assert.IsType<TextBlock>(childGrid.Children[0]);
  23. TextBlock textBlock = (TextBlock)childGrid.Children[0];
  24. Assert.Equal("Hello", textBlock.Text);
  25. Assert.IsType<TextBlock>(childGrid.Children[1]);
  26. TextBlock textBlock2 = (TextBlock)childGrid.Children[1];
  27. Assert.Equal("World", textBlock2.Text);
  28. }
  29. [Fact]
  30. public void TestThatColumnLayoutIsBuildCorrectly()
  31. {
  32. Layout layout = new Layout(
  33. body: new Column(
  34. new Text("Hello"),
  35. new Text("World")));
  36. Control result = layout.BuildNative();
  37. Assert.IsType<Panel>(result);
  38. Panel grid = (Panel)result;
  39. Assert.Single(grid.Children);
  40. Assert.IsType<StackPanel>(grid.Children[0]);
  41. Panel childGrid = (StackPanel)grid.Children[0];
  42. Assert.Equal(Avalonia.Layout.HorizontalAlignment.Stretch, childGrid.HorizontalAlignment);
  43. Assert.Equal(Avalonia.Layout.VerticalAlignment.Stretch, childGrid.VerticalAlignment);
  44. Assert.Equal(2, childGrid.Children.Count);
  45. Assert.IsType<TextBlock>(childGrid.Children[0]);
  46. TextBlock textBlock = (TextBlock)childGrid.Children[0];
  47. Assert.Equal("Hello", textBlock.Text);
  48. Assert.IsType<TextBlock>(childGrid.Children[1]);
  49. TextBlock textBlock2 = (TextBlock)childGrid.Children[1];
  50. Assert.Equal("World", textBlock2.Text);
  51. }
  52. [Fact]
  53. public void TestCenteredTextLayoutIsBuildCorrectly()
  54. {
  55. Layout layout = new Layout(
  56. body: new Center(
  57. child: new Text("Hello")));
  58. object result = layout.BuildNative();
  59. Assert.IsType<Panel>(result);
  60. Panel grid = (Panel)result;
  61. Assert.Single(grid.Children);
  62. Assert.IsType<Panel>(grid.Children[0]);
  63. Panel childGrid = (Panel)grid.Children[0];
  64. Assert.Equal(Avalonia.Layout.HorizontalAlignment.Center, childGrid.HorizontalAlignment);
  65. Assert.Equal(Avalonia.Layout.VerticalAlignment.Center, childGrid.VerticalAlignment);
  66. Assert.Single(childGrid.Children);
  67. Assert.IsType<TextBlock>(childGrid.Children[0]);
  68. TextBlock textBlock = (TextBlock)childGrid.Children[0];
  69. Assert.Equal("Hello", textBlock.Text);
  70. }
  71. }