BarTests.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using JetBrains.Annotations;
  2. namespace Terminal.Gui.ViewsTests;
  3. [TestSubject (typeof (Bar))]
  4. public class BarTests
  5. {
  6. [Fact]
  7. public void Constructor_Defaults ()
  8. {
  9. var bar = new Bar ();
  10. Assert.NotNull (bar);
  11. Assert.True (bar.CanFocus);
  12. Assert.IsType<DimAuto> (bar.Width);
  13. Assert.IsType<DimAuto> (bar.Height);
  14. // TOOD: more
  15. }
  16. [Fact]
  17. public void Constructor_InitializesEmpty_WhenNoShortcutsProvided ()
  18. {
  19. var bar = new Bar ();
  20. Assert.Empty (bar.Subviews);
  21. }
  22. [Fact]
  23. public void Constructor_InitializesWithShortcuts_WhenProvided ()
  24. {
  25. var shortcuts = new List<Shortcut>
  26. {
  27. new Shortcut(Key.Empty, "Command1", null, null),
  28. new Shortcut(Key.Empty, "Command2", null, null)
  29. };
  30. var bar = new Bar (shortcuts);
  31. Assert.Equal (shortcuts.Count, bar.Subviews.Count);
  32. for (int i = 0; i < shortcuts.Count; i++)
  33. {
  34. Assert.Same (shortcuts [i], bar.Subviews [i]);
  35. }
  36. }
  37. [Fact]
  38. public void OrientationProperty_SetsCorrectly ()
  39. {
  40. var bar = new Bar ();
  41. Assert.Equal (Orientation.Horizontal, bar.Orientation); // Default value
  42. bar.Orientation = Orientation.Vertical;
  43. Assert.Equal (Orientation.Vertical, bar.Orientation);
  44. }
  45. [Fact]
  46. public void AlignmentModesProperty_SetsCorrectly ()
  47. {
  48. var bar = new Bar ();
  49. Assert.Equal (AlignmentModes.StartToEnd, bar.AlignmentModes); // Default value
  50. bar.AlignmentModes = AlignmentModes.EndToStart;
  51. Assert.Equal (AlignmentModes.EndToStart, bar.AlignmentModes);
  52. }
  53. [Fact]
  54. public void AddShortcutAt_InsertsShortcutCorrectly ()
  55. {
  56. var bar = new Bar ();
  57. var shortcut = new Shortcut (Key.Empty, "Command", null, null);
  58. bar.AddShortcutAt (0, shortcut);
  59. Assert.Contains (shortcut, bar.Subviews);
  60. }
  61. [Fact]
  62. public void RemoveShortcut_RemovesShortcutCorrectly ()
  63. {
  64. var shortcut1 = new Shortcut (Key.Empty, "Command1", null, null);
  65. var shortcut2 = new Shortcut (Key.Empty, "Command2", null, null);
  66. var bar = new Bar (new List<Shortcut> { shortcut1, shortcut2 });
  67. var removedShortcut = bar.RemoveShortcut (0);
  68. Assert.Same (shortcut1, removedShortcut);
  69. Assert.DoesNotContain (shortcut1, bar.Subviews);
  70. Assert.Contains (shortcut2, bar.Subviews);
  71. }
  72. [Fact]
  73. public void Layout_ChangesBasedOnOrientation ()
  74. {
  75. var shortcut1 = new Shortcut (Key.Empty, "Command1", null, null);
  76. var shortcut2 = new Shortcut (Key.Empty, "Command2", null, null);
  77. var bar = new Bar (new List<Shortcut> { shortcut1, shortcut2 });
  78. bar.Orientation = Orientation.Horizontal;
  79. bar.LayoutSubviews ();
  80. // TODO: Assert specific layout expectations for horizontal orientation
  81. bar.Orientation = Orientation.Vertical;
  82. bar.LayoutSubviews ();
  83. // TODO: Assert specific layout expectations for vertical orientation
  84. }
  85. }