TextViewScrollingTests.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using UnitTests;
  2. namespace UnitTests_Parallelizable.ViewsTests;
  3. /// <summary>
  4. /// Tests for TextView's modern View-based scrolling infrastructure integration.
  5. /// </summary>
  6. public class TextViewScrollingTests : FakeDriverBase
  7. {
  8. [Fact]
  9. public void TextView_Uses_SetContentSize_For_Scrolling ()
  10. {
  11. IDriver driver = CreateFakeDriver ();
  12. var textView = new TextView
  13. {
  14. Width = 10,
  15. Height = 5,
  16. Text = "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7",
  17. Driver = driver
  18. };
  19. textView.BeginInit ();
  20. textView.EndInit ();
  21. // Content size should reflect the number of lines
  22. Size contentSize = textView.GetContentSize ();
  23. Assert.Equal (7, contentSize.Height); // 7 lines of text
  24. Assert.True (contentSize.Width >= 6); // At least as wide as "Line 1"
  25. }
  26. [Fact]
  27. public void VerticalScrollBar_AutoShow_Enabled_By_Default ()
  28. {
  29. IDriver driver = CreateFakeDriver ();
  30. var textView = new TextView
  31. {
  32. Width = 10,
  33. Height = 3,
  34. Driver = driver
  35. };
  36. textView.BeginInit ();
  37. textView.EndInit ();
  38. // VerticalScrollBar should have AutoShow enabled
  39. Assert.True (textView.VerticalScrollBar.AutoShow);
  40. }
  41. [Fact]
  42. public void HorizontalScrollBar_AutoShow_Tracks_WordWrap ()
  43. {
  44. IDriver driver = CreateFakeDriver ();
  45. var textView = new TextView
  46. {
  47. Width = 10,
  48. Height = 3,
  49. WordWrap = false,
  50. Driver = driver
  51. };
  52. textView.BeginInit ();
  53. textView.EndInit ();
  54. // When WordWrap is false, HorizontalScrollBar AutoShow should be true
  55. Assert.True (textView.HorizontalScrollBar.AutoShow);
  56. // When WordWrap is true, HorizontalScrollBar AutoShow should be false
  57. textView.WordWrap = true;
  58. Assert.False (textView.HorizontalScrollBar.AutoShow);
  59. }
  60. [Fact]
  61. public void TextView_Viewport_Syncs_With_Scrolling ()
  62. {
  63. IDriver driver = CreateFakeDriver ();
  64. var textView = new TextView
  65. {
  66. Width = 20,
  67. Height = 5,
  68. Text = "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7",
  69. Driver = driver
  70. };
  71. textView.BeginInit ();
  72. textView.EndInit ();
  73. // Initially, Viewport.Y should be 0
  74. Assert.Equal (0, textView.Viewport.Y);
  75. Assert.Equal (0, textView.TopRow);
  76. // Scroll down
  77. textView.TopRow = 2;
  78. // Viewport.Y should update to match
  79. Assert.Equal (2, textView.Viewport.Y);
  80. Assert.Equal (2, textView.TopRow);
  81. }
  82. [Fact]
  83. public void TextView_ContentSize_Updates_When_Text_Changes ()
  84. {
  85. IDriver driver = CreateFakeDriver ();
  86. var textView = new TextView
  87. {
  88. Width = 20,
  89. Height = 5,
  90. Text = "Short",
  91. Driver = driver
  92. };
  93. textView.BeginInit ();
  94. textView.EndInit ();
  95. Size initialContentSize = textView.GetContentSize ();
  96. Assert.Equal (1, initialContentSize.Height); // 1 line
  97. // Add more lines
  98. textView.Text = "Line 1\nLine 2\nLine 3\nLine 4\nLine 5";
  99. Size newContentSize = textView.GetContentSize ();
  100. Assert.Equal (5, newContentSize.Height); // 5 lines
  101. }
  102. [Fact]
  103. public void TextView_LeftColumn_Syncs_With_Viewport_X ()
  104. {
  105. IDriver driver = CreateFakeDriver ();
  106. var textView = new TextView
  107. {
  108. Width = 10,
  109. Height = 3,
  110. Text = "This is a very long line that should require horizontal scrolling",
  111. WordWrap = false,
  112. Driver = driver
  113. };
  114. textView.BeginInit ();
  115. textView.EndInit ();
  116. // Initially at column 0
  117. Assert.Equal (0, textView.Viewport.X);
  118. Assert.Equal (0, textView.LeftColumn);
  119. // Scroll horizontally
  120. textView.LeftColumn = 5;
  121. // Viewport.X should update
  122. Assert.Equal (5, textView.Viewport.X);
  123. Assert.Equal (5, textView.LeftColumn);
  124. }
  125. [Fact]
  126. public void TextView_ScrollTo_Updates_Viewport ()
  127. {
  128. IDriver driver = CreateFakeDriver ();
  129. var textView = new TextView
  130. {
  131. Width = 20,
  132. Height = 5,
  133. Text = "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nLine 8\nLine 9\nLine 10",
  134. Driver = driver
  135. };
  136. textView.BeginInit ();
  137. textView.EndInit ();
  138. // Scroll to row 3
  139. textView.ScrollTo (3, isRow: true);
  140. Assert.Equal (3, textView.TopRow);
  141. Assert.Equal (3, textView.Viewport.Y);
  142. }
  143. }