LayoutBuilderElementsTests.cs 3.2 KB

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