ScrollSliderTests.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. using UnitTests;
  2. using Xunit.Abstractions;
  3. namespace 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. [InlineData (
  584. 3,
  585. 10,
  586. 1,
  587. 0,
  588. Orientation.Vertical,
  589. @"
  590. ┌───┐
  591. │███│
  592. │ │
  593. │ │
  594. │ │
  595. │ │
  596. │ │
  597. │ │
  598. │ │
  599. │ │
  600. │ │
  601. └───┘")]
  602. [InlineData (
  603. 10,
  604. 1,
  605. 3,
  606. 0,
  607. Orientation.Horizontal,
  608. @"
  609. ┌──────────┐
  610. │███ │
  611. └──────────┘")]
  612. [InlineData (
  613. 3,
  614. 10,
  615. 3,
  616. 0,
  617. Orientation.Vertical,
  618. @"
  619. ┌───┐
  620. │███│
  621. │███│
  622. │███│
  623. │ │
  624. │ │
  625. │ │
  626. │ │
  627. │ │
  628. │ │
  629. │ │
  630. └───┘")]
  631. [InlineData (
  632. 3,
  633. 10,
  634. 5,
  635. 0,
  636. Orientation.Vertical,
  637. @"
  638. ┌───┐
  639. │███│
  640. │███│
  641. │███│
  642. │███│
  643. │███│
  644. │ │
  645. │ │
  646. │ │
  647. │ │
  648. │ │
  649. └───┘")]
  650. [InlineData (
  651. 3,
  652. 10,
  653. 5,
  654. 1,
  655. Orientation.Vertical,
  656. @"
  657. ┌───┐
  658. │ │
  659. │███│
  660. │███│
  661. │███│
  662. │███│
  663. │███│
  664. │ │
  665. │ │
  666. │ │
  667. │ │
  668. └───┘")]
  669. [InlineData (
  670. 3,
  671. 10,
  672. 5,
  673. 4,
  674. Orientation.Vertical,
  675. @"
  676. ┌───┐
  677. │ │
  678. │ │
  679. │ │
  680. │ │
  681. │███│
  682. │███│
  683. │███│
  684. │███│
  685. │███│
  686. │ │
  687. └───┘")]
  688. [InlineData (
  689. 3,
  690. 10,
  691. 5,
  692. 5,
  693. Orientation.Vertical,
  694. @"
  695. ┌───┐
  696. │ │
  697. │ │
  698. │ │
  699. │ │
  700. │ │
  701. │███│
  702. │███│
  703. │███│
  704. │███│
  705. │███│
  706. └───┘")]
  707. [InlineData (
  708. 3,
  709. 10,
  710. 5,
  711. 6,
  712. Orientation.Vertical,
  713. @"
  714. ┌───┐
  715. │ │
  716. │ │
  717. │ │
  718. │ │
  719. │ │
  720. │███│
  721. │███│
  722. │███│
  723. │███│
  724. │███│
  725. └───┘")]
  726. [InlineData (
  727. 3,
  728. 10,
  729. 10,
  730. 0,
  731. Orientation.Vertical,
  732. @"
  733. ┌───┐
  734. │███│
  735. │███│
  736. │███│
  737. │███│
  738. │███│
  739. │███│
  740. │███│
  741. │███│
  742. │███│
  743. │███│
  744. └───┘")]
  745. [InlineData (
  746. 3,
  747. 10,
  748. 10,
  749. 5,
  750. Orientation.Vertical,
  751. @"
  752. ┌───┐
  753. │███│
  754. │███│
  755. │███│
  756. │███│
  757. │███│
  758. │███│
  759. │███│
  760. │███│
  761. │███│
  762. │███│
  763. └───┘")]
  764. [InlineData (
  765. 3,
  766. 10,
  767. 11,
  768. 0,
  769. Orientation.Vertical,
  770. @"
  771. ┌───┐
  772. │███│
  773. │███│
  774. │███│
  775. │███│
  776. │███│
  777. │███│
  778. │███│
  779. │███│
  780. │███│
  781. │███│
  782. └───┘")]
  783. [InlineData (
  784. 10,
  785. 3,
  786. 5,
  787. 0,
  788. Orientation.Horizontal,
  789. @"
  790. ┌──────────┐
  791. │█████ │
  792. │█████ │
  793. │█████ │
  794. └──────────┘")]
  795. [InlineData (
  796. 10,
  797. 3,
  798. 5,
  799. 1,
  800. Orientation.Horizontal,
  801. @"
  802. ┌──────────┐
  803. │ █████ │
  804. │ █████ │
  805. │ █████ │
  806. └──────────┘")]
  807. [InlineData (
  808. 10,
  809. 3,
  810. 5,
  811. 4,
  812. Orientation.Horizontal,
  813. @"
  814. ┌──────────┐
  815. │ █████ │
  816. │ █████ │
  817. │ █████ │
  818. └──────────┘")]
  819. [InlineData (
  820. 10,
  821. 3,
  822. 5,
  823. 5,
  824. Orientation.Horizontal,
  825. @"
  826. ┌──────────┐
  827. │ █████│
  828. │ █████│
  829. │ █████│
  830. └──────────┘")]
  831. [InlineData (
  832. 10,
  833. 3,
  834. 5,
  835. 6,
  836. Orientation.Horizontal,
  837. @"
  838. ┌──────────┐
  839. │ █████│
  840. │ █████│
  841. │ █████│
  842. └──────────┘")]
  843. [InlineData (
  844. 10,
  845. 3,
  846. 10,
  847. 0,
  848. Orientation.Horizontal,
  849. @"
  850. ┌──────────┐
  851. │██████████│
  852. │██████████│
  853. │██████████│
  854. └──────────┘")]
  855. [InlineData (
  856. 10,
  857. 3,
  858. 10,
  859. 5,
  860. Orientation.Horizontal,
  861. @"
  862. ┌──────────┐
  863. │██████████│
  864. │██████████│
  865. │██████████│
  866. └──────────┘")]
  867. [InlineData (
  868. 10,
  869. 3,
  870. 11,
  871. 0,
  872. Orientation.Horizontal,
  873. @"
  874. ┌──────────┐
  875. │██████████│
  876. │██████████│
  877. │██████████│
  878. └──────────┘")]
  879. public void Draws_Correctly (int superViewportWidth, int superViewportHeight, int sliderSize, int position, Orientation orientation, string expected)
  880. {
  881. IDriver driver = CreateFakeDriver ();
  882. var super = new Window
  883. {
  884. Driver = driver,
  885. Id = "super",
  886. Width = superViewportWidth + 2,
  887. Height = superViewportHeight + 2
  888. };
  889. var scrollSlider = new ScrollSlider
  890. {
  891. Orientation = orientation,
  892. Size = sliderSize,
  893. //Position = position,
  894. };
  895. Assert.Equal (sliderSize, scrollSlider.Size);
  896. super.Add (scrollSlider);
  897. scrollSlider.Position = position;
  898. super.Layout ();
  899. super.Draw ();
  900. _ = DriverAssert.AssertDriverContentsWithFrameAre (expected, output, driver);
  901. }
  902. }