VirtualizingStackPanelTests.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. ////using System;
  2. ////using System.Collections.Generic;
  3. ////using Avalonia.Controls.Primitives;
  4. ////using Avalonia.Input;
  5. ////using Avalonia.LogicalTree;
  6. ////using Moq;
  7. ////using Xunit;
  8. ////namespace Avalonia.Controls.UnitTests
  9. ////{
  10. //// public class VirtualizingStackPanelTests
  11. //// {
  12. //// public class Vertical
  13. //// {
  14. //// [Fact]
  15. //// public void Measure_Invokes_Controller_UpdateControls()
  16. //// {
  17. //// var target = new VirtualizingStackPanel();
  18. //// var controller = new Mock<IVirtualizingController>();
  19. //// ((IVirtualizingPanel)target).Controller = controller.Object;
  20. //// target.Measure(new Size(100, 100));
  21. //// controller.Verify(x => x.UpdateControls(), Times.Once());
  22. //// }
  23. //// [Fact]
  24. //// public void Measure_Invokes_Controller_UpdateControls_If_AvailableSize_Changes()
  25. //// {
  26. //// var target = new VirtualizingStackPanel();
  27. //// var controller = new Mock<IVirtualizingController>();
  28. //// ((IVirtualizingPanel)target).Controller = controller.Object;
  29. //// target.Measure(new Size(100, 100));
  30. //// target.InvalidateMeasure();
  31. //// target.Measure(new Size(100, 100));
  32. //// target.InvalidateMeasure();
  33. //// target.Measure(new Size(100, 101));
  34. //// controller.Verify(x => x.UpdateControls(), Times.Exactly(2));
  35. //// }
  36. //// [Fact]
  37. //// public void Measure_Does_Not_Invoke_Controller_UpdateControls_If_AvailableSize_Is_The_Same()
  38. //// {
  39. //// var target = new VirtualizingStackPanel();
  40. //// var controller = new Mock<IVirtualizingController>();
  41. //// ((IVirtualizingPanel)target).Controller = controller.Object;
  42. //// target.Measure(new Size(100, 100));
  43. //// target.InvalidateMeasure();
  44. //// target.Measure(new Size(100, 100));
  45. //// controller.Verify(x => x.UpdateControls(), Times.Once());
  46. //// }
  47. //// [Fact]
  48. //// public void Measure_Invokes_Controller_UpdateControls_If_AvailableSize_Is_The_Same_After_ForceInvalidateMeasure()
  49. //// {
  50. //// var target = new VirtualizingStackPanel();
  51. //// var controller = new Mock<IVirtualizingController>();
  52. //// ((IVirtualizingPanel)target).Controller = controller.Object;
  53. //// target.Measure(new Size(100, 100));
  54. //// ((IVirtualizingPanel)target).ForceInvalidateMeasure();
  55. //// target.Measure(new Size(100, 100));
  56. //// controller.Verify(x => x.UpdateControls(), Times.Exactly(2));
  57. //// }
  58. //// [Fact]
  59. //// public void Arrange_Invokes_Controller_UpdateControls()
  60. //// {
  61. //// var target = new VirtualizingStackPanel();
  62. //// var controller = new Mock<IVirtualizingController>();
  63. //// ((IVirtualizingPanel)target).Controller = controller.Object;
  64. //// target.Measure(new Size(100, 100));
  65. //// target.Arrange(new Rect(0, 0, 110, 110));
  66. //// controller.Verify(x => x.UpdateControls(), Times.Exactly(2));
  67. //// }
  68. //// [Fact]
  69. //// public void Reports_IsFull_False_Until_Measure_Height_Is_Reached()
  70. //// {
  71. //// var target = new VirtualizingStackPanel();
  72. //// var vp = (IVirtualizingPanel)target;
  73. //// target.Measure(new Size(100, 100));
  74. //// Assert.Equal(new Size(0, 0), target.DesiredSize);
  75. //// Assert.Equal(new Size(0, 0), target.Bounds.Size);
  76. //// Assert.False(vp.IsFull);
  77. //// Assert.Equal(0, vp.OverflowCount);
  78. //// target.Children.Add(new Canvas { Width = 50, Height = 50 });
  79. //// Assert.False(vp.IsFull);
  80. //// Assert.Equal(0, vp.OverflowCount);
  81. //// target.Children.Add(new Canvas { Width = 50, Height = 50 });
  82. //// Assert.True(vp.IsFull);
  83. //// Assert.Equal(0, vp.OverflowCount);
  84. //// }
  85. //// [Fact]
  86. //// public void Reports_Overflow_After_Arrange()
  87. //// {
  88. //// var target = new VirtualizingStackPanel();
  89. //// var vp = (IVirtualizingPanel)target;
  90. //// target.Measure(new Size(100, 100));
  91. //// target.Arrange(new Rect(target.DesiredSize));
  92. //// Assert.Equal(new Size(0, 0), target.Bounds.Size);
  93. //// target.Children.Add(new Canvas { Width = 50, Height = 50 });
  94. //// target.Children.Add(new Canvas { Width = 50, Height = 50 });
  95. //// target.Children.Add(new Canvas { Width = 50, Height = 50 });
  96. //// target.Children.Add(new Canvas { Width = 50, Height = 50 });
  97. //// Assert.Equal(0, vp.OverflowCount);
  98. //// target.Measure(new Size(100, 100));
  99. //// target.Arrange(new Rect(target.DesiredSize));
  100. //// Assert.Equal(2, vp.OverflowCount);
  101. //// }
  102. //// [Fact]
  103. //// public void Reports_Correct_Overflow_During_Arrange()
  104. //// {
  105. //// var target = new VirtualizingStackPanel();
  106. //// var vp = (IVirtualizingPanel)target;
  107. //// var controller = new Mock<IVirtualizingController>();
  108. //// var called = false;
  109. //// target.Children.Add(new Canvas { Width = 50, Height = 50 });
  110. //// target.Children.Add(new Canvas { Width = 50, Height = 52 });
  111. //// target.Measure(new Size(100, 100));
  112. //// controller.Setup(x => x.UpdateControls()).Callback(() =>
  113. //// {
  114. //// Assert.Equal(2, vp.PixelOverflow);
  115. //// Assert.Equal(0, vp.OverflowCount);
  116. //// called = true;
  117. //// });
  118. //// vp.Controller = controller.Object;
  119. //// target.Arrange(new Rect(target.DesiredSize));
  120. //// Assert.True(called);
  121. //// }
  122. //// [Fact]
  123. //// public void Reports_PixelOverflow_After_Arrange()
  124. //// {
  125. //// var target = new VirtualizingStackPanel();
  126. //// target.Children.Add(new Canvas { Width = 50, Height = 50 });
  127. //// target.Children.Add(new Canvas { Width = 50, Height = 52 });
  128. //// target.Measure(new Size(100, 100));
  129. //// target.Arrange(new Rect(target.DesiredSize));
  130. //// Assert.Equal(2, ((IVirtualizingPanel)target).PixelOverflow);
  131. //// }
  132. //// [Fact]
  133. //// public void Reports_PixelOverflow_After_Arrange_Smaller_Than_Measure()
  134. //// {
  135. //// var target = new VirtualizingStackPanel();
  136. //// target.Children.Add(new Canvas { Width = 50, Height = 50 });
  137. //// target.Children.Add(new Canvas { Width = 50, Height = 52 });
  138. //// target.Measure(new Size(100, 100));
  139. //// target.Arrange(new Rect(0, 0, 50, 50));
  140. //// Assert.Equal(52, ((IVirtualizingPanel)target).PixelOverflow);
  141. //// }
  142. //// [Fact]
  143. //// public void Reports_PixelOverflow_With_PixelOffset()
  144. //// {
  145. //// var target = new VirtualizingStackPanel();
  146. //// var vp = (IVirtualizingPanel)target;
  147. //// target.Children.Add(new Canvas { Width = 50, Height = 50 });
  148. //// target.Children.Add(new Canvas { Width = 50, Height = 52 });
  149. //// vp.PixelOffset = 2;
  150. //// target.Measure(new Size(100, 100));
  151. //// target.Arrange(new Rect(target.DesiredSize));
  152. //// Assert.Equal(2, vp.PixelOverflow);
  153. //// }
  154. //// [Fact]
  155. //// public void PixelOffset_Can_Be_More_Than_Child_Without_Affecting_IsFull()
  156. //// {
  157. //// var target = new VirtualizingStackPanel();
  158. //// var vp = (IVirtualizingPanel)target;
  159. //// target.Children.Add(new Canvas { Width = 50, Height = 50 });
  160. //// target.Children.Add(new Canvas { Width = 50, Height = 52 });
  161. //// vp.PixelOffset = 55;
  162. //// target.Measure(new Size(100, 100));
  163. //// target.Arrange(new Rect(target.DesiredSize));
  164. //// Assert.Equal(55, vp.PixelOffset);
  165. //// Assert.Equal(2, vp.PixelOverflow);
  166. //// Assert.True(vp.IsFull);
  167. //// }
  168. //// [Fact]
  169. //// public void Passes_Navigation_Request_To_ILogicalScrollable_Parent()
  170. //// {
  171. //// var target = new VirtualizingStackPanel();
  172. //// var presenter = new TestPresenter { Child = target };
  173. //// var from = new Canvas();
  174. //// ((INavigableContainer)target).GetControl(NavigationDirection.Next, from, false);
  175. //// Assert.Equal(1, presenter.NavigationRequests.Count);
  176. //// Assert.Equal((NavigationDirection.Next, from), presenter.NavigationRequests[0]);
  177. //// }
  178. //// private class TestPresenter : Decorator, ILogicalScrollable
  179. //// {
  180. //// public bool CanHorizontallyScroll { get; set; }
  181. //// public bool CanVerticallyScroll { get; set; }
  182. //// public bool IsLogicalScrollEnabled => true;
  183. //// public Size ScrollSize { get; }
  184. //// public Size PageScrollSize { get; }
  185. //// public Size Extent { get; }
  186. //// public Vector Offset { get; set; }
  187. //// public Size Viewport { get; }
  188. //// public event EventHandler ScrollInvalidated;
  189. //// public List<(NavigationDirection, Control)> NavigationRequests { get; } = new();
  190. //// public bool BringIntoView(Control target, Rect targetRect)
  191. //// {
  192. //// throw new NotImplementedException();
  193. //// }
  194. //// public Control GetControlInDirection(NavigationDirection direction, Control from)
  195. //// {
  196. //// NavigationRequests.Add((direction, from));
  197. //// return null;
  198. //// }
  199. //// public void RaiseScrollInvalidated(EventArgs e)
  200. //// {
  201. //// throw new NotImplementedException();
  202. //// }
  203. //// }
  204. //// }
  205. //// }
  206. ////}