TabViewTests.cs 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  1. using System.Globalization;
  2. using UnitTests;
  3. using Xunit.Abstractions;
  4. namespace Terminal.Gui.ViewsTests;
  5. public class TabViewTests (ITestOutputHelper output)
  6. {
  7. [Fact]
  8. public void AddTab_SameTabMoreThanOnce ()
  9. {
  10. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  11. Assert.Equal (2, tv.Tabs.Count);
  12. // Tab is already part of the control so shouldn't result in duplication
  13. tv.AddTab (tab1, false);
  14. tv.AddTab (tab1, false);
  15. tv.AddTab (tab1, false);
  16. tv.AddTab (tab1, false);
  17. Assert.Equal (2, tv.Tabs.Count);
  18. }
  19. [Fact]
  20. [SetupFakeDriver]
  21. public void AddTwoTabs_SecondIsSelected ()
  22. {
  23. var tv = new TabView ();
  24. Tab tab1;
  25. Tab tab2;
  26. tv.AddTab (tab1 = new () { DisplayText = "Tab1", View = new TextField { Text = "hi" } }, false);
  27. tv.AddTab (tab2 = new () { DisplayText = "Tab1", View = new Label { Text = "hi2" } }, true);
  28. Assert.Equal (2, tv.Tabs.Count);
  29. Assert.Equal (tab2, tv.SelectedTab);
  30. }
  31. [Fact]
  32. public void EnsureSelectedTabVisible_MustScroll ()
  33. {
  34. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  35. // Make tab width small to force only one tab visible at once
  36. tv.Width = 4;
  37. tv.SelectedTab = tab1;
  38. Assert.Equal (0, tv.TabScrollOffset);
  39. tv.EnsureSelectedTabIsVisible ();
  40. Assert.Equal (0, tv.TabScrollOffset);
  41. // Asking to show tab2 should automatically move scroll offset accordingly
  42. tv.SelectedTab = tab2;
  43. Assert.Equal (1, tv.TabScrollOffset);
  44. }
  45. [Fact]
  46. public void EnsureSelectedTabVisible_NullSelect ()
  47. {
  48. TabView tv = GetTabView ();
  49. tv.SelectedTab = null;
  50. Assert.Null (tv.SelectedTab);
  51. Assert.Equal (0, tv.TabScrollOffset);
  52. tv.EnsureSelectedTabIsVisible ();
  53. Assert.Null (tv.SelectedTab);
  54. Assert.Equal (0, tv.TabScrollOffset);
  55. }
  56. [Fact]
  57. public void EnsureValidScrollOffsets_TabScrollOffset ()
  58. {
  59. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  60. // Make tab width small to force only one tab visible at once
  61. tv.Width = 4;
  62. tv.SelectedTab = tab1;
  63. Assert.Equal (0, tv.TabScrollOffset);
  64. tv.TabScrollOffset = 10;
  65. tv.SelectedTab = tab2;
  66. Assert.Equal (1, tv.TabScrollOffset);
  67. tv.TabScrollOffset = -1;
  68. tv.SelectedTab = tab1;
  69. Assert.Equal (0, tv.TabScrollOffset);
  70. }
  71. [Fact]
  72. [AutoInitShutdown]
  73. public void MouseClick_ChangesTab ()
  74. {
  75. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  76. tv.Width = 20;
  77. tv.Height = 5;
  78. tv.Draw ();
  79. View tabRow = tv.SubViews.ElementAt (0);
  80. Assert.Equal ("TabRow", tabRow.GetType ().Name);
  81. DriverAssert.AssertDriverContentsAre (
  82. @"
  83. ╭────┬────╮
  84. │Tab1│Tab2│
  85. │ ╰────┴────────╮
  86. │hi │
  87. └──────────────────┘
  88. ",
  89. output
  90. );
  91. Tab clicked = null;
  92. tv.TabClicked += (s, e) => { clicked = e.Tab; };
  93. var top = new Toplevel ();
  94. top.Add (tv);
  95. Application.Begin (top);
  96. MouseEventArgs args;
  97. // Waving mouse around does not trigger click
  98. for (var i = 0; i < 100; i++)
  99. {
  100. args = new () { ScreenPosition = new (i, 1), Flags = MouseFlags.ReportMousePosition };
  101. Application.RaiseMouseEvent (args);
  102. Application.LayoutAndDraw ();
  103. Assert.Null (clicked);
  104. Assert.Equal (tab1, tv.SelectedTab);
  105. }
  106. args = new () { ScreenPosition = new (3, 1), Flags = MouseFlags.Button1Clicked };
  107. Application.RaiseMouseEvent (args);
  108. Application.LayoutAndDraw ();
  109. Assert.Equal (tab1, clicked);
  110. Assert.Equal (tab1, tv.SelectedTab);
  111. // Click to tab2
  112. args = new () { ScreenPosition = new (6, 1), Flags = MouseFlags.Button1Clicked };
  113. Application.RaiseMouseEvent (args);
  114. Application.LayoutAndDraw ();
  115. Assert.Equal (tab2, clicked);
  116. Assert.Equal (tab2, tv.SelectedTab);
  117. // cancel navigation
  118. tv.TabClicked += (s, e) =>
  119. {
  120. clicked = e.Tab;
  121. e.MouseEvent.Handled = true;
  122. };
  123. args = new () { ScreenPosition = new (3, 1), Flags = MouseFlags.Button1Clicked };
  124. Application.RaiseMouseEvent (args);
  125. Application.LayoutAndDraw ();
  126. // Tab 1 was clicked but event handler blocked navigation
  127. Assert.Equal (tab1, clicked);
  128. Assert.Equal (tab2, tv.SelectedTab);
  129. args = new () { ScreenPosition = new (12, 1), Flags = MouseFlags.Button1Clicked };
  130. Application.RaiseMouseEvent (args);
  131. Application.LayoutAndDraw ();
  132. // Clicking beyond last tab should raise event with null Tab
  133. Assert.Null (clicked);
  134. Assert.Equal (tab2, tv.SelectedTab);
  135. top.Dispose ();
  136. }
  137. [Fact]
  138. [AutoInitShutdown]
  139. public void MouseClick_Right_Left_Arrows_ChangesTab ()
  140. {
  141. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  142. tv.Width = 7;
  143. tv.Height = 5;
  144. tv.Draw ();
  145. View tabRow = tv.SubViews.ElementAt (0);
  146. Assert.Equal ("TabRow", tabRow.GetType ().Name);
  147. DriverAssert.AssertDriverContentsAre (
  148. @"
  149. ╭────╮
  150. │Tab1│
  151. │ ╰►
  152. │hi │
  153. └─────┘
  154. ",
  155. output
  156. );
  157. Tab clicked = null;
  158. tv.TabClicked += (s, e) => { clicked = e.Tab; };
  159. Tab oldChanged = null;
  160. Tab newChanged = null;
  161. tv.SelectedTabChanged += (s, e) =>
  162. {
  163. oldChanged = e.OldTab;
  164. newChanged = e.NewTab;
  165. };
  166. var top = new Toplevel ();
  167. top.Add (tv);
  168. Application.Begin (top);
  169. // Click the right arrow
  170. var args = new MouseEventArgs { ScreenPosition = new (6, 2), Flags = MouseFlags.Button1Clicked };
  171. Application.RaiseMouseEvent (args);
  172. Application.LayoutAndDraw ();
  173. Assert.Null (clicked);
  174. Assert.Equal (tab1, oldChanged);
  175. Assert.Equal (tab2, newChanged);
  176. Assert.Equal (tab2, tv.SelectedTab);
  177. DriverAssert.AssertDriverContentsAre (
  178. @"
  179. ╭────╮
  180. │Tab2│
  181. ◄ ╰╮
  182. │hi2 │
  183. └─────┘
  184. ",
  185. output
  186. );
  187. // Click the left arrow
  188. args = new () { ScreenPosition = new (0, 2), Flags = MouseFlags.Button1Clicked };
  189. Application.RaiseMouseEvent (args);
  190. Application.LayoutAndDraw ();
  191. Assert.Null (clicked);
  192. Assert.Equal (tab2, oldChanged);
  193. Assert.Equal (tab1, newChanged);
  194. Assert.Equal (tab1, tv.SelectedTab);
  195. DriverAssert.AssertDriverContentsAre (
  196. @"
  197. ╭────╮
  198. │Tab1│
  199. │ ╰►
  200. │hi │
  201. └─────┘
  202. ",
  203. output
  204. );
  205. top.Dispose ();
  206. }
  207. [Fact]
  208. [AutoInitShutdown]
  209. public void MouseClick_Right_Left_Arrows_ChangesTab_With_Border ()
  210. {
  211. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  212. tv.Width = 9;
  213. tv.Height = 7;
  214. Assert.Equal (LineStyle.None, tv.BorderStyle);
  215. tv.BorderStyle = LineStyle.Single;
  216. tv.Layout ();
  217. tv.Draw ();
  218. View tabRow = tv.SubViews.ElementAt (0);
  219. Assert.Equal ("TabRow", tabRow.GetType ().Name);
  220. DriverAssert.AssertDriverContentsAre (
  221. @"
  222. ┌───────┐
  223. │╭────╮ │
  224. ││Tab1│ │
  225. ││ ╰►│
  226. ││hi ││
  227. │└─────┘│
  228. └───────┘
  229. ",
  230. output
  231. );
  232. Tab clicked = null;
  233. tv.TabClicked += (s, e) => { clicked = e.Tab; };
  234. Tab oldChanged = null;
  235. Tab newChanged = null;
  236. tv.SelectedTabChanged += (s, e) =>
  237. {
  238. oldChanged = e.OldTab;
  239. newChanged = e.NewTab;
  240. };
  241. var top = new Toplevel ();
  242. top.Add (tv);
  243. Application.Begin (top);
  244. // Click the right arrow
  245. var args = new MouseEventArgs { ScreenPosition = new (7, 3), Flags = MouseFlags.Button1Clicked };
  246. Application.RaiseMouseEvent (args);
  247. Application.LayoutAndDraw ();
  248. Assert.Null (clicked);
  249. Assert.Equal (tab1, oldChanged);
  250. Assert.Equal (tab2, newChanged);
  251. Assert.Equal (tab2, tv.SelectedTab);
  252. DriverAssert.AssertDriverContentsAre (
  253. @"
  254. ┌───────┐
  255. │╭────╮ │
  256. ││Tab2│ │
  257. │◄ ╰╮│
  258. ││hi2 ││
  259. │└─────┘│
  260. └───────┘
  261. ",
  262. output
  263. );
  264. // Click the left arrow
  265. args = new () { ScreenPosition = new (1, 3), Flags = MouseFlags.Button1Clicked };
  266. Application.RaiseMouseEvent (args);
  267. Application.LayoutAndDraw ();
  268. Assert.Null (clicked);
  269. Assert.Equal (tab2, oldChanged);
  270. Assert.Equal (tab1, newChanged);
  271. Assert.Equal (tab1, tv.SelectedTab);
  272. DriverAssert.AssertDriverContentsAre (
  273. @"
  274. ┌───────┐
  275. │╭────╮ │
  276. ││Tab1│ │
  277. ││ ╰►│
  278. ││hi ││
  279. │└─────┘│
  280. └───────┘
  281. ",
  282. output
  283. );
  284. top.Dispose ();
  285. }
  286. [Fact]
  287. [AutoInitShutdown]
  288. public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp_F6 ()
  289. {
  290. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  291. tv.Width = 7;
  292. tv.Height = 5;
  293. var btn = new Button
  294. {
  295. Id = "btn",
  296. Y = Pos.Bottom (tv) + 1,
  297. Height = 1,
  298. Width = 7,
  299. Text = "Ok"
  300. };
  301. Toplevel top = new ();
  302. top.Add (tv, btn);
  303. Application.Begin (top);
  304. // Is the selected tab view hosting focused
  305. Assert.Equal (tab1, tv.SelectedTab);
  306. Assert.Equal (tv, top.Focused);
  307. Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
  308. Assert.Equal (tv.SelectedTab.View, top.Focused.MostFocused);
  309. // Press the cursor up key to focus the selected tab
  310. Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp));
  311. Application.LayoutAndDraw ();
  312. // Is the selected tab focused
  313. Assert.Equal (tab1, tv.SelectedTab);
  314. Assert.Equal (tv, top.Focused);
  315. Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
  316. Tab oldChanged = null;
  317. Tab newChanged = null;
  318. tv.SelectedTabChanged += (s, e) =>
  319. {
  320. oldChanged = e.OldTab;
  321. newChanged = e.NewTab;
  322. };
  323. // Press the cursor right key to select the next tab
  324. Assert.True (Application.RaiseKeyDownEvent (Key.CursorRight));
  325. Application.LayoutAndDraw ();
  326. Assert.Equal (tab1, oldChanged);
  327. Assert.Equal (tab2, newChanged);
  328. Assert.Equal (tab2, tv.SelectedTab);
  329. Assert.Equal (tv, top.Focused);
  330. Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
  331. // Press the cursor down key. Since the selected tab has no focusable views, the focus should move to the next view in the toplevel
  332. Assert.True (Application.RaiseKeyDownEvent (Key.CursorDown));
  333. Assert.Equal (tab2, tv.SelectedTab);
  334. Assert.Equal (btn, top.MostFocused);
  335. // Add a focusable subview to Selected Tab View which is a Label with CanFocus as false
  336. var btnSubView = new View ()
  337. {
  338. Id = "btnSubView",
  339. Title = "_SubView",
  340. CanFocus = true
  341. };
  342. tv.SelectedTab.View.Add (btnSubView);
  343. Assert.False (tv.SelectedTab.View.CanFocus);
  344. // Press cursor up. Should focus the subview in the selected tab.
  345. Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp));
  346. Assert.Equal (tab2, tv.SelectedTab);
  347. Assert.NotEqual (btnSubView, top.MostFocused);
  348. Assert.Equal (tab2, top.MostFocused);
  349. tv.SelectedTab.View.CanFocus = true;
  350. Assert.True (Application.RaiseKeyDownEvent (Key.CursorDown));
  351. Assert.Equal (tab2, tv.SelectedTab);
  352. Assert.Equal (btnSubView, top.MostFocused);
  353. Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp));
  354. Assert.Equal (tab2, top.MostFocused);
  355. Assert.NotEqual (btn, top.MostFocused);
  356. Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp));
  357. Assert.Equal (btnSubView, top.MostFocused);
  358. Assert.True (Application.RaiseKeyDownEvent (Key.F6));
  359. Assert.Equal (tab2, top.MostFocused);
  360. // Press the cursor down key twice.
  361. Assert.True (Application.RaiseKeyDownEvent (Key.CursorDown));
  362. Assert.True (Application.RaiseKeyDownEvent (Key.CursorDown));
  363. Assert.Equal (btn, top.MostFocused);
  364. // Press the cursor down key again will focus next view in the toplevel, which is the TabView
  365. Assert.True (Application.RaiseKeyDownEvent (Key.CursorDown));
  366. Assert.Equal (tab2, tv.SelectedTab);
  367. Assert.Equal (tv, top.Focused);
  368. // Due to the RestoreFocus method prioritize the _previouslyFocused, so btnSubView will be focused again
  369. Assert.Equal (btnSubView, tv.MostFocused);
  370. // Press the cursor up key to focus the selected tab which it's the only way to do that
  371. Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp));
  372. Assert.Equal (tab2, tv.SelectedTab);
  373. Assert.False (tab2.View.HasFocus);
  374. Assert.Equal (tv, top.Focused);
  375. Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp));
  376. Assert.Equal (tv, top.Focused);
  377. Assert.Equal (btnSubView, top.MostFocused);
  378. Assert.True (Application.RaiseKeyDownEvent (Key.F6));
  379. Assert.Equal (tv, top.Focused);
  380. Assert.Equal (tab2, top.Focused.MostFocused);
  381. Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
  382. // Press the cursor left key to select the previous tab
  383. Assert.True (Application.RaiseKeyDownEvent (Key.CursorLeft));
  384. Application.LayoutAndDraw ();
  385. Assert.Equal (tab2, oldChanged);
  386. Assert.Equal (tab1, newChanged);
  387. Assert.Equal (tab1, tv.SelectedTab);
  388. Assert.Equal (tv, top.Focused);
  389. Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
  390. Assert.Equal (tab1, top.Focused.MostFocused);
  391. // Press the end key to select the last tab
  392. Assert.True (Application.RaiseKeyDownEvent (Key.End));
  393. Application.LayoutAndDraw ();
  394. Assert.Equal (tab1, oldChanged);
  395. Assert.Equal (tab2, newChanged);
  396. Assert.Equal (tab2, tv.SelectedTab);
  397. Assert.Equal (tv, top.Focused);
  398. Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
  399. // Press the home key to select the first tab
  400. Assert.True (Application.RaiseKeyDownEvent (Key.Home));
  401. Application.LayoutAndDraw ();
  402. Assert.Equal (tab2, oldChanged);
  403. Assert.Equal (tab1, newChanged);
  404. Assert.Equal (tab1, tv.SelectedTab);
  405. Assert.Equal (tv, top.Focused);
  406. Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
  407. // Press the page down key to select the next set of tabs
  408. Assert.True (Application.RaiseKeyDownEvent (Key.PageDown));
  409. Application.LayoutAndDraw ();
  410. Assert.Equal (tab1, oldChanged);
  411. Assert.Equal (tab2, newChanged);
  412. Assert.Equal (tab2, tv.SelectedTab);
  413. Assert.Equal (tv, top.Focused);
  414. Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
  415. // Press the page up key to select the previous set of tabs
  416. Assert.True (Application.RaiseKeyDownEvent (Key.PageUp));
  417. Application.LayoutAndDraw ();
  418. Assert.Equal (tab2, oldChanged);
  419. Assert.Equal (tab1, newChanged);
  420. Assert.Equal (tab1, tv.SelectedTab);
  421. Assert.Equal (tv, top.Focused);
  422. Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
  423. top.Dispose ();
  424. }
  425. [Fact]
  426. public void RemoveAllTabs_ClearsSelection ()
  427. {
  428. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  429. tv.SelectedTab = tab1;
  430. tv.RemoveTab (tab1);
  431. tv.RemoveTab (tab2);
  432. Assert.Null (tv.SelectedTab);
  433. }
  434. [Fact]
  435. public void RemoveTab_ChangesSelection ()
  436. {
  437. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  438. tv.SelectedTab = tab1;
  439. tv.RemoveTab (tab1);
  440. Assert.Equal (tab2, tv.SelectedTab);
  441. }
  442. [Fact]
  443. public void RemoveTab_MultipleCalls_NotAnError ()
  444. {
  445. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  446. tv.SelectedTab = tab1;
  447. // Repeated calls to remove a tab that is not part of
  448. // the collection should be ignored
  449. tv.RemoveTab (tab1);
  450. tv.RemoveTab (tab1);
  451. tv.RemoveTab (tab1);
  452. tv.RemoveTab (tab1);
  453. Assert.Equal (tab2, tv.SelectedTab);
  454. }
  455. [Fact]
  456. public void SelectedTabChanged_Called ()
  457. {
  458. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  459. tv.SelectedTab = tab1;
  460. Tab oldTab = null;
  461. Tab newTab = null;
  462. var called = 0;
  463. tv.SelectedTabChanged += (s, e) =>
  464. {
  465. oldTab = e.OldTab;
  466. newTab = e.NewTab;
  467. called++;
  468. };
  469. tv.SelectedTab = tab2;
  470. Assert.Equal (1, called);
  471. Assert.Equal (tab1, oldTab);
  472. Assert.Equal (tab2, newTab);
  473. }
  474. [Fact]
  475. [SetupFakeDriver]
  476. public void ShowTopLine_False_TabsOnBottom_False_TestTabView_Width3 ()
  477. {
  478. TabView tv = GetTabView (out _, out _);
  479. tv.Width = 3;
  480. tv.Height = 5;
  481. tv.Style = new () { ShowTopLine = false };
  482. tv.ApplyStyleChanges ();
  483. tv.Layout ();
  484. tv.Draw ();
  485. DriverAssert.AssertDriverContentsWithFrameAre (
  486. @"
  487. ││
  488. │╰►
  489. │h│
  490. │ │
  491. └─┘",
  492. output
  493. );
  494. }
  495. [Fact]
  496. [SetupFakeDriver]
  497. public void ShowTopLine_False_TabsOnBottom_False_TestTabView_Width4 ()
  498. {
  499. TabView tv = GetTabView (out _, out _);
  500. tv.Width = 4;
  501. tv.Height = 5;
  502. tv.Style = new () { ShowTopLine = false };
  503. tv.ApplyStyleChanges ();
  504. tv.Layout ();
  505. tv.Draw ();
  506. DriverAssert.AssertDriverContentsWithFrameAre (
  507. @"
  508. │T│
  509. │ ╰►
  510. │hi│
  511. │ │
  512. └──┘",
  513. output
  514. );
  515. }
  516. [Fact]
  517. [SetupFakeDriver]
  518. public void ShowTopLine_False_TabsOnBottom_False_TestThinTabView_WithLongNames ()
  519. {
  520. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  521. tv.Width = 10;
  522. tv.Height = 5;
  523. tv.Style = new () { ShowTopLine = false };
  524. tv.ApplyStyleChanges ();
  525. // Test two tab names that fit
  526. tab1.DisplayText = "12";
  527. tab2.DisplayText = "13";
  528. // Ensures that the tab bar subview gets the bounds of the parent TabView
  529. tv.Layout ();
  530. tv.Draw ();
  531. DriverAssert.AssertDriverContentsWithFrameAre (
  532. @"
  533. │12│13│
  534. │ ╰──┴──╮
  535. │hi │
  536. │ │
  537. └────────┘",
  538. output
  539. );
  540. tv.SelectedTab = tab2;
  541. Assert.Equal (tab2, tv.SubViews.First (v => v.Id.Contains ("tabRow")).MostFocused);
  542. tv.Layout ();
  543. View.SetClipToScreen ();
  544. tv.Draw ();
  545. DriverAssert.AssertDriverContentsWithFrameAre (
  546. @"
  547. │12│13│
  548. ├──╯ ╰──╮
  549. │hi2 │
  550. │ │
  551. └────────┘",
  552. output
  553. );
  554. tv.SelectedTab = tab1;
  555. // Test first tab name too long
  556. tab1.DisplayText = "12345678910";
  557. tab2.DisplayText = "13";
  558. tv.Layout ();
  559. View.SetClipToScreen ();
  560. tv.Draw ();
  561. DriverAssert.AssertDriverContentsWithFrameAre (
  562. @"
  563. │1234567│
  564. │ ╰►
  565. │hi │
  566. │ │
  567. └────────┘",
  568. output
  569. );
  570. //switch to tab2
  571. tv.SelectedTab = tab2;
  572. tv.Layout ();
  573. View.SetClipToScreen ();
  574. tv.Draw ();
  575. DriverAssert.AssertDriverContentsWithFrameAre (
  576. @"
  577. │13│
  578. ◄ ╰─────╮
  579. │hi2 │
  580. │ │
  581. └────────┘",
  582. output
  583. );
  584. // now make both tabs too long
  585. tab1.DisplayText = "12345678910";
  586. tab2.DisplayText = "abcdefghijklmnopq";
  587. tv.Layout ();
  588. View.SetClipToScreen ();
  589. tv.Draw ();
  590. DriverAssert.AssertDriverContentsWithFrameAre (
  591. @"
  592. │abcdefg│
  593. ◄ ╰╮
  594. │hi2 │
  595. │ │
  596. └────────┘",
  597. output
  598. );
  599. }
  600. [Fact]
  601. [SetupFakeDriver]
  602. public void ShowTopLine_False_TabsOnBottom_True_TestTabView_Width3 ()
  603. {
  604. TabView tv = GetTabView (out _, out _);
  605. tv.Width = 3;
  606. tv.Height = 5;
  607. tv.Style = new () { ShowTopLine = false, TabsOnBottom = true };
  608. tv.ApplyStyleChanges ();
  609. tv.Layout ();
  610. tv.Draw ();
  611. DriverAssert.AssertDriverContentsWithFrameAre (
  612. @"
  613. ┌─┐
  614. │h│
  615. │ │
  616. │╭►
  617. ││ ",
  618. output
  619. );
  620. }
  621. [Fact]
  622. [SetupFakeDriver]
  623. public void ShowTopLine_False_TabsOnBottom_True_TestTabView_Width4 ()
  624. {
  625. TabView tv = GetTabView (out _, out _);
  626. tv.Width = 4;
  627. tv.Height = 5;
  628. tv.Style = new () { ShowTopLine = false, TabsOnBottom = true };
  629. tv.ApplyStyleChanges ();
  630. tv.Layout ();
  631. tv.Draw ();
  632. DriverAssert.AssertDriverContentsWithFrameAre (
  633. @"
  634. ┌──┐
  635. │hi│
  636. │ │
  637. │ ╭►
  638. │T│ ",
  639. output
  640. );
  641. }
  642. [Fact]
  643. [SetupFakeDriver]
  644. public void ShowTopLine_False_TabsOnBottom_True_TestThinTabView_WithLongNames ()
  645. {
  646. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  647. tv.Width = 10;
  648. tv.Height = 5;
  649. tv.Style = new () { ShowTopLine = false, TabsOnBottom = true };
  650. tv.ApplyStyleChanges ();
  651. tv.Layout ();
  652. // Test two tab names that fit
  653. tab1.DisplayText = "12";
  654. tab2.DisplayText = "13";
  655. tv.Layout ();
  656. tv.Draw ();
  657. DriverAssert.AssertDriverContentsWithFrameAre (
  658. @"
  659. ┌────────┐
  660. │hi │
  661. │ │
  662. │ ╭──┬──╯
  663. │12│13│ ",
  664. output
  665. );
  666. tv.SelectedTab = tab2;
  667. Assert.Equal (tab2, tv.SubViews.First (v => v.Id.Contains ("tabRow")).MostFocused);
  668. tv.Layout ();
  669. View.SetClipToScreen ();
  670. tv.Draw ();
  671. DriverAssert.AssertDriverContentsWithFrameAre (
  672. @"
  673. ┌────────┐
  674. │hi2 │
  675. │ │
  676. ├──╮ ╭──╯
  677. │12│13│ ",
  678. output
  679. );
  680. tv.SelectedTab = tab1;
  681. // Test first tab name too long
  682. tab1.DisplayText = "12345678910";
  683. tab2.DisplayText = "13";
  684. tv.Layout ();
  685. View.SetClipToScreen ();
  686. tv.Draw ();
  687. DriverAssert.AssertDriverContentsWithFrameAre (
  688. @"
  689. ┌────────┐
  690. │hi │
  691. │ │
  692. │ ╭►
  693. │1234567│ ",
  694. output
  695. );
  696. //switch to tab2
  697. tv.SelectedTab = tab2;
  698. tv.Layout ();
  699. View.SetClipToScreen ();
  700. tv.Draw ();
  701. DriverAssert.AssertDriverContentsWithFrameAre (
  702. @"
  703. ┌────────┐
  704. │hi2 │
  705. │ │
  706. ◄ ╭─────╯
  707. │13│ ",
  708. output
  709. );
  710. // now make both tabs too long
  711. tab1.DisplayText = "12345678910";
  712. tab2.DisplayText = "abcdefghijklmnopq";
  713. tv.Layout ();
  714. View.SetClipToScreen ();
  715. tv.Draw ();
  716. DriverAssert.AssertDriverContentsWithFrameAre (
  717. @"
  718. ┌────────┐
  719. │hi2 │
  720. │ │
  721. ◄ ╭╯
  722. │abcdefg│ ",
  723. output
  724. );
  725. }
  726. [Fact]
  727. [SetupFakeDriver]
  728. public void ShowTopLine_True_TabsOnBottom_False_TestTabView_Width3 ()
  729. {
  730. TabView tv = GetTabView (out _, out _);
  731. tv.Width = 3;
  732. tv.Height = 5;
  733. tv.Layout ();
  734. tv.Draw ();
  735. DriverAssert.AssertDriverContentsWithFrameAre (
  736. @"
  737. ╭╮
  738. ││
  739. │╰►
  740. │h│
  741. └─┘",
  742. output
  743. );
  744. }
  745. [Fact]
  746. [SetupFakeDriver]
  747. public void ShowTopLine_True_TabsOnBottom_False_TestTabView_Width4 ()
  748. {
  749. TabView tv = GetTabView (out _, out _);
  750. tv.Width = 4;
  751. tv.Height = 5;
  752. tv.Layout ();
  753. View.SetClipToScreen ();
  754. tv.Draw ();
  755. DriverAssert.AssertDriverContentsWithFrameAre (
  756. @"
  757. ╭─╮
  758. │T│
  759. │ ╰►
  760. │hi│
  761. └──┘",
  762. output
  763. );
  764. }
  765. [Fact]
  766. [SetupFakeDriver]
  767. public void ShowTopLine_True_TabsOnBottom_False_TestThinTabView_WithLongNames ()
  768. {
  769. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  770. tv.Width = 10;
  771. tv.Height = 5;
  772. // Test two tab names that fit
  773. tab1.DisplayText = "12";
  774. tab2.DisplayText = "13";
  775. tv.Layout ();
  776. tv.Draw ();
  777. DriverAssert.AssertDriverContentsWithFrameAre (
  778. @"
  779. ╭──┬──╮
  780. │12│13│
  781. │ ╰──┴──╮
  782. │hi │
  783. └────────┘",
  784. output
  785. );
  786. tv.SelectedTab = tab2;
  787. tv.Layout ();
  788. View.SetClipToScreen ();
  789. tv.Draw ();
  790. DriverAssert.AssertDriverContentsWithFrameAre (
  791. @"
  792. ╭──┬──╮
  793. │12│13│
  794. ├──╯ ╰──╮
  795. │hi2 │
  796. └────────┘",
  797. output
  798. );
  799. tv.SelectedTab = tab1;
  800. // Test first tab name too long
  801. tab1.DisplayText = "12345678910";
  802. tab2.DisplayText = "13";
  803. tv.Layout ();
  804. View.SetClipToScreen ();
  805. tv.Draw ();
  806. DriverAssert.AssertDriverContentsWithFrameAre (
  807. @"
  808. ╭───────╮
  809. │1234567│
  810. │ ╰►
  811. │hi │
  812. └────────┘",
  813. output
  814. );
  815. //switch to tab2
  816. tv.SelectedTab = tab2;
  817. tv.Layout ();
  818. View.SetClipToScreen ();
  819. tv.Draw ();
  820. DriverAssert.AssertDriverContentsWithFrameAre (
  821. @"
  822. ╭──╮
  823. │13│
  824. ◄ ╰─────╮
  825. │hi2 │
  826. └────────┘",
  827. output
  828. );
  829. // now make both tabs too long
  830. tab1.DisplayText = "12345678910";
  831. tab2.DisplayText = "abcdefghijklmnopq";
  832. tv.Layout ();
  833. View.SetClipToScreen ();
  834. tv.Draw ();
  835. DriverAssert.AssertDriverContentsWithFrameAre (
  836. @"
  837. ╭───────╮
  838. │abcdefg│
  839. ◄ ╰╮
  840. │hi2 │
  841. └────────┘",
  842. output
  843. );
  844. }
  845. [Fact]
  846. [SetupFakeDriver]
  847. public void ShowTopLine_True_TabsOnBottom_False_With_Unicode ()
  848. {
  849. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  850. tv.Width = 20;
  851. tv.Height = 5;
  852. tab1.DisplayText = "Tab0";
  853. tab2.DisplayText = "Les Mise" + char.ConvertFromUtf32 (int.Parse ("0301", NumberStyles.HexNumber)) + "rables";
  854. tv.Layout ();
  855. tv.Draw ();
  856. DriverAssert.AssertDriverContentsWithFrameAre (
  857. @"
  858. ╭────╮
  859. │Tab0│
  860. │ ╰─────────────►
  861. │hi │
  862. └──────────────────┘",
  863. output
  864. );
  865. tv.SelectedTab = tab2;
  866. tv.Layout ();
  867. View.SetClipToScreen ();
  868. tv.Draw ();
  869. DriverAssert.AssertDriverContentsWithFrameAre (
  870. @"
  871. ╭──────────────╮
  872. │Les Misérables│
  873. ◄ ╰───╮
  874. │hi2 │
  875. └──────────────────┘",
  876. output
  877. );
  878. }
  879. [Fact]
  880. [SetupFakeDriver]
  881. public void ShowTopLine_True_TabsOnBottom_True_TestTabView_Width3 ()
  882. {
  883. TabView tv = GetTabView (out _, out _);
  884. tv.Width = 3;
  885. tv.Height = 5;
  886. tv.Style = new () { TabsOnBottom = true };
  887. tv.ApplyStyleChanges ();
  888. tv.Layout ();
  889. tv.Draw ();
  890. DriverAssert.AssertDriverContentsWithFrameAre (
  891. @"
  892. ┌─┐
  893. │h│
  894. │╭►
  895. ││
  896. ╰╯ ",
  897. output
  898. );
  899. }
  900. [Fact]
  901. [SetupFakeDriver]
  902. public void ShowTopLine_True_TabsOnBottom_True_TestTabView_Width4 ()
  903. {
  904. TabView tv = GetTabView (out _, out _);
  905. tv.Width = 4;
  906. tv.Height = 5;
  907. tv.Style = new () { TabsOnBottom = true };
  908. tv.ApplyStyleChanges ();
  909. tv.Layout ();
  910. tv.Draw ();
  911. DriverAssert.AssertDriverContentsWithFrameAre (
  912. @"
  913. ┌──┐
  914. │hi│
  915. │ ╭►
  916. │T│
  917. ╰─╯ ",
  918. output
  919. );
  920. }
  921. [Fact]
  922. [SetupFakeDriver]
  923. public void ShowTopLine_True_TabsOnBottom_True_TestThinTabView_WithLongNames ()
  924. {
  925. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  926. tv.Width = 10;
  927. tv.Height = 5;
  928. tv.Style = new () { TabsOnBottom = true };
  929. tv.ApplyStyleChanges ();
  930. tv.Layout ();
  931. // Test two tab names that fit
  932. tab1.DisplayText = "12";
  933. tab2.DisplayText = "13";
  934. tv.Layout ();
  935. tv.Draw ();
  936. DriverAssert.AssertDriverContentsWithFrameAre (
  937. @"
  938. ┌────────┐
  939. │hi │
  940. │ ╭──┬──╯
  941. │12│13│
  942. ╰──┴──╯ ",
  943. output
  944. );
  945. // Test first tab name too long
  946. tab1.DisplayText = "12345678910";
  947. tab2.DisplayText = "13";
  948. tv.Layout ();
  949. View.SetClipToScreen ();
  950. tv.Draw ();
  951. DriverAssert.AssertDriverContentsWithFrameAre (
  952. @"
  953. ┌────────┐
  954. │hi │
  955. │ ╭►
  956. │1234567│
  957. ╰───────╯ ",
  958. output
  959. );
  960. //switch to tab2
  961. tv.SelectedTab = tab2;
  962. tv.Layout ();
  963. View.SetClipToScreen ();
  964. tv.Draw ();
  965. DriverAssert.AssertDriverContentsWithFrameAre (
  966. @"
  967. ┌────────┐
  968. │hi2 │
  969. ◄ ╭─────╯
  970. │13│
  971. ╰──╯ ",
  972. output
  973. );
  974. // now make both tabs too long
  975. tab1.DisplayText = "12345678910";
  976. tab2.DisplayText = "abcdefghijklmnopq";
  977. tv.Layout ();
  978. View.SetClipToScreen ();
  979. tv.Draw ();
  980. DriverAssert.AssertDriverContentsWithFrameAre (
  981. @"
  982. ┌────────┐
  983. │hi2 │
  984. ◄ ╭╯
  985. │abcdefg│
  986. ╰───────╯ ",
  987. output
  988. );
  989. }
  990. [Fact]
  991. [SetupFakeDriver]
  992. public void ShowTopLine_True_TabsOnBottom_True_With_Unicode ()
  993. {
  994. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  995. tv.Width = 20;
  996. tv.Height = 5;
  997. tv.Style = new () { TabsOnBottom = true };
  998. tv.ApplyStyleChanges ();
  999. tab1.DisplayText = "Tab0";
  1000. tab2.DisplayText = "Les Mise" + char.ConvertFromUtf32 (int.Parse ("0301", NumberStyles.HexNumber)) + "rables";
  1001. tv.Layout ();
  1002. tv.Draw ();
  1003. DriverAssert.AssertDriverContentsWithFrameAre (
  1004. @"
  1005. ┌──────────────────┐
  1006. │hi │
  1007. │ ╭─────────────►
  1008. │Tab0│
  1009. ╰────╯ ",
  1010. output
  1011. );
  1012. tv.SelectedTab = tab2;
  1013. tv.Layout ();
  1014. View.SetClipToScreen ();
  1015. tv.Draw ();
  1016. DriverAssert.AssertDriverContentsWithFrameAre (
  1017. @"
  1018. ┌──────────────────┐
  1019. │hi2 │
  1020. ◄ ╭───╯
  1021. │Les Misérables│
  1022. ╰──────────────╯ ",
  1023. output
  1024. );
  1025. }
  1026. [Fact]
  1027. public void SwitchTabBy_NormalUsage ()
  1028. {
  1029. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  1030. Tab tab3;
  1031. Tab tab4;
  1032. Tab tab5;
  1033. tv.AddTab (tab3 = new (), false);
  1034. tv.AddTab (tab4 = new (), false);
  1035. tv.AddTab (tab5 = new (), false);
  1036. tv.SelectedTab = tab1;
  1037. var called = 0;
  1038. tv.SelectedTabChanged += (s, e) => { called++; };
  1039. tv.SwitchTabBy (1);
  1040. Assert.Equal (1, called);
  1041. Assert.Equal (tab2, tv.SelectedTab);
  1042. //reset called counter
  1043. called = 0;
  1044. // go right 2
  1045. tv.SwitchTabBy (2);
  1046. // even though we go right 2 indexes the event should only be called once
  1047. Assert.Equal (1, called);
  1048. Assert.Equal (tab4, tv.SelectedTab);
  1049. }
  1050. [Fact]
  1051. public void SwitchTabBy_OutOfTabsRange ()
  1052. {
  1053. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  1054. tv.SelectedTab = tab1;
  1055. tv.SwitchTabBy (500);
  1056. Assert.Equal (tab2, tv.SelectedTab);
  1057. tv.SwitchTabBy (-500);
  1058. Assert.Equal (tab1, tv.SelectedTab);
  1059. }
  1060. [Fact]
  1061. public void RemoveTab_ThatHasFocus ()
  1062. {
  1063. TabView tv = GetTabView (out Tab _, out Tab tab2);
  1064. tv.SelectedTab = tab2;
  1065. tab2.HasFocus = true;
  1066. Assert.Equal (2, tv.Tabs.Count);
  1067. foreach (Tab t in tv.Tabs.ToArray ())
  1068. {
  1069. tv.RemoveTab (t);
  1070. }
  1071. Assert.Empty (tv.Tabs);
  1072. }
  1073. [Fact]
  1074. [SetupFakeDriver]
  1075. public void Add_Three_TabsOnTop_ChangesTab ()
  1076. {
  1077. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  1078. Tab tab3;
  1079. tv.AddTab (
  1080. tab3 = new () { Id = "tab3", DisplayText = "Tab3", View = new TextView { Id = "tab3.TextView", Width = 3, Height = 1, Text = "hi3" } },
  1081. false);
  1082. tv.Width = 20;
  1083. tv.Height = 5;
  1084. tv.Layout ();
  1085. tv.Draw ();
  1086. Assert.Equal (tab1, tv.SelectedTab);
  1087. DriverAssert.AssertDriverContentsAre (
  1088. @"
  1089. ╭────┬────┬────╮
  1090. │Tab1│Tab2│Tab3│
  1091. │ ╰────┴────┴───╮
  1092. │hi │
  1093. └──────────────────┘
  1094. ",
  1095. output
  1096. );
  1097. tv.SelectedTab = tab2;
  1098. tv.Layout ();
  1099. View.SetClipToScreen ();
  1100. tv.Draw ();
  1101. DriverAssert.AssertDriverContentsWithFrameAre (
  1102. @"
  1103. ╭────┬────┬────╮
  1104. │Tab1│Tab2│Tab3│
  1105. ├────╯ ╰────┴───╮
  1106. │hi2 │
  1107. └──────────────────┘
  1108. ",
  1109. output
  1110. );
  1111. tv.SelectedTab = tab3;
  1112. tv.Layout ();
  1113. View.SetClipToScreen ();
  1114. tv.Draw ();
  1115. DriverAssert.AssertDriverContentsWithFrameAre (
  1116. @"
  1117. ╭────┬────┬────╮
  1118. │Tab1│Tab2│Tab3│
  1119. ├────┴────╯ ╰───╮
  1120. │hi3 │
  1121. └──────────────────┘
  1122. ",
  1123. output
  1124. );
  1125. }
  1126. [Fact]
  1127. [SetupFakeDriver]
  1128. public void Add_Three_TabsOnBottom_ChangesTab ()
  1129. {
  1130. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  1131. Tab tab3;
  1132. tv.AddTab (
  1133. tab3 = new () { Id = "tab3", DisplayText = "Tab3", View = new TextView { Id = "tab3.TextView", Width = 3, Height = 1, Text = "hi3" } },
  1134. false);
  1135. tv.Width = 20;
  1136. tv.Height = 5;
  1137. tv.Style = new () { TabsOnBottom = true };
  1138. tv.ApplyStyleChanges ();
  1139. tv.Layout ();
  1140. tv.Draw ();
  1141. Assert.Equal (tab1, tv.SelectedTab);
  1142. DriverAssert.AssertDriverContentsAre (
  1143. @"
  1144. ┌──────────────────┐
  1145. │hi │
  1146. │ ╭────┬────┬───╯
  1147. │Tab1│Tab2│Tab3│
  1148. ╰────┴────┴────╯
  1149. ",
  1150. output
  1151. );
  1152. tv.SelectedTab = tab2;
  1153. tv.Layout ();
  1154. View.SetClipToScreen ();
  1155. tv.Draw ();
  1156. DriverAssert.AssertDriverContentsWithFrameAre (
  1157. @"
  1158. ┌──────────────────┐
  1159. │hi2 │
  1160. ├────╮ ╭────┬───╯
  1161. │Tab1│Tab2│Tab3│
  1162. ╰────┴────┴────╯
  1163. ",
  1164. output
  1165. );
  1166. tv.SelectedTab = tab3;
  1167. tv.Layout ();
  1168. View.SetClipToScreen ();
  1169. tv.Draw ();
  1170. DriverAssert.AssertDriverContentsWithFrameAre (
  1171. @"
  1172. ┌──────────────────┐
  1173. │hi3 │
  1174. ├────┬────╮ ╭───╯
  1175. │Tab1│Tab2│Tab3│
  1176. ╰────┴────┴────╯
  1177. ",
  1178. output
  1179. );
  1180. }
  1181. [Fact]
  1182. [AutoInitShutdown]
  1183. public void Tab_Get_Focus_By_Press_F6 ()
  1184. {
  1185. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  1186. tv.Width = 20;
  1187. tv.Height = 5;
  1188. Toplevel top = new ();
  1189. top.Add (tv);
  1190. Application.Begin (top);
  1191. Assert.False (tab1.HasFocus);
  1192. Assert.True (Application.RaiseKeyDownEvent (Key.F6));
  1193. Assert.True (tab1.HasFocus);
  1194. top.Dispose ();
  1195. }
  1196. [Fact]
  1197. [SetupFakeDriver]
  1198. public void Mouse_Wheel_Changes_Tab ()
  1199. {
  1200. TabView tv = GetTabView (out Tab tab1, out Tab tab2);
  1201. tv.Width = 20;
  1202. tv.Height = 5;
  1203. Toplevel top = new ();
  1204. top.Add (tv);
  1205. Application.Begin (top);
  1206. Assert.False (tab1.HasFocus);
  1207. Application.RaiseMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.WheeledDown });
  1208. Assert.True (tab2.HasFocus);
  1209. Application.RaiseMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.WheeledUp });
  1210. Assert.True (tab1.HasFocus);
  1211. Application.RaiseMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.WheeledRight });
  1212. Assert.True (tab2.HasFocus);
  1213. Application.RaiseMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.WheeledLeft });
  1214. Assert.True (tab1.HasFocus);
  1215. top.Dispose ();
  1216. }
  1217. private TabView GetTabView () { return GetTabView (out _, out _); }
  1218. private TabView GetTabView (out Tab tab1, out Tab tab2)
  1219. {
  1220. var tv = new TabView () { Id = "tv " };
  1221. tv.BeginInit ();
  1222. tv.EndInit ();
  1223. tv.ColorScheme = new ();
  1224. tv.AddTab (
  1225. tab1 = new () { Id = "tab1", DisplayText = "Tab1", View = new TextField { Id = "tab1.TextField", Width = 2, Text = "hi" } },
  1226. false
  1227. );
  1228. tv.AddTab (tab2 = new () { Id = "tab2", DisplayText = "Tab2", View = new Label { Id = "tab1.Label", Text = "hi2" } }, false);
  1229. return tv;
  1230. }
  1231. }