DialogTests.cs 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334
  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. }