UniformGridTests.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using Avalonia.Controls.Primitives;
  2. using Xunit;
  3. namespace Avalonia.Controls.UnitTests.Primitives
  4. {
  5. public class UniformGridTests
  6. {
  7. [Fact]
  8. public void Grid_Columns_Equals_Rows_For_Auto_Columns_And_Rows()
  9. {
  10. var target = new UniformGrid()
  11. {
  12. Children =
  13. {
  14. new Border { Width = 50, Height = 70 },
  15. new Border { Width = 30, Height = 50 },
  16. new Border { Width = 80, Height = 90 }
  17. }
  18. };
  19. target.Measure(Size.Infinity);
  20. target.Arrange(new Rect(target.DesiredSize));
  21. // 2 * 2 grid
  22. Assert.Equal(new Size(2 * 80, 2 * 90), target.Bounds.Size);
  23. }
  24. [Fact]
  25. public void Grid_Expands_Vertically_For_Columns_With_Auto_Rows()
  26. {
  27. var target = new UniformGrid()
  28. {
  29. Columns = 2,
  30. Children =
  31. {
  32. new Border { Width = 50, Height = 70 },
  33. new Border { Width = 30, Height = 50 },
  34. new Border { Width = 80, Height = 90 },
  35. new Border { Width = 20, Height = 30 },
  36. new Border { Width = 40, Height = 60 }
  37. }
  38. };
  39. target.Measure(Size.Infinity);
  40. target.Arrange(new Rect(target.DesiredSize));
  41. // 2 * 3 grid
  42. Assert.Equal(new Size(2 * 80, 3 * 90), target.Bounds.Size);
  43. }
  44. [Fact]
  45. public void Grid_Extends_For_Columns_And_First_Column_With_Auto_Rows()
  46. {
  47. var target = new UniformGrid()
  48. {
  49. Columns = 3,
  50. FirstColumn = 2,
  51. Children =
  52. {
  53. new Border { Width = 50, Height = 70 },
  54. new Border { Width = 30, Height = 50 },
  55. new Border { Width = 80, Height = 90 },
  56. new Border { Width = 20, Height = 30 },
  57. new Border { Width = 40, Height = 60 }
  58. }
  59. };
  60. target.Measure(Size.Infinity);
  61. target.Arrange(new Rect(target.DesiredSize));
  62. // 3 * 3 grid
  63. Assert.Equal(new Size(3 * 80, 3 * 90), target.Bounds.Size);
  64. }
  65. [Fact]
  66. public void Grid_Expands_Horizontally_For_Rows_With_Auto_Columns()
  67. {
  68. var target = new UniformGrid()
  69. {
  70. Rows = 2,
  71. Children =
  72. {
  73. new Border { Width = 50, Height = 70 },
  74. new Border { Width = 30, Height = 50 },
  75. new Border { Width = 80, Height = 90 },
  76. new Border { Width = 20, Height = 30 },
  77. new Border { Width = 40, Height = 60 }
  78. }
  79. };
  80. target.Measure(Size.Infinity);
  81. target.Arrange(new Rect(target.DesiredSize));
  82. // 3 * 2 grid
  83. Assert.Equal(new Size(3 * 80, 2 * 90), target.Bounds.Size);
  84. }
  85. [Fact]
  86. public void Grid_Size_Is_Limited_By_Rows_And_Columns()
  87. {
  88. var target = new UniformGrid()
  89. {
  90. Columns = 2,
  91. Rows = 2,
  92. Children =
  93. {
  94. new Border { Width = 50, Height = 70 },
  95. new Border { Width = 30, Height = 50 },
  96. new Border { Width = 80, Height = 90 },
  97. new Border { Width = 20, Height = 30 },
  98. new Border { Width = 40, Height = 60 }
  99. }
  100. };
  101. target.Measure(Size.Infinity);
  102. target.Arrange(new Rect(target.DesiredSize));
  103. // 2 * 2 grid
  104. Assert.Equal(new Size(2 * 80, 2 * 90), target.Bounds.Size);
  105. }
  106. [Fact]
  107. public void Not_Visible_Children_Are_Ignored()
  108. {
  109. var target = new UniformGrid()
  110. {
  111. Children =
  112. {
  113. new Border { Width = 50, Height = 70 },
  114. new Border { Width = 30, Height = 50 },
  115. new Border { Width = 80, Height = 90, IsVisible = false },
  116. new Border { Width = 20, Height = 30 },
  117. new Border { Width = 40, Height = 60 }
  118. }
  119. };
  120. target.Measure(Size.Infinity);
  121. target.Arrange(new Rect(target.DesiredSize));
  122. // 2 * 2 grid
  123. Assert.Equal(new Size(2 * 50, 2 * 70), target.Bounds.Size);
  124. }
  125. }
  126. }