TrackTests.cs 4.4 KB

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