TrackTests.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using Avalonia.Controls.Primitives;
  2. using Avalonia.Layout;
  3. using Avalonia.LogicalTree;
  4. using Avalonia.UnitTests;
  5. using Xunit;
  6. namespace Avalonia.Controls.UnitTests.Primitives
  7. {
  8. public class TrackTests : ScopedTestBase
  9. {
  10. [Fact]
  11. public void Measure_Should_Return_Thumb_DesiredWidth_In_Vertical_Orientation()
  12. {
  13. var thumb = new Thumb
  14. {
  15. Width = 12,
  16. };
  17. var target = new Track
  18. {
  19. Thumb = thumb,
  20. Orientation = Orientation.Vertical,
  21. };
  22. target.Measure(new Size(100, 100));
  23. Assert.Equal(new Size(12, 0), target.DesiredSize);
  24. }
  25. [Fact]
  26. public void Measure_Should_Return_Thumb_DesiredHeight_In_Horizontal_Orientation()
  27. {
  28. var thumb = new Thumb
  29. {
  30. Height = 12,
  31. };
  32. var target = new Track
  33. {
  34. Thumb = thumb,
  35. Orientation = Orientation.Horizontal,
  36. };
  37. target.Measure(new Size(100, 100));
  38. Assert.Equal(new Size(0, 12), target.DesiredSize);
  39. }
  40. [Fact]
  41. public void Should_Arrange_Thumb_In_Horizontal_Orientation()
  42. {
  43. var thumb = new Thumb
  44. {
  45. Height = 12,
  46. };
  47. var target = new Track
  48. {
  49. Thumb = thumb,
  50. Orientation = Orientation.Horizontal,
  51. Minimum = 100,
  52. Maximum = 200,
  53. Height = 12,
  54. Value = 150,
  55. ViewportSize = 50,
  56. };
  57. target.Measure(new Size(100, 100));
  58. target.Arrange(new Rect(0, 0, 100, 100));
  59. Assert.Equal(new Rect(33, 0, 34, 12), thumb.Bounds);
  60. }
  61. [Fact]
  62. public void Should_Arrange_Thumb_In_Vertical_Orientation()
  63. {
  64. var thumb = new Thumb
  65. {
  66. Width = 12,
  67. };
  68. var target = new Track
  69. {
  70. Thumb = thumb,
  71. Orientation = Orientation.Vertical,
  72. Minimum = 100,
  73. Maximum = 200,
  74. Value = 150,
  75. ViewportSize = 50,
  76. Width = 12,
  77. };
  78. target.Measure(new Size(100, 100));
  79. target.Arrange(new Rect(0, 0, 100, 100));
  80. Assert.Equal(new Rect(0, 33, 12, 34), thumb.Bounds);
  81. }
  82. [Fact]
  83. public void Thumb_Should_Have_Zero_Width_When_Minimum_Equals_Maximum()
  84. {
  85. var thumb = new Thumb
  86. {
  87. Height = 12,
  88. };
  89. var target = new Track
  90. {
  91. Height = 12,
  92. Thumb = thumb,
  93. Orientation = Orientation.Horizontal,
  94. Minimum = 100,
  95. Maximum = 100,
  96. };
  97. target.Measure(new Size(100, 100));
  98. target.Arrange(new Rect(0, 0, 100, 100));
  99. Assert.Equal(new Rect(0, 0, 0, 12), thumb.Bounds);
  100. }
  101. [Fact]
  102. public void Thumb_Should_Be_Logical_Child()
  103. {
  104. var thumb = new Thumb
  105. {
  106. Height = 12,
  107. };
  108. var target = new Track
  109. {
  110. Height = 12,
  111. Thumb = thumb,
  112. Orientation = Orientation.Horizontal,
  113. Minimum = 100,
  114. Maximum = 100,
  115. };
  116. Assert.Same(thumb.Parent, target);
  117. Assert.Equal(new[] { thumb }, ((ILogical)target).LogicalChildren);
  118. }
  119. [Fact]
  120. public void Should_Not_Pass_Invalid_Arrange_Rect()
  121. {
  122. var thumb = new Thumb { Width = 100.873106060606 };
  123. var increaseButton = new Button { Width = 10 };
  124. var decreaseButton = new Button { Width = 10 };
  125. var target = new Track
  126. {
  127. Height = 12,
  128. Thumb = thumb,
  129. IncreaseButton = increaseButton,
  130. DecreaseButton = decreaseButton,
  131. Orientation = Orientation.Horizontal,
  132. Minimum = 0,
  133. Maximum = 287,
  134. Value = 287,
  135. ViewportSize = 241,
  136. };
  137. target.Measure(Size.Infinity);
  138. // #1297 was occuring here.
  139. target.Arrange(new Rect(0, 0, 221, 12));
  140. }
  141. }
  142. }