TitleTests.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System.Text;
  2. using Xunit.Abstractions;
  3. //using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
  4. // Alias Console to MockConsole so we don't accidentally use Console
  5. namespace Terminal.Gui.ViewTests;
  6. public class TitleTests
  7. {
  8. private readonly ITestOutputHelper _output;
  9. public TitleTests (ITestOutputHelper output) { this._output = output; }
  10. [Fact]
  11. public void Set_Title_Fires_TitleChanged ()
  12. {
  13. var r = new View ();
  14. Assert.Equal (string.Empty, r.Title);
  15. string expectedOld = null;
  16. string expected = null;
  17. r.TitleChanged += (s, args) =>
  18. {
  19. Assert.Equal (expectedOld, args.OldValue);
  20. Assert.Equal (r.Title, args.NewValue);
  21. };
  22. expected = "title";
  23. expectedOld = r.Title;
  24. r.Title = expected;
  25. Assert.Equal (expected, r.Title);
  26. r.Dispose ();
  27. }
  28. [Fact]
  29. public void Set_Title_Fires_TitleChanging ()
  30. {
  31. var r = new View ();
  32. Assert.Equal (string.Empty, r.Title);
  33. string expectedOld = null;
  34. string expectedDuring = null;
  35. string expectedAfter = null;
  36. var cancel = false;
  37. r.TitleChanging += (s, args) =>
  38. {
  39. Assert.Equal (expectedOld, args.OldValue);
  40. Assert.Equal (expectedDuring, args.NewValue);
  41. args.Cancel = cancel;
  42. };
  43. expectedOld = string.Empty;
  44. r.Title = expectedDuring = expectedAfter = "title";
  45. Assert.Equal (expectedAfter, r.Title);
  46. expectedOld = r.Title;
  47. r.Title = expectedDuring = expectedAfter = "a different title";
  48. Assert.Equal (expectedAfter, r.Title);
  49. // Now setup cancelling the change and change it back to "title"
  50. cancel = true;
  51. expectedOld = r.Title;
  52. r.Title = expectedDuring = "title";
  53. Assert.Equal (expectedAfter, r.Title);
  54. r.Dispose ();
  55. }
  56. // Setting Text does NOT set the HotKey
  57. [Fact]
  58. public void Title_Does_Set_HotKey ()
  59. {
  60. var view = new View { HotKeySpecifier = (Rune)'_', Title = "_Hello World" };
  61. Assert.Equal (Key.H, view.HotKey);
  62. }
  63. [SetupFakeDriver]
  64. [Fact]
  65. public void Change_View_Size_Update_Title_Size ()
  66. {
  67. var view = new View { Title = "_Hello World", Width = Dim.Auto (), Height = Dim.Auto (), BorderStyle = LineStyle.Single};
  68. var top = new Toplevel ();
  69. top.Add (view);
  70. Application.Begin (top);
  71. Assert.Equal (string.Empty, view.Text);
  72. Assert.Equal (new (2, 2), view.Frame.Size);
  73. TestHelpers.AssertDriverContentsWithFrameAre (@"
  74. ┌┐
  75. └┘", _output);
  76. var text = "This text will increment the view size and display the title.";
  77. view.Text = text;
  78. top.Draw ();
  79. Assert.Equal (text, view.Text);
  80. // SetupFakeDriver only create a screen with 25 cols and 25 rows
  81. Assert.Equal (new (25, 3), view.Frame.Size);
  82. TestHelpers.AssertDriverContentsWithFrameAre (@"
  83. ┌┤Hello World├──────────┐
  84. │This text will incremen│
  85. └───────────────────────┘", _output);
  86. top.Dispose ();
  87. }
  88. }