LayoutBuilderElementsTests.cs 3.1 KB

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