DialogTests.cs 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  1. using Xunit.Abstractions;
  2. using static Terminal.Gui.Application;
  3. namespace Terminal.Gui.DialogTests;
  4. public class DialogTests
  5. {
  6. private readonly ITestOutputHelper _output;
  7. public DialogTests (ITestOutputHelper output) { _output = output; }
  8. [Fact]
  9. [AutoInitShutdown]
  10. public void Add_Button_Works ()
  11. {
  12. RunState runstate = null;
  13. var d = (FakeDriver)Driver;
  14. var title = "1234";
  15. var btn1Text = "yes";
  16. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  17. var btn2Text = "no";
  18. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  19. // We test with one button first, but do this to get the width right for 2
  20. int width = $@"{CM.Glyphs.VLine} {btn1} {btn2} {CM.Glyphs.VLine}".Length;
  21. d.SetBufferSize (width, 1);
  22. // Default (center)
  23. var dlg = new Dialog
  24. {
  25. Title = title,
  26. Width = width,
  27. Height = 1,
  28. ButtonAlignment = Dialog.ButtonAlignments.Center,
  29. Buttons = [new Button { Text = btn1Text }]
  30. };
  31. // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
  32. dlg.Border.Thickness = new Thickness (1, 0, 1, 0);
  33. runstate = Begin (dlg);
  34. var buttonRow = $"{CM.Glyphs.VLine} {btn1} {CM.Glyphs.VLine}";
  35. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  36. // Now add a second button
  37. buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {CM.Glyphs.VLine}";
  38. dlg.AddButton (new Button { Text = btn2Text });
  39. var first = false;
  40. RunIteration (ref runstate, ref first);
  41. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  42. End (runstate);
  43. // Justify
  44. dlg = new Dialog
  45. {
  46. Title = title,
  47. Width = width,
  48. Height = 1,
  49. ButtonAlignment = Dialog.ButtonAlignments.Justify,
  50. Buttons = [new Button { Text = btn1Text }]
  51. };
  52. // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
  53. dlg.Border.Thickness = new Thickness (1, 0, 1, 0);
  54. runstate = Begin (dlg);
  55. buttonRow = $"{CM.Glyphs.VLine} {btn1}{CM.Glyphs.VLine}";
  56. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  57. // Now add a second button
  58. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2}{CM.Glyphs.VLine}";
  59. dlg.AddButton (new Button { Text = btn2Text });
  60. first = false;
  61. RunIteration (ref runstate, ref first);
  62. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  63. End (runstate);
  64. // Right
  65. dlg = new Dialog
  66. {
  67. Title = title,
  68. Width = width,
  69. Height = 1,
  70. ButtonAlignment = Dialog.ButtonAlignments.Right,
  71. Buttons = [new Button { Text = btn1Text }]
  72. };
  73. // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
  74. dlg.Border.Thickness = new Thickness (1, 0, 1, 0);
  75. runstate = Begin (dlg);
  76. buttonRow = $"{CM.Glyphs.VLine}{new string (' ', width - btn1.Length - 2)}{btn1}{CM.Glyphs.VLine}";
  77. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  78. // Now add a second button
  79. buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2}{CM.Glyphs.VLine}";
  80. dlg.AddButton (new Button { Text = btn2Text });
  81. first = false;
  82. RunIteration (ref runstate, ref first);
  83. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  84. End (runstate);
  85. // Left
  86. dlg = new Dialog
  87. {
  88. Title = title,
  89. Width = width,
  90. Height = 1,
  91. ButtonAlignment = Dialog.ButtonAlignments.Left,
  92. Buttons = [new Button { Text = btn1Text }]
  93. };
  94. // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
  95. dlg.Border.Thickness = new Thickness (1, 0, 1, 0);
  96. runstate = Begin (dlg);
  97. buttonRow = $"{CM.Glyphs.VLine}{btn1}{new string (' ', width - btn1.Length - 2)}{CM.Glyphs.VLine}";
  98. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  99. // Now add a second button
  100. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {CM.Glyphs.VLine}";
  101. dlg.AddButton (new Button { Text = btn2Text });
  102. first = false;
  103. RunIteration (ref runstate, ref first);
  104. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  105. End (runstate);
  106. }
  107. [Fact]
  108. [AutoInitShutdown]
  109. public void ButtonAlignment_Four ()
  110. {
  111. RunState runstate = null;
  112. var d = (FakeDriver)Driver;
  113. var title = "1234";
  114. // E.g "|[ yes ][ no ][ maybe ]|"
  115. var btn1Text = "yes";
  116. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  117. var btn2Text = "no";
  118. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  119. var btn3Text = "maybe";
  120. var btn3 = $"{CM.Glyphs.LeftBracket} {btn3Text} {CM.Glyphs.RightBracket}";
  121. var btn4Text = "never";
  122. var btn4 = $"{CM.Glyphs.LeftBracket} {btn4Text} {CM.Glyphs.RightBracket}";
  123. var buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
  124. int width = buttonRow.Length;
  125. d.SetBufferSize (buttonRow.Length, 3);
  126. // Default - Center
  127. (runstate, Dialog _) = RunButtonTestDialog (
  128. title,
  129. width,
  130. Dialog.ButtonAlignments.Center,
  131. new Button { Text = btn1Text },
  132. new Button { Text = btn2Text },
  133. new Button { Text = btn3Text },
  134. new Button { Text = btn4Text }
  135. );
  136. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  137. End (runstate);
  138. // Justify
  139. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
  140. Assert.Equal (width, buttonRow.Length);
  141. (runstate, Dialog _) = RunButtonTestDialog (
  142. title,
  143. width,
  144. Dialog.ButtonAlignments.Justify,
  145. new Button { Text = btn1Text },
  146. new Button { Text = btn2Text },
  147. new Button { Text = btn3Text },
  148. new Button { Text = btn4Text }
  149. );
  150. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  151. End (runstate);
  152. // Right
  153. buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
  154. Assert.Equal (width, buttonRow.Length);
  155. (runstate, Dialog _) = RunButtonTestDialog (
  156. title,
  157. width,
  158. Dialog.ButtonAlignments.Right,
  159. new Button { Text = btn1Text },
  160. new Button { Text = btn2Text },
  161. new Button { Text = btn3Text },
  162. new Button { Text = btn4Text }
  163. );
  164. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  165. End (runstate);
  166. // Left
  167. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
  168. Assert.Equal (width, buttonRow.Length);
  169. (runstate, Dialog _) = RunButtonTestDialog (
  170. title,
  171. width,
  172. Dialog.ButtonAlignments.Left,
  173. new Button { Text = btn1Text },
  174. new Button { Text = btn2Text },
  175. new Button { Text = btn3Text },
  176. new Button { Text = btn4Text }
  177. );
  178. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  179. End (runstate);
  180. }
  181. [Fact]
  182. [AutoInitShutdown]
  183. public void ButtonAlignment_Four_On_Too_Small_Width ()
  184. {
  185. RunState runstate = null;
  186. var d = (FakeDriver)Driver;
  187. var title = "1234";
  188. // E.g "|[ yes ][ no ][ maybe ][ never ]|"
  189. var btn1Text = "yes";
  190. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  191. var btn2Text = "no";
  192. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  193. var btn3Text = "maybe";
  194. var btn3 = $"{CM.Glyphs.LeftBracket} {btn3Text} {CM.Glyphs.RightBracket}";
  195. var btn4Text = "never";
  196. var btn4 = $"{CM.Glyphs.LeftBracket} {btn4Text} {CM.Glyphs.RightBracket}";
  197. var buttonRow = string.Empty;
  198. var width = 30;
  199. d.SetBufferSize (width, 1);
  200. // Default - Center
  201. buttonRow =
  202. $"{CM.Glyphs.VLine}es {CM.Glyphs.RightBracket} {btn2} {btn3} {CM.Glyphs.LeftBracket} neve{CM.Glyphs.VLine}";
  203. (runstate, Dialog dlg) = RunButtonTestDialog (
  204. title,
  205. width,
  206. Dialog.ButtonAlignments.Center,
  207. new Button { Text = btn1Text },
  208. new Button { Text = btn2Text },
  209. new Button { Text = btn3Text },
  210. new Button { Text = btn4Text }
  211. );
  212. Assert.Equal (new (width, 1), dlg.Frame.Size);
  213. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  214. End (runstate);
  215. // Justify
  216. buttonRow =
  217. $"{
  218. CM.Glyphs.VLine
  219. }{
  220. CM.Glyphs.LeftBracket
  221. } yes {
  222. CM.Glyphs.LeftBracket
  223. } no {
  224. CM.Glyphs.LeftBracket
  225. } maybe {
  226. CM.Glyphs.LeftBracket
  227. } never {
  228. CM.Glyphs.RightBracket
  229. }{
  230. CM.Glyphs.VLine
  231. }";
  232. (runstate, Dialog _) = RunButtonTestDialog (
  233. title,
  234. width,
  235. Dialog.ButtonAlignments.Justify,
  236. new Button { Text = btn1Text },
  237. new Button { Text = btn2Text },
  238. new Button { Text = btn3Text },
  239. new Button { Text = btn4Text }
  240. );
  241. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  242. End (runstate);
  243. // Right
  244. buttonRow = $"{CM.Glyphs.VLine}{CM.Glyphs.RightBracket} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
  245. (runstate, Dialog _) = RunButtonTestDialog (
  246. title,
  247. width,
  248. Dialog.ButtonAlignments.Right,
  249. new Button { Text = btn1Text },
  250. new Button { Text = btn2Text },
  251. new Button { Text = btn3Text },
  252. new Button { Text = btn4Text }
  253. );
  254. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  255. End (runstate);
  256. // Left
  257. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {CM.Glyphs.LeftBracket} n{CM.Glyphs.VLine}";
  258. (runstate, Dialog _) = RunButtonTestDialog (
  259. title,
  260. width,
  261. Dialog.ButtonAlignments.Left,
  262. new Button { Text = btn1Text },
  263. new Button { Text = btn2Text },
  264. new Button { Text = btn3Text },
  265. new Button { Text = btn4Text }
  266. );
  267. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  268. End (runstate);
  269. }
  270. [Fact]
  271. [AutoInitShutdown]
  272. public void ButtonAlignment_Four_WideOdd ()
  273. {
  274. RunState runstate = null;
  275. var d = (FakeDriver)Driver;
  276. var title = "1234";
  277. // E.g "|[ yes ][ no ][ maybe ]|"
  278. var btn1Text = "really long button 1";
  279. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  280. var btn2Text = "really long button 2";
  281. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  282. var btn3Text = "really long button 3";
  283. var btn3 = $"{CM.Glyphs.LeftBracket} {btn3Text} {CM.Glyphs.RightBracket}";
  284. var btn4Text = "really long button 44"; // 44 is intentional to make length different than rest
  285. var btn4 = $"{CM.Glyphs.LeftBracket} {btn4Text} {CM.Glyphs.RightBracket}";
  286. // Note extra spaces to make dialog even wider
  287. // 123456 1234567
  288. var buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
  289. int width = buttonRow.Length;
  290. d.SetBufferSize (buttonRow.Length, 1);
  291. // Default - Center
  292. (runstate, Dialog _) = RunButtonTestDialog (
  293. title,
  294. width,
  295. Dialog.ButtonAlignments.Center,
  296. new Button { Text = btn1Text },
  297. new Button { Text = btn2Text },
  298. new Button { Text = btn3Text },
  299. new Button { Text = btn4Text }
  300. );
  301. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  302. End (runstate);
  303. // Justify
  304. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
  305. Assert.Equal (width, buttonRow.Length);
  306. (runstate, Dialog _) = RunButtonTestDialog (
  307. title,
  308. width,
  309. Dialog.ButtonAlignments.Justify,
  310. new Button { Text = btn1Text },
  311. new Button { Text = btn2Text },
  312. new Button { Text = btn3Text },
  313. new Button { Text = btn4Text }
  314. );
  315. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  316. End (runstate);
  317. // Right
  318. buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
  319. Assert.Equal (width, buttonRow.Length);
  320. (runstate, Dialog _) = RunButtonTestDialog (
  321. title,
  322. width,
  323. Dialog.ButtonAlignments.Right,
  324. new Button { Text = btn1Text },
  325. new Button { Text = btn2Text },
  326. new Button { Text = btn3Text },
  327. new Button { Text = btn4Text }
  328. );
  329. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  330. End (runstate);
  331. // Left
  332. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
  333. Assert.Equal (width, buttonRow.Length);
  334. (runstate, Dialog _) = RunButtonTestDialog (
  335. title,
  336. width,
  337. Dialog.ButtonAlignments.Left,
  338. new Button { Text = btn1Text },
  339. new Button { Text = btn2Text },
  340. new Button { Text = btn3Text },
  341. new Button { Text = btn4Text }
  342. );
  343. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  344. End (runstate);
  345. }
  346. [Fact]
  347. [AutoInitShutdown]
  348. public void ButtonAlignment_Four_Wider ()
  349. {
  350. RunState runstate = null;
  351. var d = (FakeDriver)Driver;
  352. var title = "1234";
  353. // E.g "|[ yes ][ no ][ maybe ]|"
  354. var btn1Text = "yes";
  355. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  356. var btn2Text = "no";
  357. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  358. var btn3Text = "你你你你你"; // This is a wide char
  359. var btn3 = $"{CM.Glyphs.LeftBracket} {btn3Text} {CM.Glyphs.RightBracket}";
  360. // Requires a Nerd Font
  361. var btn4Text = "\uE36E\uE36F\uE370\uE371\uE372\uE373";
  362. var btn4 = $"{CM.Glyphs.LeftBracket} {btn4Text} {CM.Glyphs.RightBracket}";
  363. // Note extra spaces to make dialog even wider
  364. // 123456 123456
  365. var buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
  366. int width = buttonRow.GetColumns ();
  367. d.SetBufferSize (width, 3);
  368. // Default - Center
  369. (runstate, Dialog _) = RunButtonTestDialog (
  370. title,
  371. width,
  372. Dialog.ButtonAlignments.Center,
  373. new Button { Text = btn1Text },
  374. new Button { Text = btn2Text },
  375. new Button { Text = btn3Text },
  376. new Button { Text = btn4Text }
  377. );
  378. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  379. End (runstate);
  380. // Justify
  381. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
  382. Assert.Equal (width, buttonRow.GetColumns ());
  383. (runstate, Dialog _) = RunButtonTestDialog (
  384. title,
  385. width,
  386. Dialog.ButtonAlignments.Justify,
  387. new Button { Text = btn1Text },
  388. new Button { Text = btn2Text },
  389. new Button { Text = btn3Text },
  390. new Button { Text = btn4Text }
  391. );
  392. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  393. End (runstate);
  394. // Right
  395. buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
  396. Assert.Equal (width, buttonRow.GetColumns ());
  397. (runstate, Dialog _) = RunButtonTestDialog (
  398. title,
  399. width,
  400. Dialog.ButtonAlignments.Right,
  401. new Button { Text = btn1Text },
  402. new Button { Text = btn2Text },
  403. new Button { Text = btn3Text },
  404. new Button { Text = btn4Text }
  405. );
  406. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  407. End (runstate);
  408. // Left
  409. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
  410. Assert.Equal (width, buttonRow.GetColumns ());
  411. (runstate, Dialog _) = RunButtonTestDialog (
  412. title,
  413. width,
  414. Dialog.ButtonAlignments.Left,
  415. new Button { Text = btn1Text },
  416. new Button { Text = btn2Text },
  417. new Button { Text = btn3Text },
  418. new Button { Text = btn4Text }
  419. );
  420. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  421. End (runstate);
  422. }
  423. [Fact]
  424. [AutoInitShutdown]
  425. public void ButtonAlignment_One ()
  426. {
  427. var d = (FakeDriver)Driver;
  428. RunState runstate = null;
  429. var title = "1234";
  430. // E.g "|[ ok ]|"
  431. var btnText = "ok";
  432. var buttonRow =
  433. $"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket} {CM.Glyphs.VLine}";
  434. int width = buttonRow.Length;
  435. d.SetBufferSize (width, 1);
  436. (runstate, Dialog _) = RunButtonTestDialog (
  437. title,
  438. width,
  439. Dialog.ButtonAlignments.Center,
  440. new Button { Text = btnText }
  441. );
  442. // Center
  443. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  444. End (runstate);
  445. // Justify
  446. buttonRow =
  447. $"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket}{CM.Glyphs.VLine}";
  448. Assert.Equal (width, buttonRow.Length);
  449. (runstate, Dialog _) = RunButtonTestDialog (
  450. title,
  451. width,
  452. Dialog.ButtonAlignments.Justify,
  453. new Button { Text = btnText }
  454. );
  455. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  456. End (runstate);
  457. // Right
  458. buttonRow =
  459. $"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket}{CM.Glyphs.VLine}";
  460. Assert.Equal (width, buttonRow.Length);
  461. (runstate, Dialog _) = RunButtonTestDialog (
  462. title,
  463. width,
  464. Dialog.ButtonAlignments.Right,
  465. new Button { Text = btnText }
  466. );
  467. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  468. End (runstate);
  469. // Left
  470. buttonRow =
  471. $"{CM.Glyphs.VLine}{CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket} {CM.Glyphs.VLine}";
  472. Assert.Equal (width, buttonRow.Length);
  473. (runstate, Dialog _) = RunButtonTestDialog (
  474. title,
  475. width,
  476. Dialog.ButtonAlignments.Left,
  477. new Button { Text = btnText }
  478. );
  479. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  480. End (runstate);
  481. // Wider
  482. buttonRow =
  483. $"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket} {CM.Glyphs.VLine}";
  484. width = buttonRow.Length;
  485. d.SetBufferSize (width, 1);
  486. (runstate, Dialog _) = RunButtonTestDialog (
  487. title,
  488. width,
  489. Dialog.ButtonAlignments.Center,
  490. new Button { Text = btnText }
  491. );
  492. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  493. End (runstate);
  494. // Justify
  495. buttonRow =
  496. $"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket}{CM.Glyphs.VLine}";
  497. Assert.Equal (width, buttonRow.Length);
  498. (runstate, Dialog _) = RunButtonTestDialog (
  499. title,
  500. width,
  501. Dialog.ButtonAlignments.Justify,
  502. new Button { Text = btnText }
  503. );
  504. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  505. End (runstate);
  506. // Right
  507. buttonRow =
  508. $"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket}{CM.Glyphs.VLine}";
  509. Assert.Equal (width, buttonRow.Length);
  510. (runstate, Dialog _) = RunButtonTestDialog (
  511. title,
  512. width,
  513. Dialog.ButtonAlignments.Right,
  514. new Button { Text = btnText }
  515. );
  516. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  517. End (runstate);
  518. // Left
  519. buttonRow =
  520. $"{CM.Glyphs.VLine}{CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket} {CM.Glyphs.VLine}";
  521. Assert.Equal (width, buttonRow.Length);
  522. (runstate, Dialog _) = RunButtonTestDialog (
  523. title,
  524. width,
  525. Dialog.ButtonAlignments.Left,
  526. new Button { Text = btnText }
  527. );
  528. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  529. End (runstate);
  530. }
  531. [Fact]
  532. [AutoInitShutdown]
  533. public void ButtonAlignment_Three ()
  534. {
  535. RunState runstate = null;
  536. var d = (FakeDriver)Driver;
  537. var title = "1234";
  538. // E.g "|[ yes ][ no ][ maybe ]|"
  539. var btn1Text = "yes";
  540. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  541. var btn2Text = "no";
  542. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  543. var btn3Text = "maybe";
  544. var btn3 = $"{CM.Glyphs.LeftBracket} {btn3Text} {CM.Glyphs.RightBracket}";
  545. var buttonRow = $@"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {CM.Glyphs.VLine}";
  546. int width = buttonRow.Length;
  547. d.SetBufferSize (buttonRow.Length, 3);
  548. (runstate, Dialog _) = RunButtonTestDialog (
  549. title,
  550. width,
  551. Dialog.ButtonAlignments.Center,
  552. new Button { Text = btn1Text },
  553. new Button { Text = btn2Text },
  554. new Button { Text = btn3Text }
  555. );
  556. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  557. End (runstate);
  558. // Justify
  559. buttonRow = $@"{CM.Glyphs.VLine}{btn1} {btn2} {btn3}{CM.Glyphs.VLine}";
  560. Assert.Equal (width, buttonRow.Length);
  561. (runstate, Dialog _) = RunButtonTestDialog (
  562. title,
  563. width,
  564. Dialog.ButtonAlignments.Justify,
  565. new Button { Text = btn1Text },
  566. new Button { Text = btn2Text },
  567. new Button { Text = btn3Text }
  568. );
  569. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  570. End (runstate);
  571. // Right
  572. buttonRow = $@"{CM.Glyphs.VLine} {btn1} {btn2} {btn3}{CM.Glyphs.VLine}";
  573. Assert.Equal (width, buttonRow.Length);
  574. (runstate, Dialog _) = RunButtonTestDialog (
  575. title,
  576. width,
  577. Dialog.ButtonAlignments.Right,
  578. new Button { Text = btn1Text },
  579. new Button { Text = btn2Text },
  580. new Button { Text = btn3Text }
  581. );
  582. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  583. End (runstate);
  584. // Left
  585. buttonRow = $@"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {CM.Glyphs.VLine}";
  586. Assert.Equal (width, buttonRow.Length);
  587. (runstate, Dialog _) = RunButtonTestDialog (
  588. title,
  589. width,
  590. Dialog.ButtonAlignments.Left,
  591. new Button { Text = btn1Text },
  592. new Button { Text = btn2Text },
  593. new Button { Text = btn3Text }
  594. );
  595. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  596. End (runstate);
  597. }
  598. [Fact]
  599. [AutoInitShutdown]
  600. public void ButtonAlignment_Two ()
  601. {
  602. RunState runstate = null;
  603. var d = (FakeDriver)Driver;
  604. var title = "1234";
  605. // E.g "|[ yes ][ no ]|"
  606. var btn1Text = "yes";
  607. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  608. var btn2Text = "no";
  609. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  610. var buttonRow = $@"{CM.Glyphs.VLine} {btn1} {btn2} {CM.Glyphs.VLine}";
  611. int width = buttonRow.Length;
  612. d.SetBufferSize (buttonRow.Length, 3);
  613. (runstate, Dialog _) = RunButtonTestDialog (
  614. title,
  615. width,
  616. Dialog.ButtonAlignments.Center,
  617. new Button { Text = btn1Text },
  618. new Button { Text = btn2Text }
  619. );
  620. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  621. End (runstate);
  622. // Justify
  623. buttonRow = $@"{CM.Glyphs.VLine}{btn1} {btn2}{CM.Glyphs.VLine}";
  624. Assert.Equal (width, buttonRow.Length);
  625. (runstate, Dialog _) = RunButtonTestDialog (
  626. title,
  627. width,
  628. Dialog.ButtonAlignments.Justify,
  629. new Button { Text = btn1Text },
  630. new Button { Text = btn2Text }
  631. );
  632. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  633. End (runstate);
  634. // Right
  635. buttonRow = $@"{CM.Glyphs.VLine} {btn1} {btn2}{CM.Glyphs.VLine}";
  636. Assert.Equal (width, buttonRow.Length);
  637. (runstate, Dialog _) = RunButtonTestDialog (
  638. title,
  639. width,
  640. Dialog.ButtonAlignments.Right,
  641. new Button { Text = btn1Text },
  642. new Button { Text = btn2Text }
  643. );
  644. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  645. End (runstate);
  646. // Left
  647. buttonRow = $@"{CM.Glyphs.VLine}{btn1} {btn2} {CM.Glyphs.VLine}";
  648. Assert.Equal (width, buttonRow.Length);
  649. (runstate, Dialog _) = RunButtonTestDialog (
  650. title,
  651. width,
  652. Dialog.ButtonAlignments.Left,
  653. new Button { Text = btn1Text },
  654. new Button { Text = btn2Text }
  655. );
  656. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  657. End (runstate);
  658. }
  659. [Fact]
  660. [AutoInitShutdown]
  661. public void ButtonAlignment_Two_Hidden ()
  662. {
  663. RunState runstate = null;
  664. var firstIteration = false;
  665. var d = (FakeDriver)Driver;
  666. var title = "1234";
  667. // E.g "|[ yes ][ no ]|"
  668. var btn1Text = "yes";
  669. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  670. var btn2Text = "no";
  671. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  672. var buttonRow = $@"{CM.Glyphs.VLine} {btn1} {btn2} {CM.Glyphs.VLine}";
  673. int width = buttonRow.Length;
  674. d.SetBufferSize (buttonRow.Length, 3);
  675. Dialog dlg = null;
  676. Button button1, button2;
  677. // Default (Center)
  678. button1 = new Button { Text = btn1Text };
  679. button2 = new Button { Text = btn2Text };
  680. (runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, button1, button2);
  681. button1.Visible = false;
  682. RunIteration (ref runstate, ref firstIteration);
  683. buttonRow = $@"{CM.Glyphs.VLine} {btn2} {CM.Glyphs.VLine}";
  684. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  685. End (runstate);
  686. // Justify
  687. Assert.Equal (width, buttonRow.Length);
  688. button1 = new Button { Text = btn1Text };
  689. button2 = new Button { Text = btn2Text };
  690. (runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, button1, button2);
  691. button1.Visible = false;
  692. RunIteration (ref runstate, ref firstIteration);
  693. buttonRow = $@"{CM.Glyphs.VLine} {btn2}{CM.Glyphs.VLine}";
  694. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  695. End (runstate);
  696. // Right
  697. Assert.Equal (width, buttonRow.Length);
  698. button1 = new Button { Text = btn1Text };
  699. button2 = new Button { Text = btn2Text };
  700. (runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, button1, button2);
  701. button1.Visible = false;
  702. RunIteration (ref runstate, ref firstIteration);
  703. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  704. End (runstate);
  705. // Left
  706. Assert.Equal (width, buttonRow.Length);
  707. button1 = new Button { Text = btn1Text };
  708. button2 = new Button { Text = btn2Text };
  709. (runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, button1, button2);
  710. button1.Visible = false;
  711. RunIteration (ref runstate, ref firstIteration);
  712. buttonRow = $@"{CM.Glyphs.VLine} {btn2} {CM.Glyphs.VLine}";
  713. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  714. End (runstate);
  715. }
  716. [Fact]
  717. [AutoInitShutdown]
  718. public void Dialog_In_Window_With_Size_One_Button_Aligns ()
  719. {
  720. ((FakeDriver)Driver).SetBufferSize (20, 5);
  721. var win = new Window ();
  722. var iterations = 0;
  723. Iteration += (s, a) =>
  724. {
  725. if (++iterations > 2)
  726. {
  727. RequestStop ();
  728. }
  729. };
  730. var btn = $"{CM.Glyphs.LeftBracket} Ok {CM.Glyphs.RightBracket}";
  731. win.Loaded += (s, a) =>
  732. {
  733. var dlg = new Dialog { Width = 18, Height = 3, Buttons = [new Button { Text = "Ok" }] };
  734. dlg.Loaded += (s, a) =>
  735. {
  736. Refresh ();
  737. var expected = @$"
  738. ┌──────────────────┐
  739. │┌────────────────┐│
  740. ││ {
  741. btn
  742. } ││
  743. │└────────────────┘│
  744. └──────────────────┘";
  745. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  746. };
  747. Run (dlg);
  748. };
  749. Run (win);
  750. }
  751. [Theory]
  752. [AutoInitShutdown]
  753. [InlineData (
  754. 5,
  755. @"
  756. ┌┌───────────────┐─┐
  757. ││ │ │
  758. ││ ⟦ Ok ⟧ │ │
  759. │└───────────────┘ │
  760. └──────────────────┘"
  761. )]
  762. [InlineData (
  763. 6,
  764. @"
  765. ┌┌───────────────┐─┐
  766. ││ │ │
  767. ││ │ │
  768. ││ ⟦ Ok ⟧ │ │
  769. │└───────────────┘ │
  770. └──────────────────┘"
  771. )]
  772. [InlineData (
  773. 7,
  774. @"
  775. ┌──────────────────┐
  776. │┌───────────────┐ │
  777. ││ │ │
  778. ││ │ │
  779. ││ ⟦ Ok ⟧ │ │
  780. │└───────────────┘ │
  781. └──────────────────┘"
  782. )]
  783. [InlineData (
  784. 8,
  785. @"
  786. ┌──────────────────┐
  787. │┌───────────────┐ │
  788. ││ │ │
  789. ││ │ │
  790. ││ │ │
  791. ││ ⟦ Ok ⟧ │ │
  792. │└───────────────┘ │
  793. └──────────────────┘"
  794. )]
  795. [InlineData (
  796. 9,
  797. @"
  798. ┌──────────────────┐
  799. │┌───────────────┐ │
  800. ││ │ │
  801. ││ │ │
  802. ││ │ │
  803. ││ │ │
  804. ││ ⟦ Ok ⟧ │ │
  805. │└───────────────┘ │
  806. └──────────────────┘"
  807. )]
  808. public void Dialog_In_Window_Without_Size_One_Button_Aligns (int height, string expected)
  809. {
  810. ((FakeDriver)Driver).SetBufferSize (20, height);
  811. var win = new Window ();
  812. int iterations = -1;
  813. Iteration += (s, a) =>
  814. {
  815. iterations++;
  816. if (iterations == 0)
  817. {
  818. var dlg = new Dialog { Buttons = [new Button { Text = "Ok" }] };
  819. Run (dlg);
  820. }
  821. else if (iterations == 1)
  822. {
  823. // BUGBUG: This seems wrong; is it a bug in Dim.Percent(85)?? No
  824. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  825. }
  826. else
  827. {
  828. RequestStop ();
  829. }
  830. };
  831. Run (win);
  832. }
  833. [Fact]
  834. [AutoInitShutdown]
  835. public void Dialog_Opened_From_Another_Dialog ()
  836. {
  837. ((FakeDriver)Driver).SetBufferSize (30, 10);
  838. var btn1 = new Button { Text = "press me 1" };
  839. Button btn2 = null;
  840. Button btn3 = null;
  841. string expected = null;
  842. btn1.Accept += (s, e) =>
  843. {
  844. btn2 = new Button { Text = "Show Sub" };
  845. btn3 = new Button { Text = "Close" };
  846. btn3.Accept += (s, e) => RequestStop ();
  847. btn2.Accept += (s, e) =>
  848. {
  849. // Don't test MessageBox in Dialog unit tests!
  850. var subBtn = new Button { Text = "Ok", IsDefault = true };
  851. var subDlg = new Dialog { Text = "ya", Width = 20, Height = 5, Buttons = [subBtn] };
  852. subBtn.Accept += (s, e) => RequestStop (subDlg);
  853. Run (subDlg);
  854. };
  855. var dlg = new Dialog { Buttons = [btn2, btn3] };
  856. Run (dlg);
  857. };
  858. var btn =
  859. $"{
  860. CM.Glyphs.LeftBracket
  861. }{
  862. CM.Glyphs.LeftDefaultIndicator
  863. } Ok {
  864. CM.Glyphs.RightDefaultIndicator
  865. }{
  866. CM.Glyphs.RightBracket
  867. }";
  868. int iterations = -1;
  869. Iteration += (s, a) =>
  870. {
  871. iterations++;
  872. if (iterations == 0)
  873. {
  874. Assert.True (btn1.NewKeyDownEvent (Key.Space));
  875. }
  876. else if (iterations == 1)
  877. {
  878. expected = @$"
  879. ┌───────────────────────┐
  880. │ │
  881. │ │
  882. │ │
  883. │ │
  884. │ │
  885. │{
  886. CM.Glyphs.LeftBracket
  887. } Show Sub {
  888. CM.Glyphs.RightBracket
  889. } {
  890. CM.Glyphs.LeftBracket
  891. } Close {
  892. CM.Glyphs.RightBracket
  893. } │
  894. └───────────────────────┘";
  895. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  896. Assert.True (btn2.NewKeyDownEvent (Key.Space));
  897. }
  898. else if (iterations == 2)
  899. {
  900. TestHelpers.AssertDriverContentsWithFrameAre (
  901. @$"
  902. ┌───────────────────────┐
  903. │ ┌──────────────────┐ │
  904. │ │ya │ │
  905. │ │ │ │
  906. │ │ {
  907. btn
  908. } │ │
  909. │ └──────────────────┘ │
  910. │{
  911. CM.Glyphs.LeftBracket
  912. } Show Sub {
  913. CM.Glyphs.RightBracket
  914. } {
  915. CM.Glyphs.LeftBracket
  916. } Close {
  917. CM.Glyphs.RightBracket
  918. } │
  919. └───────────────────────┘",
  920. _output
  921. );
  922. Assert.True (Current.NewKeyDownEvent (Key.Enter));
  923. }
  924. else if (iterations == 3)
  925. {
  926. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  927. Assert.True (btn3.NewKeyDownEvent (Key.Space));
  928. }
  929. else if (iterations == 4)
  930. {
  931. TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
  932. RequestStop ();
  933. }
  934. };
  935. Run ();
  936. Shutdown ();
  937. Assert.Equal (4, iterations);
  938. }
  939. [Fact]
  940. [AutoInitShutdown]
  941. public void FileDialog_FileSystemWatcher ()
  942. {
  943. for (var i = 0; i < 8; i++)
  944. {
  945. var fd = new FileDialog ();
  946. fd.Ready += (s, e) => RequestStop ();
  947. Run (fd);
  948. }
  949. }
  950. [Fact]
  951. [AutoInitShutdown]
  952. public void Location_Default ()
  953. {
  954. var d = new Dialog ();
  955. Begin (d);
  956. ((FakeDriver)Driver).SetBufferSize (100, 100);
  957. // Default location is centered, so 100 / 2 - 85 / 2 = 7
  958. var expected = 7;
  959. Assert.Equal (new Point (expected, expected), (Point)d.Frame.Location);
  960. }
  961. [Fact]
  962. [AutoInitShutdown]
  963. public void Location_Not_Default ()
  964. {
  965. var d = new Dialog { X = 1, Y = 1 };
  966. Begin (d);
  967. ((FakeDriver)Driver).SetBufferSize (100, 100);
  968. // Default location is centered, so 100 / 2 - 85 / 2 = 7
  969. var expected = 1;
  970. Assert.Equal (new Point (expected, expected), (Point)d.Frame.Location);
  971. }
  972. [Fact]
  973. [AutoInitShutdown]
  974. public void Location_When_Application_Top_Not_Default ()
  975. {
  976. var expected = 5;
  977. var d = new Dialog { X = expected, Y = expected, Height = 5, Width = 5 };
  978. Begin (d);
  979. ((FakeDriver)Driver).SetBufferSize (20, 10);
  980. // Default location is centered, so 100 / 2 - 85 / 2 = 7
  981. Assert.Equal (new Point (expected, expected), (Point)d.Frame.Location);
  982. TestHelpers.AssertDriverContentsWithFrameAre (
  983. @"
  984. ┌───┐
  985. │ │
  986. │ │
  987. │ │
  988. └───┘",
  989. _output
  990. );
  991. }
  992. [Fact]
  993. [AutoInitShutdown]
  994. public void Location_When_Not_Application_Top_Not_Default ()
  995. {
  996. Top.BorderStyle = LineStyle.Double;
  997. int iterations = -1;
  998. Iteration += (s, a) =>
  999. {
  1000. iterations++;
  1001. if (iterations == 0)
  1002. {
  1003. var d = new Dialog { X = 5, Y = 5, Height = 3, Width = 5 };
  1004. Begin (d);
  1005. Assert.Equal (new Point (5, 5), (Point)d.Frame.Location);
  1006. TestHelpers.AssertDriverContentsWithFrameAre (
  1007. @"
  1008. ╔══════════════════╗
  1009. ║ ║
  1010. ║ ║
  1011. ║ ║
  1012. ║ ║
  1013. ║ ┌───┐ ║
  1014. ║ │ │ ║
  1015. ║ └───┘ ║
  1016. ║ ║
  1017. ╚══════════════════╝",
  1018. _output
  1019. );
  1020. d = new Dialog { X = 5, Y = 5 };
  1021. Begin (d);
  1022. // This is because of PostionTopLevels and EnsureVisibleBounds
  1023. Assert.Equal (new (3, 2), d.Frame.Location);
  1024. // #3127: Before
  1025. // Assert.Equal (new (17, 8), d.Frame.Size);
  1026. // TestHelpers.AssertDriverContentsWithFrameAre (@"
  1027. //╔══════════════════╗
  1028. //║ ║
  1029. //║ ┌───────────────┐
  1030. //║ │ │
  1031. //║ │ │
  1032. //║ │ │
  1033. //║ │ │
  1034. //║ │ │
  1035. //║ │ │
  1036. //╚══└───────────────┘", _output);
  1037. // #3127: After: Because Toplevel is now Width/Height = Dim.Filll
  1038. Assert.Equal (new (15, 6), d.Frame.Size);
  1039. TestHelpers.AssertDriverContentsWithFrameAre (
  1040. @"
  1041. ╔══════════════════╗
  1042. ║ ║
  1043. ║ ┌─────────────┐ ║
  1044. ║ │ │ ║
  1045. ║ │ │ ║
  1046. ║ │ │ ║
  1047. ║ │ │ ║
  1048. ║ └─────────────┘ ║
  1049. ║ ║
  1050. ╚══════════════════╝",
  1051. _output
  1052. );
  1053. }
  1054. else if (iterations > 0)
  1055. {
  1056. RequestStop ();
  1057. }
  1058. };
  1059. Begin (Top);
  1060. ((FakeDriver)Driver).SetBufferSize (20, 10);
  1061. Run ();
  1062. }
  1063. [Fact]
  1064. [AutoInitShutdown]
  1065. public void One_Button_Works ()
  1066. {
  1067. RunState runstate = null;
  1068. var d = (FakeDriver)Driver;
  1069. var title = "";
  1070. var btnText = "ok";
  1071. var buttonRow =
  1072. $"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket} {CM.Glyphs.VLine}";
  1073. int width = buttonRow.Length;
  1074. d.SetBufferSize (buttonRow.Length, 10);
  1075. (runstate, Dialog _) = RunButtonTestDialog (
  1076. title,
  1077. width,
  1078. Dialog.ButtonAlignments.Center,
  1079. new Button { Text = btnText }
  1080. );
  1081. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  1082. End (runstate);
  1083. }
  1084. [Fact]
  1085. [AutoInitShutdown]
  1086. public void Size_Default ()
  1087. {
  1088. var d = new Dialog ();
  1089. Begin (d);
  1090. ((FakeDriver)Driver).SetBufferSize (100, 100);
  1091. // Default size is Percent(85)
  1092. Assert.Equal (new ((int)(100 * .85), (int)(100 * .85)), d.Frame.Size);
  1093. }
  1094. [Fact]
  1095. [AutoInitShutdown]
  1096. public void Size_Not_Default ()
  1097. {
  1098. var d = new Dialog { Width = 50, Height = 50 };
  1099. Begin (d);
  1100. ((FakeDriver)Driver).SetBufferSize (100, 100);
  1101. // Default size is Percent(85)
  1102. Assert.Equal (new (50, 50), d.Frame.Size);
  1103. }
  1104. [Fact]
  1105. [AutoInitShutdown]
  1106. public void Zero_Buttons_Works ()
  1107. {
  1108. RunState runstate = null;
  1109. var d = (FakeDriver)Driver;
  1110. var title = "1234";
  1111. var buttonRow = $"{CM.Glyphs.VLine} {CM.Glyphs.VLine}";
  1112. int width = buttonRow.Length;
  1113. d.SetBufferSize (buttonRow.Length, 3);
  1114. (runstate, Dialog _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, null);
  1115. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
  1116. End (runstate);
  1117. }
  1118. private (RunState, Dialog) RunButtonTestDialog (
  1119. string title,
  1120. int width,
  1121. Dialog.ButtonAlignments align,
  1122. params Button [] btns
  1123. )
  1124. {
  1125. var dlg = new Dialog
  1126. {
  1127. Title = title,
  1128. X = 0,
  1129. Y = 0,
  1130. Width = width,
  1131. Height = 1,
  1132. ButtonAlignment = align,
  1133. Buttons = btns
  1134. };
  1135. // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
  1136. dlg.Border.Thickness = new Thickness (1, 0, 1, 0);
  1137. return (Begin (dlg), dlg);
  1138. }
  1139. [Fact]
  1140. [SetupFakeDriver]
  1141. [TestRespondersDisposed]
  1142. public void Run_Does_Not_Dispose_Dialog ()
  1143. {
  1144. Init ();
  1145. Dialog dlg = new ();
  1146. dlg.Ready += Dlg_Ready;
  1147. Run (dlg);
  1148. #if DEBUG_IDISPOSABLE
  1149. Assert.False (dlg.WasDisposed);
  1150. #endif
  1151. dlg.Dispose ();
  1152. Shutdown();
  1153. return;
  1154. void Dlg_Ready (object sender, EventArgs e)
  1155. {
  1156. RequestStop ();
  1157. }
  1158. }
  1159. }