WizardStepTests.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. namespace ViewsTests;
  2. [Collection ("Global Test Setup")]
  3. public class WizardStepTests
  4. {
  5. #region Constructor Tests
  6. [Fact]
  7. public void Constructor_Initializes_Properties ()
  8. {
  9. // Arrange & Act
  10. WizardStep step = new ();
  11. // Assert
  12. Assert.NotNull (step);
  13. Assert.True (step.CanFocus);
  14. Assert.Equal (TabBehavior.TabStop, step.TabStop);
  15. Assert.Equal (LineStyle.None, step.BorderStyle);
  16. Assert.IsType<DimFill> (step.Width);
  17. Assert.IsType<DimFill> (step.Height);
  18. }
  19. [Fact]
  20. public void Constructor_Sets_Default_Button_Text ()
  21. {
  22. // Arrange & Act
  23. WizardStep step = new ();
  24. // Assert
  25. Assert.Equal (string.Empty, step.BackButtonText);
  26. Assert.Equal (string.Empty, step.NextButtonText);
  27. }
  28. #endregion Constructor Tests
  29. #region Title Tests
  30. [Fact]
  31. public void Title_Can_Be_Set ()
  32. {
  33. // Arrange
  34. WizardStep step = new ();
  35. string title = "Test Step";
  36. // Act
  37. step.Title = title;
  38. // Assert
  39. Assert.Equal (title, step.Title);
  40. }
  41. [Fact]
  42. public void Title_Change_Raises_TitleChanged_Event ()
  43. {
  44. // Arrange
  45. WizardStep step = new ();
  46. var eventRaised = false;
  47. string? newTitle = null;
  48. step.TitleChanged += (sender, args) =>
  49. {
  50. eventRaised = true;
  51. newTitle = args.Value;
  52. };
  53. // Act
  54. step.Title = "New Title";
  55. // Assert
  56. Assert.True (eventRaised);
  57. Assert.Equal ("New Title", newTitle);
  58. }
  59. #endregion Title Tests
  60. #region HelpText Tests
  61. [Fact]
  62. public void HelpText_Can_Be_Set ()
  63. {
  64. // Arrange
  65. WizardStep step = new ();
  66. string helpText = "This is help text";
  67. // Act
  68. step.HelpText = helpText;
  69. // Assert
  70. Assert.Equal (helpText, step.HelpText);
  71. }
  72. [Fact]
  73. public void HelpText_Empty_By_Default ()
  74. {
  75. // Arrange & Act
  76. WizardStep step = new ();
  77. // Assert
  78. Assert.Equal (string.Empty, step.HelpText);
  79. }
  80. [Fact]
  81. public void HelpText_Setting_Calls_ShowHide ()
  82. {
  83. // Arrange
  84. WizardStep step = new ();
  85. step.BeginInit ();
  86. step.EndInit ();
  87. // Act - Setting help text should adjust padding
  88. step.HelpText = "Help text content";
  89. // Assert - Padding should have right thickness when help text is present
  90. Assert.True (step.Padding!.Thickness.Right > 0);
  91. }
  92. [Fact]
  93. public void HelpText_Clearing_Removes_Padding ()
  94. {
  95. // Arrange
  96. WizardStep step = new ();
  97. step.BeginInit ();
  98. step.EndInit ();
  99. step.HelpText = "Help text content";
  100. // Act - Clear help text
  101. step.HelpText = string.Empty;
  102. // Assert - Padding right should be 0 when help text is empty
  103. Assert.Equal (0, step.Padding!.Thickness.Right);
  104. }
  105. #endregion HelpText Tests
  106. #region BackButtonText Tests
  107. [Fact]
  108. public void BackButtonText_Can_Be_Set ()
  109. {
  110. // Arrange
  111. WizardStep step = new ();
  112. string buttonText = "Previous";
  113. // Act
  114. step.BackButtonText = buttonText;
  115. // Assert
  116. Assert.Equal (buttonText, step.BackButtonText);
  117. }
  118. [Fact]
  119. public void BackButtonText_Empty_By_Default ()
  120. {
  121. // Arrange & Act
  122. WizardStep step = new ();
  123. // Assert
  124. Assert.Equal (string.Empty, step.BackButtonText);
  125. }
  126. #endregion BackButtonText Tests
  127. #region NextButtonText Tests
  128. [Fact]
  129. public void NextButtonText_Can_Be_Set ()
  130. {
  131. // Arrange
  132. WizardStep step = new ();
  133. string buttonText = "Continue";
  134. // Act
  135. step.NextButtonText = buttonText;
  136. // Assert
  137. Assert.Equal (buttonText, step.NextButtonText);
  138. }
  139. [Fact]
  140. public void NextButtonText_Empty_By_Default ()
  141. {
  142. // Arrange & Act
  143. WizardStep step = new ();
  144. // Assert
  145. Assert.Equal (string.Empty, step.NextButtonText);
  146. }
  147. #endregion NextButtonText Tests
  148. #region SubView Tests
  149. [Fact]
  150. public void Can_Add_SubViews ()
  151. {
  152. // Arrange
  153. WizardStep step = new ();
  154. Label label = new () { Text = "Test Label" };
  155. // Act
  156. step.Add (label);
  157. // Assert
  158. Assert.Contains (label, step.SubViews);
  159. }
  160. [Fact]
  161. public void Can_Add_Multiple_SubViews ()
  162. {
  163. // Arrange
  164. WizardStep step = new ();
  165. Label label1 = new () { Text = "Label 1" };
  166. Label label2 = new () { Text = "Label 2" };
  167. TextField textField = new () { Width = 10 };
  168. // Act
  169. step.Add (label1, label2, textField);
  170. // Assert
  171. Assert.Equal (3, step.SubViews.Count);
  172. Assert.Contains (label1, step.SubViews);
  173. Assert.Contains (label2, step.SubViews);
  174. Assert.Contains (textField, step.SubViews);
  175. }
  176. #endregion SubView Tests
  177. #region Enabled Tests
  178. [Fact]
  179. public void Enabled_True_By_Default ()
  180. {
  181. // Arrange & Act
  182. WizardStep step = new ();
  183. // Assert
  184. Assert.True (step.Enabled);
  185. }
  186. [Fact]
  187. public void Enabled_Can_Be_Set_To_False ()
  188. {
  189. // Arrange
  190. WizardStep step = new ();
  191. // Act
  192. step.Enabled = false;
  193. // Assert
  194. Assert.False (step.Enabled);
  195. }
  196. [Fact]
  197. public void Enabled_Change_Raises_EnabledChanged_Event ()
  198. {
  199. // Arrange
  200. WizardStep step = new ();
  201. var eventRaised = false;
  202. step.EnabledChanged += (sender, args) => { eventRaised = true; };
  203. // Act
  204. step.Enabled = false;
  205. // Assert
  206. Assert.True (eventRaised);
  207. }
  208. #endregion Enabled Tests
  209. #region Visible Tests
  210. [Fact]
  211. public void Visible_True_By_Default ()
  212. {
  213. // Arrange & Act
  214. WizardStep step = new ();
  215. // Assert
  216. Assert.True (step.Visible);
  217. }
  218. [Fact]
  219. public void Visible_Can_Be_Changed ()
  220. {
  221. // Arrange
  222. WizardStep step = new ();
  223. // Act
  224. step.Visible = false;
  225. // Assert
  226. Assert.False (step.Visible);
  227. }
  228. #endregion Visible Tests
  229. #region HelpTextView Tests
  230. [Fact]
  231. public void HelpTextView_Added_To_Padding ()
  232. {
  233. // Arrange
  234. WizardStep step = new ();
  235. step.BeginInit ();
  236. step.EndInit ();
  237. // Act
  238. step.HelpText = "Help content";
  239. // Assert
  240. // The help text view should be in the Padding
  241. Assert.True (step.Padding!.SubViews.Count > 0);
  242. }
  243. [Fact]
  244. public void HelpTextView_Visible_When_HelpText_Set ()
  245. {
  246. // Arrange
  247. WizardStep step = new ();
  248. step.BeginInit ();
  249. step.EndInit ();
  250. // Act
  251. step.HelpText = "Help content";
  252. // Assert
  253. // When help text is set, padding right should be non-zero
  254. Assert.True (step.Padding!.Thickness.Right > 0);
  255. }
  256. [Fact]
  257. public void HelpTextView_Hidden_When_HelpText_Empty ()
  258. {
  259. // Arrange
  260. WizardStep step = new ();
  261. step.BeginInit ();
  262. step.EndInit ();
  263. step.HelpText = "Help content";
  264. // Act
  265. step.HelpText = string.Empty;
  266. // Assert
  267. // When help text is cleared, padding right should be 0
  268. Assert.Equal (0, step.Padding!.Thickness.Right);
  269. }
  270. #endregion HelpTextView Tests
  271. #region Layout Tests
  272. [Fact]
  273. public void Width_Is_Fill_After_Construction ()
  274. {
  275. // Arrange & Act
  276. WizardStep step = new ();
  277. // Assert
  278. Assert.IsType<DimFill> (step.Width);
  279. }
  280. [Fact]
  281. public void Height_Is_Fill_After_Construction ()
  282. {
  283. // Arrange & Act
  284. WizardStep step = new ();
  285. // Assert
  286. Assert.IsType<DimFill> (step.Height);
  287. }
  288. #endregion Layout Tests
  289. #region Focus Tests
  290. [Fact]
  291. public void CanFocus_True_By_Default ()
  292. {
  293. // Arrange & Act
  294. WizardStep step = new ();
  295. // Assert
  296. Assert.True (step.CanFocus);
  297. }
  298. [Fact]
  299. public void TabStop_Is_TabStop_By_Default ()
  300. {
  301. // Arrange & Act
  302. WizardStep step = new ();
  303. // Assert
  304. Assert.Equal (TabBehavior.TabStop, step.TabStop);
  305. }
  306. #endregion Focus Tests
  307. #region BorderStyle Tests
  308. [Fact]
  309. public void BorderStyle_Can_Be_Changed ()
  310. {
  311. // Arrange
  312. WizardStep step = new ();
  313. // Act
  314. step.BorderStyle = LineStyle.Single;
  315. // Assert
  316. Assert.Equal (LineStyle.Single, step.BorderStyle);
  317. }
  318. #endregion BorderStyle Tests
  319. #region Integration Tests
  320. [Fact]
  321. public void Step_With_HelpText_And_SubViews ()
  322. {
  323. // Arrange
  324. WizardStep step = new ()
  325. {
  326. Title = "User Information",
  327. HelpText = "Please enter your details"
  328. };
  329. Label nameLabel = new () { Text = "Name:" };
  330. TextField nameField = new () { X = Pos.Right (nameLabel) + 1, Width = 20 };
  331. step.Add (nameLabel, nameField);
  332. step.BeginInit ();
  333. step.EndInit ();
  334. // Assert
  335. Assert.Equal ("User Information", step.Title);
  336. Assert.Equal ("Please enter your details", step.HelpText);
  337. // SubViews includes the views we added
  338. Assert.Contains (nameLabel, step.SubViews);
  339. Assert.Contains (nameField, step.SubViews);
  340. Assert.True (step.Padding!.Thickness.Right > 0);
  341. }
  342. [Fact]
  343. public void Step_With_Custom_Button_Text ()
  344. {
  345. // Arrange & Act
  346. WizardStep step = new ()
  347. {
  348. Title = "Confirmation",
  349. BackButtonText = "Go Back",
  350. NextButtonText = "Accept"
  351. };
  352. // Assert
  353. Assert.Equal ("Confirmation", step.Title);
  354. Assert.Equal ("Go Back", step.BackButtonText);
  355. Assert.Equal ("Accept", step.NextButtonText);
  356. }
  357. [Fact]
  358. public void Disabled_Step_Maintains_Properties ()
  359. {
  360. // Arrange
  361. WizardStep step = new ()
  362. {
  363. Title = "Optional Step",
  364. HelpText = "This step is optional",
  365. Enabled = false
  366. };
  367. // Assert
  368. Assert.Equal ("Optional Step", step.Title);
  369. Assert.Equal ("This step is optional", step.HelpText);
  370. Assert.False (step.Enabled);
  371. }
  372. #endregion Integration Tests
  373. }