2
0

TabViewTests.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509
  1. using System.Globalization;
  2. using UnitTests;
  3. using Xunit.Abstractions;
  4. namespace UnitTests.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. [SetupFakeApplication]
  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 (Skip = "Really slow test")]
  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 Runnable ();
  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. AutoInitShutdownAttribute.RunIteration ();
  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. AutoInitShutdownAttribute.RunIteration ();
  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. AutoInitShutdownAttribute.RunIteration ();
  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. AutoInitShutdownAttribute.RunIteration ();
  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. AutoInitShutdownAttribute.RunIteration ();
  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 Runnable ();
  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. AutoInitShutdownAttribute.RunIteration ();
  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. AutoInitShutdownAttribute.RunIteration ();
  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 Runnable ();
  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. AutoInitShutdownAttribute.RunIteration ();
  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. AutoInitShutdownAttribute.RunIteration ();
  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. Runnable 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. AutoInitShutdownAttribute.RunIteration ();
  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. AutoInitShutdownAttribute.RunIteration ();
  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 runnable
  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 runnable, 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. AutoInitShutdownAttribute.RunIteration ();
  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. AutoInitShutdownAttribute.RunIteration ();
  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. AutoInitShutdownAttribute.RunIteration ();
  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. AutoInitShutdownAttribute.RunIteration ();
  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. AutoInitShutdownAttribute.RunIteration ();
  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. [SetupFakeApplication]
  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. [SetupFakeApplication]
  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. [SetupFakeApplication]
  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. tv.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. tv.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. tv.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. tv.SetClipToScreen ();
  589. tv.Draw ();
  590. DriverAssert.AssertDriverContentsWithFrameAre (
  591. @"
  592. │abcdefg│
  593. ◄ ╰╮
  594. │hi2 │
  595. │ │
  596. └────────┘",
  597. output
  598. );
  599. }
  600. [Fact]
  601. [SetupFakeApplication]
  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. [SetupFakeApplication]
  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. [SetupFakeApplication]
  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. tv.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. tv.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. tv.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. tv.SetClipToScreen ();
  715. tv.Draw ();
  716. DriverAssert.AssertDriverContentsWithFrameAre (
  717. @"
  718. ┌────────┐
  719. │hi2 │
  720. │ │
  721. ◄ ╭╯
  722. │abcdefg│ ",
  723. output
  724. );
  725. }
  726. [Fact]
  727. [SetupFakeApplication]
  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. [SetupFakeApplication]
  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. tv.SetClipToScreen ();
  754. tv.Draw ();
  755. DriverAssert.AssertDriverContentsWithFrameAre (
  756. @"
  757. ╭─╮
  758. │T│
  759. │ ╰►
  760. │hi│
  761. └──┘",
  762. output
  763. );
  764. }
  765. [Fact]
  766. [SetupFakeApplication]
  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. tv.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. tv.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. tv.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. tv.SetClipToScreen ();
  834. tv.Draw ();
  835. DriverAssert.AssertDriverContentsWithFrameAre (
  836. @"
  837. ╭───────╮
  838. │abcdefg│
  839. ◄ ╰╮
  840. │hi2 │
  841. └────────┘",
  842. output
  843. );
  844. }
  845. [Fact]
  846. [SetupFakeApplication]
  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. tv.SetClipToScreen ();
  868. tv.Draw ();
  869. DriverAssert.AssertDriverContentsWithFrameAre (
  870. @"
  871. ╭──────────────╮
  872. │Les Misérables│
  873. ◄ ╰───╮
  874. │hi2 │
  875. └──────────────────┘",
  876. output
  877. );
  878. }
  879. [Fact]
  880. [SetupFakeApplication]
  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. [SetupFakeApplication]
  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. [SetupFakeApplication]
  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. tv.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. tv.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. tv.SetClipToScreen ();
  979. tv.Draw ();
  980. DriverAssert.AssertDriverContentsWithFrameAre (
  981. @"
  982. ┌────────┐
  983. │hi2 │
  984. ◄ ╭╯
  985. │abcdefg│
  986. ╰───────╯ ",
  987. output
  988. );
  989. }
  990. [Fact]
  991. [SetupFakeApplication]
  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. tv.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. [SetupFakeApplication]
  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. tv.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. tv.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. [SetupFakeApplication]
  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. tv.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. tv.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. Runnable 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. [SetupFakeApplication]
  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. Runnable 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 ()
  1221. {
  1222. Driver = ApplicationImpl.Instance.Driver,
  1223. Id = "tv "
  1224. };
  1225. tv.BeginInit ();
  1226. tv.EndInit ();
  1227. //tv.Scheme = new ();
  1228. tv.AddTab (
  1229. tab1 = new () { Id = "tab1", DisplayText = "Tab1", View = new TextField { Id = "tab1.TextField", Width = 2, Text = "hi" } },
  1230. false
  1231. );
  1232. tv.AddTab (tab2 = new () { Id = "tab2", DisplayText = "Tab2", View = new Label { Id = "tab1.Label", Text = "hi2" } }, false);
  1233. return tv;
  1234. }
  1235. }