ScrollSliderTests.cs 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. using UnitTests;
  2. using Xunit.Abstractions;
  3. namespace UnitTests_Parallelizable.ViewsTests;
  4. public class ScrollSliderTests (ITestOutputHelper output) : FakeDriverBase
  5. {
  6. [Fact]
  7. public void Constructor_Initializes_Correctly ()
  8. {
  9. var scrollSlider = new ScrollSlider ();
  10. Assert.False (scrollSlider.CanFocus);
  11. Assert.Equal (Orientation.Vertical, scrollSlider.Orientation);
  12. Assert.Equal (TextDirection.TopBottom_LeftRight, scrollSlider.TextDirection);
  13. Assert.Equal (Alignment.Center, scrollSlider.TextAlignment);
  14. Assert.Equal (Alignment.Center, scrollSlider.VerticalTextAlignment);
  15. scrollSlider.Layout ();
  16. Assert.Equal (0, scrollSlider.Frame.X);
  17. Assert.Equal (0, scrollSlider.Frame.Y);
  18. Assert.Equal (1, scrollSlider.Size);
  19. Assert.Equal (2048, scrollSlider.VisibleContentSize);
  20. }
  21. [Fact]
  22. public void Add_To_SuperView_Initializes_Correctly ()
  23. {
  24. var super = new View
  25. {
  26. Id = "super",
  27. Width = 10,
  28. Height = 10,
  29. CanFocus = true
  30. };
  31. var scrollSlider = new ScrollSlider ();
  32. super.Add (scrollSlider);
  33. Assert.False (scrollSlider.CanFocus);
  34. Assert.Equal (Orientation.Vertical, scrollSlider.Orientation);
  35. Assert.Equal (TextDirection.TopBottom_LeftRight, scrollSlider.TextDirection);
  36. Assert.Equal (Alignment.Center, scrollSlider.TextAlignment);
  37. Assert.Equal (Alignment.Center, scrollSlider.VerticalTextAlignment);
  38. scrollSlider.Layout ();
  39. Assert.Equal (0, scrollSlider.Frame.X);
  40. Assert.Equal (0, scrollSlider.Frame.Y);
  41. Assert.Equal (1, scrollSlider.Size);
  42. Assert.Equal (10, scrollSlider.VisibleContentSize);
  43. }
  44. //[Fact]
  45. //public void OnOrientationChanged_Sets_Size_To_1 ()
  46. //{
  47. // var scrollSlider = new ScrollSlider ();
  48. // scrollSlider.Orientation = Orientation.Horizontal;
  49. // Assert.Equal (1, scrollSlider.Size);
  50. //}
  51. [Fact]
  52. public void OnOrientationChanged_Sets_Position_To_0 ()
  53. {
  54. var super = new View
  55. {
  56. Id = "super",
  57. Width = 10,
  58. Height = 10
  59. };
  60. var scrollSlider = new ScrollSlider ();
  61. super.Add (scrollSlider);
  62. scrollSlider.Layout ();
  63. scrollSlider.Position = 1;
  64. scrollSlider.Orientation = Orientation.Horizontal;
  65. Assert.Equal (0, scrollSlider.Position);
  66. }
  67. [Fact]
  68. public void OnOrientationChanged_Updates_TextDirection_And_TextAlignment ()
  69. {
  70. var scrollSlider = new ScrollSlider ();
  71. scrollSlider.Orientation = Orientation.Horizontal;
  72. Assert.Equal (TextDirection.LeftRight_TopBottom, scrollSlider.TextDirection);
  73. Assert.Equal (Alignment.Center, scrollSlider.TextAlignment);
  74. Assert.Equal (Alignment.Center, scrollSlider.VerticalTextAlignment);
  75. }
  76. [Theory]
  77. [CombinatorialData]
  78. public void Size_Clamps_To_SuperView_Viewport ([CombinatorialRange (-1, 6, 1)] int sliderSize, Orientation orientation)
  79. {
  80. var super = new View
  81. {
  82. Id = "super",
  83. Width = 5,
  84. Height = 5
  85. };
  86. var scrollSlider = new ScrollSlider
  87. {
  88. Orientation = orientation
  89. };
  90. super.Add (scrollSlider);
  91. scrollSlider.Layout ();
  92. scrollSlider.Size = sliderSize;
  93. scrollSlider.Layout ();
  94. Assert.True (scrollSlider.Size > 0);
  95. Assert.True (scrollSlider.Size <= 5);
  96. }
  97. [Theory]
  98. [CombinatorialData]
  99. public void Size_Clamps_To_VisibleContentSizes (
  100. [CombinatorialRange (1, 6, 1)] int dimension,
  101. [CombinatorialRange (-1, 6, 1)] int sliderSize,
  102. Orientation orientation
  103. )
  104. {
  105. var scrollSlider = new ScrollSlider
  106. {
  107. Orientation = orientation,
  108. VisibleContentSize = dimension,
  109. Size = sliderSize
  110. };
  111. scrollSlider.Layout ();
  112. Assert.True (scrollSlider.Size > 0);
  113. Assert.True (scrollSlider.Size <= dimension);
  114. }
  115. [Theory]
  116. [CombinatorialData]
  117. public void CalculateSize_ScrollBounds_0_Returns_1 (
  118. [CombinatorialRange (-1, 5, 1)] int visibleContentSize,
  119. [CombinatorialRange (-1, 5, 1)] int scrollableContentSize
  120. )
  121. {
  122. // Arrange
  123. // Act
  124. int sliderSize = ScrollSlider.CalculateSize (scrollableContentSize, visibleContentSize, 0);
  125. // Assert
  126. Assert.Equal (1, sliderSize);
  127. }
  128. [Theory]
  129. [CombinatorialData]
  130. public void CalculateSize_ScrollableContentSize_0_Returns_1 (
  131. [CombinatorialRange (-1, 5, 1)] int visibleContentSize,
  132. [CombinatorialRange (-1, 5, 1)] int sliderBounds
  133. )
  134. {
  135. // Arrange
  136. // Act
  137. int sliderSize = ScrollSlider.CalculateSize (0, visibleContentSize, sliderBounds);
  138. // Assert
  139. Assert.Equal (1, sliderSize);
  140. }
  141. //[Theory]
  142. //[CombinatorialData]
  143. //public void CalculateSize_VisibleContentSize_0_Returns_0 ([CombinatorialRange (-1, 5, 1)] int scrollableContentSize, [CombinatorialRange (-1, 5, 1)] int sliderBounds)
  144. //{
  145. // // Arrange
  146. // // Act
  147. // var sliderSize = ScrollSlider.CalculateSize (scrollableContentSize, 0, sliderBounds);
  148. // // Assert
  149. // Assert.Equal (0, sliderSize);
  150. //}
  151. [Theory]
  152. [InlineData (0, 1, 1, 1)]
  153. [InlineData (1, 1, 1, 1)]
  154. [InlineData (1, 2, 1, 1)]
  155. [InlineData (0, 5, 5, 5)]
  156. [InlineData (1, 5, 5, 1)]
  157. [InlineData (2, 5, 5, 2)]
  158. [InlineData (3, 5, 5, 3)]
  159. [InlineData (4, 5, 5, 4)]
  160. [InlineData (5, 5, 5, 5)]
  161. [InlineData (6, 5, 5, 5)]
  162. public void CalculateSize_Calculates_Correctly (int visibleContentSize, int scrollableContentSize, int scrollBounds, int expectedSliderSize)
  163. {
  164. // Arrange
  165. // Act
  166. int sliderSize = ScrollSlider.CalculateSize (scrollableContentSize, visibleContentSize, scrollBounds);
  167. // Assert
  168. Assert.Equal (expectedSliderSize, sliderSize);
  169. }
  170. [Fact]
  171. public void VisibleContentSize_Not_Set_Uses_SuperView ()
  172. {
  173. View super = new ()
  174. {
  175. Id = "super",
  176. Height = 5,
  177. Width = 5
  178. };
  179. var scrollSlider = new ScrollSlider ();
  180. super.Add (scrollSlider);
  181. super.Layout ();
  182. Assert.Equal (5, scrollSlider.VisibleContentSize);
  183. }
  184. [Fact]
  185. public void VisibleContentSize_Set_Overrides_SuperView ()
  186. {
  187. View super = new ()
  188. {
  189. Id = "super",
  190. Height = 5,
  191. Width = 5
  192. };
  193. var scrollSlider = new ScrollSlider
  194. {
  195. VisibleContentSize = 10
  196. };
  197. super.Add (scrollSlider);
  198. super.Layout ();
  199. Assert.Equal (10, scrollSlider.VisibleContentSize);
  200. super.Height = 3;
  201. super.Layout ();
  202. Assert.Equal (10, scrollSlider.VisibleContentSize);
  203. super.Height = 7;
  204. super.Layout ();
  205. Assert.Equal (10, scrollSlider.VisibleContentSize);
  206. }
  207. [Theory]
  208. [CombinatorialData]
  209. public void VisibleContentSizes_Clamps_0_To_Dimension ([CombinatorialRange (0, 10, 1)] int dimension, Orientation orientation)
  210. {
  211. var scrollSlider = new ScrollSlider
  212. {
  213. Orientation = orientation,
  214. VisibleContentSize = dimension
  215. };
  216. Assert.InRange (scrollSlider.VisibleContentSize, 1, 10);
  217. View super = new ()
  218. {
  219. Id = "super",
  220. Height = dimension,
  221. Width = dimension
  222. };
  223. scrollSlider = new()
  224. {
  225. Orientation = orientation
  226. };
  227. super.Add (scrollSlider);
  228. super.Layout ();
  229. Assert.InRange (scrollSlider.VisibleContentSize, 1, 10);
  230. scrollSlider.VisibleContentSize = dimension;
  231. Assert.InRange (scrollSlider.VisibleContentSize, 1, 10);
  232. }
  233. [Theory]
  234. //// 0123456789
  235. //// ---------
  236. //// ◄█►
  237. //[InlineData (3, 3, 0, 1, 0)]
  238. //[InlineData (3, 3, 1, 1, 0)]
  239. //[InlineData (3, 3, 2, 1, 0)]
  240. //// 0123456789
  241. //// ---------
  242. //// ◄██►
  243. //[InlineData (4, 4, 0, 2, 0)]
  244. //[InlineData (4, 4, 1, 2, 0)]
  245. //[InlineData (4, 4, 2, 2, 0)]
  246. //[InlineData (4, 4, 3, 2, 0)]
  247. //[InlineData (4, 4, 4, 2, 0)]
  248. // 012345
  249. // ^----
  250. // █░
  251. [InlineData (2, 5, 0, 0)]
  252. // -^---
  253. // █░
  254. [InlineData (2, 5, 1, 0)]
  255. // --^--
  256. // ░█
  257. [InlineData (2, 5, 2, 1)]
  258. // ---^-
  259. // ░█
  260. [InlineData (2, 5, 3, 1)]
  261. // ----^
  262. // ░█
  263. [InlineData (2, 5, 4, 1)]
  264. // 012345
  265. // ^----
  266. // █░░
  267. [InlineData (3, 5, 0, 0)]
  268. // -^---
  269. // ░█░
  270. [InlineData (3, 5, 1, 1)]
  271. // --^--
  272. // ░░█
  273. [InlineData (3, 5, 2, 2)]
  274. // ---^-
  275. // ░░█
  276. [InlineData (3, 5, 3, 2)]
  277. // ----^
  278. // ░░█
  279. [InlineData (3, 5, 4, 2)]
  280. // 0123456789
  281. // ^-----
  282. // █░░
  283. [InlineData (3, 6, 0, 0)]
  284. // -^----
  285. // █░░
  286. [InlineData (3, 6, 1, 1)]
  287. // --^---
  288. // ░█░
  289. [InlineData (3, 6, 2, 1)]
  290. // ---^--
  291. // ░░█
  292. [InlineData (3, 6, 3, 2)]
  293. // ----^-
  294. // ░░█
  295. [InlineData (3, 6, 4, 2)]
  296. // -----^
  297. // ░░█
  298. [InlineData (3, 6, 5, 2)]
  299. // 012345
  300. // ^----
  301. // ███░
  302. [InlineData (4, 5, 0, 0)]
  303. // -^---
  304. // ░███
  305. [InlineData (4, 5, 1, 1)]
  306. // --^--
  307. // ░███
  308. [InlineData (4, 5, 2, 1)]
  309. // ---^-
  310. // ░███
  311. [InlineData (4, 5, 3, 1)]
  312. // ----^
  313. // ░███
  314. [InlineData (4, 5, 4, 1)]
  315. //// 01234
  316. //// ^---------
  317. //// ◄█░░►
  318. //[InlineData (5, 10, 0, 1, 0)]
  319. //// -^--------
  320. //// ◄█░░►
  321. //[InlineData (5, 10, 1, 1, 0)]
  322. //// --^-------
  323. //// ◄█░░►
  324. //[InlineData (5, 10, 2, 1, 0)]
  325. //// ---^------
  326. //// ◄█░░►
  327. //[InlineData (5, 10, 3, 1, 0)]
  328. //// ----^----
  329. //// ◄░█░►
  330. //[InlineData (5, 10, 4, 1, 1)]
  331. //// -----^---
  332. //// ◄░█░►
  333. //[InlineData (5, 10, 5, 1, 1)]
  334. //// ------^--
  335. //// ◄░░█►
  336. //[InlineData (5, 10, 6, 1, 2)]
  337. //// ------^--
  338. //// ◄░░█►
  339. //[InlineData (5, 10, 7, 1, 2)]
  340. //// -------^-
  341. //// ◄░░█►
  342. //[InlineData (5, 10, 8, 1, 2)]
  343. //// --------^
  344. //// ◄░░█►
  345. //[InlineData (5, 10, 9, 1, 2)]
  346. // 0123456789
  347. // ████░░░░
  348. // ^-----------------
  349. // 012345678901234567890123456789
  350. // ░████░░░
  351. // ----^-------------
  352. // 012345678901234567890123456789
  353. // ░░████░░
  354. // --------^---------
  355. // 012345678901234567890123456789
  356. // ░░░████░
  357. // ------------^-----
  358. // 012345678901234567890123456789
  359. // ░░░░████
  360. // ----------------^--
  361. // 0123456789
  362. // ███░░░░░
  363. // ^-----------------
  364. // 012345678901234567890123456789
  365. // ░░███░░░
  366. // --------^---------
  367. // 012345678901234567890123456789
  368. // ░░░███░░
  369. // ------------^-----
  370. // 012345678901234567890123456789
  371. // ░░░░███░
  372. // ----------------^--
  373. // 012345678901234567890123456789
  374. // ░░░░░███
  375. // ----------------^--
  376. [InlineData (8, 18, 0, 0)]
  377. [InlineData (8, 18, 1, 0)]
  378. // 012345678901234567890123456789
  379. // ░███░░░░
  380. // --^---------------
  381. [InlineData (8, 18, 2, 1)]
  382. [InlineData (8, 18, 3, 2)]
  383. [InlineData (8, 18, 4, 2)]
  384. [InlineData (8, 18, 5, 2)]
  385. [InlineData (8, 18, 6, 3)]
  386. [InlineData (8, 18, 7, 4)]
  387. [InlineData (8, 18, 8, 4)]
  388. [InlineData (8, 18, 9, 4)]
  389. // 012345678901234567890123456789
  390. // ░░░░░███
  391. // ----------^--------
  392. [InlineData (8, 18, 10, 5)]
  393. [InlineData (8, 18, 11, 5)]
  394. [InlineData (8, 18, 12, 5)]
  395. [InlineData (8, 18, 13, 5)]
  396. [InlineData (8, 18, 14, 5)]
  397. [InlineData (8, 18, 15, 5)]
  398. [InlineData (8, 18, 16, 5)]
  399. [InlineData (8, 18, 17, 5)]
  400. [InlineData (8, 18, 18, 5)]
  401. [InlineData (8, 18, 19, 5)]
  402. [InlineData (8, 18, 20, 5)]
  403. [InlineData (8, 18, 21, 5)]
  404. [InlineData (8, 18, 22, 5)]
  405. [InlineData (8, 18, 23, 5)]
  406. // ------------------ ^
  407. [InlineData (8, 18, 24, 5)]
  408. [InlineData (8, 18, 25, 5)]
  409. //// 0123456789
  410. //// ◄████░░░░►
  411. //// ^-----------------
  412. //[InlineData (10, 20, 0, 5, 0)]
  413. //[InlineData (10, 20, 1, 5, 0)]
  414. //[InlineData (10, 20, 2, 5, 0)]
  415. //[InlineData (10, 20, 3, 5, 0)]
  416. //[InlineData (10, 20, 4, 5, 1)]
  417. //[InlineData (10, 20, 5, 5, 1)]
  418. //[InlineData (10, 20, 6, 5, 1)]
  419. //[InlineData (10, 20, 7, 5, 2)]
  420. //[InlineData (10, 20, 8, 5, 2)]
  421. //[InlineData (10, 20, 9, 5, 2)]
  422. //[InlineData (10, 20, 10, 5, 3)]
  423. //[InlineData (10, 20, 11, 5, 3)]
  424. //[InlineData (10, 20, 12, 5, 3)]
  425. //[InlineData (10, 20, 13, 5, 3)]
  426. //[InlineData (10, 20, 14, 5, 4)]
  427. //[InlineData (10, 20, 15, 5, 4)]
  428. //[InlineData (10, 20, 16, 5, 4)]
  429. //[InlineData (10, 20, 17, 5, 5)]
  430. //[InlineData (10, 20, 18, 5, 5)]
  431. //[InlineData (10, 20, 19, 5, 5)]
  432. //[InlineData (10, 20, 20, 5, 6)]
  433. //[InlineData (10, 20, 21, 5, 6)]
  434. //[InlineData (10, 20, 22, 5, 6)]
  435. //[InlineData (10, 20, 23, 5, 6)]
  436. //[InlineData (10, 20, 24, 5, 6)]
  437. //[InlineData (10, 20, 25, 5, 6)]
  438. public void CalculatePosition_Calculates_Correctly (int visibleContentSize, int scrollableContentSize, int contentPosition, int expectedSliderPosition)
  439. {
  440. // Arrange
  441. // Act
  442. int sliderPosition = ScrollSlider.CalculatePosition (
  443. scrollableContentSize,
  444. visibleContentSize,
  445. contentPosition,
  446. visibleContentSize,
  447. NavigationDirection.Forward);
  448. // Assert
  449. Assert.Equal (expectedSliderPosition, sliderPosition);
  450. }
  451. [Theory]
  452. [InlineData (8, 18, 0, 0)]
  453. public void CalculateContentPosition_Calculates_Correctly (
  454. int visibleContentSize,
  455. int scrollableContentSize,
  456. int sliderPosition,
  457. int expectedContentPosition
  458. )
  459. {
  460. // Arrange
  461. // Act
  462. int contentPosition = ScrollSlider.CalculateContentPosition (
  463. scrollableContentSize,
  464. visibleContentSize,
  465. sliderPosition,
  466. visibleContentSize);
  467. // Assert
  468. Assert.Equal (expectedContentPosition, contentPosition);
  469. }
  470. [Theory]
  471. [CombinatorialData]
  472. public void ClampPosition_WithSuperView_Clamps_To_ViewPort_Minus_Size_If_VisibleContentSize_Not_Set (
  473. [CombinatorialRange (10, 10, 1)] int dimension,
  474. [CombinatorialRange (1, 5, 1)] int sliderSize,
  475. [CombinatorialRange (-1, 10, 2)] int sliderPosition,
  476. Orientation orientation
  477. )
  478. {
  479. View super = new ()
  480. {
  481. Id = "super",
  482. Height = dimension,
  483. Width = dimension
  484. };
  485. var scrollSlider = new ScrollSlider
  486. {
  487. Orientation = orientation,
  488. Size = sliderSize
  489. };
  490. super.Add (scrollSlider);
  491. super.Layout ();
  492. Assert.Equal (dimension, scrollSlider.VisibleContentSize);
  493. int clampedPosition = scrollSlider.ClampPosition (sliderPosition);
  494. Assert.InRange (clampedPosition, 0, dimension - sliderSize);
  495. }
  496. [Theory]
  497. [CombinatorialData]
  498. public void ClampPosition_WithSuperView_Clamps_To_VisibleContentSize_Minus_Size (
  499. [CombinatorialRange (10, 10, 1)] int dimension,
  500. [CombinatorialRange (1, 5, 1)] int sliderSize,
  501. [CombinatorialRange (-1, 10, 2)] int sliderPosition,
  502. Orientation orientation
  503. )
  504. {
  505. View super = new ()
  506. {
  507. Id = "super",
  508. Height = dimension + 2,
  509. Width = dimension + 2
  510. };
  511. var scrollSlider = new ScrollSlider
  512. {
  513. Orientation = orientation,
  514. VisibleContentSize = dimension,
  515. Size = sliderSize
  516. };
  517. super.Add (scrollSlider);
  518. super.Layout ();
  519. int clampedPosition = scrollSlider.ClampPosition (sliderPosition);
  520. Assert.InRange (clampedPosition, 0, dimension - sliderSize);
  521. }
  522. [Theory]
  523. [CombinatorialData]
  524. public void ClampPosition_NoSuperView_Clamps_To_VisibleContentSize_Minus_Size (
  525. [CombinatorialRange (10, 10, 1)] int dimension,
  526. [CombinatorialRange (1, 5, 1)] int sliderSize,
  527. [CombinatorialRange (-1, 10, 2)] int sliderPosition,
  528. Orientation orientation
  529. )
  530. {
  531. var scrollSlider = new ScrollSlider
  532. {
  533. Orientation = orientation,
  534. VisibleContentSize = dimension,
  535. Size = sliderSize
  536. };
  537. int clampedPosition = scrollSlider.ClampPosition (sliderPosition);
  538. Assert.InRange (clampedPosition, 0, dimension - sliderSize);
  539. }
  540. [Theory]
  541. [CombinatorialData]
  542. public void Position_Clamps_To_VisibleContentSize (
  543. [CombinatorialRange (0, 5, 1)] int dimension,
  544. [CombinatorialRange (1, 5, 1)] int sliderSize,
  545. [CombinatorialRange (-1, 10, 2)] int sliderPosition,
  546. Orientation orientation
  547. )
  548. {
  549. var scrollSlider = new ScrollSlider
  550. {
  551. Orientation = orientation,
  552. VisibleContentSize = dimension,
  553. Size = sliderSize,
  554. Position = sliderPosition
  555. };
  556. Assert.True (scrollSlider.Position <= 5);
  557. }
  558. [Theory]
  559. [CombinatorialData]
  560. public void Position_Clamps_To_SuperView_Viewport (
  561. [CombinatorialRange (0, 5, 1)] int sliderSize,
  562. [CombinatorialRange (-2, 10, 2)] int sliderPosition,
  563. Orientation orientation
  564. )
  565. {
  566. var super = new View
  567. {
  568. Id = "super",
  569. Width = 5,
  570. Height = 5
  571. };
  572. var scrollSlider = new ScrollSlider
  573. {
  574. Orientation = orientation
  575. };
  576. super.Add (scrollSlider);
  577. scrollSlider.Size = sliderSize;
  578. scrollSlider.Layout ();
  579. scrollSlider.Position = sliderPosition;
  580. Assert.True (scrollSlider.Position <= 5);
  581. }
  582. [Theory]
  583. [SetupFakeApplication]
  584. [InlineData (
  585. 3,
  586. 10,
  587. 1,
  588. 0,
  589. Orientation.Vertical,
  590. @"
  591. ┌───┐
  592. │███│
  593. │ │
  594. │ │
  595. │ │
  596. │ │
  597. │ │
  598. │ │
  599. │ │
  600. │ │
  601. │ │
  602. └───┘")]
  603. [InlineData (
  604. 10,
  605. 1,
  606. 3,
  607. 0,
  608. Orientation.Horizontal,
  609. @"
  610. ┌──────────┐
  611. │███ │
  612. └──────────┘")]
  613. [InlineData (
  614. 3,
  615. 10,
  616. 3,
  617. 0,
  618. Orientation.Vertical,
  619. @"
  620. ┌───┐
  621. │███│
  622. │███│
  623. │███│
  624. │ │
  625. │ │
  626. │ │
  627. │ │
  628. │ │
  629. │ │
  630. │ │
  631. └───┘")]
  632. [InlineData (
  633. 3,
  634. 10,
  635. 5,
  636. 0,
  637. Orientation.Vertical,
  638. @"
  639. ┌───┐
  640. │███│
  641. │███│
  642. │███│
  643. │███│
  644. │███│
  645. │ │
  646. │ │
  647. │ │
  648. │ │
  649. │ │
  650. └───┘")]
  651. [InlineData (
  652. 3,
  653. 10,
  654. 5,
  655. 1,
  656. Orientation.Vertical,
  657. @"
  658. ┌───┐
  659. │ │
  660. │███│
  661. │███│
  662. │███│
  663. │███│
  664. │███│
  665. │ │
  666. │ │
  667. │ │
  668. │ │
  669. └───┘")]
  670. [InlineData (
  671. 3,
  672. 10,
  673. 5,
  674. 4,
  675. Orientation.Vertical,
  676. @"
  677. ┌───┐
  678. │ │
  679. │ │
  680. │ │
  681. │ │
  682. │███│
  683. │███│
  684. │███│
  685. │███│
  686. │███│
  687. │ │
  688. └───┘")]
  689. [InlineData (
  690. 3,
  691. 10,
  692. 5,
  693. 5,
  694. Orientation.Vertical,
  695. @"
  696. ┌───┐
  697. │ │
  698. │ │
  699. │ │
  700. │ │
  701. │ │
  702. │███│
  703. │███│
  704. │███│
  705. │███│
  706. │███│
  707. └───┘")]
  708. [InlineData (
  709. 3,
  710. 10,
  711. 5,
  712. 6,
  713. Orientation.Vertical,
  714. @"
  715. ┌───┐
  716. │ │
  717. │ │
  718. │ │
  719. │ │
  720. │ │
  721. │███│
  722. │███│
  723. │███│
  724. │███│
  725. │███│
  726. └───┘")]
  727. [InlineData (
  728. 3,
  729. 10,
  730. 10,
  731. 0,
  732. Orientation.Vertical,
  733. @"
  734. ┌───┐
  735. │███│
  736. │███│
  737. │███│
  738. │███│
  739. │███│
  740. │███│
  741. │███│
  742. │███│
  743. │███│
  744. │███│
  745. └───┘")]
  746. [InlineData (
  747. 3,
  748. 10,
  749. 10,
  750. 5,
  751. Orientation.Vertical,
  752. @"
  753. ┌───┐
  754. │███│
  755. │███│
  756. │███│
  757. │███│
  758. │███│
  759. │███│
  760. │███│
  761. │███│
  762. │███│
  763. │███│
  764. └───┘")]
  765. [InlineData (
  766. 3,
  767. 10,
  768. 11,
  769. 0,
  770. Orientation.Vertical,
  771. @"
  772. ┌───┐
  773. │███│
  774. │███│
  775. │███│
  776. │███│
  777. │███│
  778. │███│
  779. │███│
  780. │███│
  781. │███│
  782. │███│
  783. └───┘")]
  784. [InlineData (
  785. 10,
  786. 3,
  787. 5,
  788. 0,
  789. Orientation.Horizontal,
  790. @"
  791. ┌──────────┐
  792. │█████ │
  793. │█████ │
  794. │█████ │
  795. └──────────┘")]
  796. [InlineData (
  797. 10,
  798. 3,
  799. 5,
  800. 1,
  801. Orientation.Horizontal,
  802. @"
  803. ┌──────────┐
  804. │ █████ │
  805. │ █████ │
  806. │ █████ │
  807. └──────────┘")]
  808. [InlineData (
  809. 10,
  810. 3,
  811. 5,
  812. 4,
  813. Orientation.Horizontal,
  814. @"
  815. ┌──────────┐
  816. │ █████ │
  817. │ █████ │
  818. │ █████ │
  819. └──────────┘")]
  820. [InlineData (
  821. 10,
  822. 3,
  823. 5,
  824. 5,
  825. Orientation.Horizontal,
  826. @"
  827. ┌──────────┐
  828. │ █████│
  829. │ █████│
  830. │ █████│
  831. └──────────┘")]
  832. [InlineData (
  833. 10,
  834. 3,
  835. 5,
  836. 6,
  837. Orientation.Horizontal,
  838. @"
  839. ┌──────────┐
  840. │ █████│
  841. │ █████│
  842. │ █████│
  843. └──────────┘")]
  844. [InlineData (
  845. 10,
  846. 3,
  847. 10,
  848. 0,
  849. Orientation.Horizontal,
  850. @"
  851. ┌──────────┐
  852. │██████████│
  853. │██████████│
  854. │██████████│
  855. └──────────┘")]
  856. [InlineData (
  857. 10,
  858. 3,
  859. 10,
  860. 5,
  861. Orientation.Horizontal,
  862. @"
  863. ┌──────────┐
  864. │██████████│
  865. │██████████│
  866. │██████████│
  867. └──────────┘")]
  868. [InlineData (
  869. 10,
  870. 3,
  871. 11,
  872. 0,
  873. Orientation.Horizontal,
  874. @"
  875. ┌──────────┐
  876. │██████████│
  877. │██████████│
  878. │██████████│
  879. └──────────┘")]
  880. public void Draws_Correctly (int superViewportWidth, int superViewportHeight, int sliderSize, int position, Orientation orientation, string expected)
  881. {
  882. IDriver driver = CreateFakeDriver ();
  883. var super = new Window
  884. {
  885. Driver = driver,
  886. Id = "super",
  887. Width = superViewportWidth + 2,
  888. Height = superViewportHeight + 2
  889. };
  890. var scrollSlider = new ScrollSlider
  891. {
  892. Orientation = orientation,
  893. Size = sliderSize,
  894. //Position = position,
  895. };
  896. Assert.Equal (sliderSize, scrollSlider.Size);
  897. super.Add (scrollSlider);
  898. scrollSlider.Position = position;
  899. super.Layout ();
  900. super.Draw ();
  901. _ = DriverAssert.AssertDriverContentsWithFrameAre (expected, output, driver);
  902. }
  903. }