WindowTests.cs 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using UnitTests;
  2. using Xunit.Abstractions;
  3. namespace UnitTests.ViewsTests;
  4. public class WindowTests ()
  5. {
  6. [Fact]
  7. public void New_Initializes ()
  8. {
  9. // Parameterless
  10. using var defaultWindow = new Window ();
  11. defaultWindow.Layout ();
  12. Assert.NotNull (defaultWindow);
  13. Assert.Equal (string.Empty, defaultWindow.Title);
  14. // Toplevels have Width/Height set to Dim.Fill
  15. // If there's no SuperView, Top, or Driver, the default Fill width is int.MaxValue
  16. Assert.Equal ($"Window(){defaultWindow.Frame}", defaultWindow.ToString ());
  17. Assert.True (defaultWindow.CanFocus);
  18. Assert.False (defaultWindow.HasFocus);
  19. Assert.Equal (new Rectangle (0, 0, Application.Screen.Width - 2, Application.Screen.Height - 2), defaultWindow.Viewport);
  20. Assert.Equal (new Rectangle (0, 0, Application.Screen.Width, Application.Screen.Height), defaultWindow.Frame);
  21. Assert.Null (defaultWindow.Focused);
  22. Assert.NotNull (defaultWindow.GetScheme ());
  23. Assert.Equal (0, defaultWindow.X);
  24. Assert.Equal (0, defaultWindow.Y);
  25. Assert.Equal (Dim.Fill (), defaultWindow.Width);
  26. Assert.Equal (Dim.Fill (), defaultWindow.Height);
  27. Assert.False (defaultWindow.IsCurrentTop);
  28. Assert.Empty (defaultWindow.Id);
  29. Assert.False (defaultWindow.WantContinuousButtonPressed);
  30. Assert.False (defaultWindow.WantMousePositionReports);
  31. Assert.Null (defaultWindow.SuperView);
  32. Assert.Null (defaultWindow.MostFocused);
  33. Assert.Equal (TextDirection.LeftRight_TopBottom, defaultWindow.TextDirection);
  34. Assert.Equal (ViewArrangement.Overlapped, defaultWindow.Arrangement);
  35. // Empty Rect
  36. using var windowWithFrameRectEmpty = new Window { Frame = Rectangle.Empty, Title = "title" };
  37. windowWithFrameRectEmpty.Layout ();
  38. Assert.NotNull (windowWithFrameRectEmpty);
  39. Assert.Equal ("title", windowWithFrameRectEmpty.Title);
  40. Assert.True (windowWithFrameRectEmpty.CanFocus);
  41. Assert.False (windowWithFrameRectEmpty.HasFocus);
  42. Assert.Null (windowWithFrameRectEmpty.Focused);
  43. Assert.NotNull (windowWithFrameRectEmpty.GetScheme ());
  44. Assert.Equal (0, windowWithFrameRectEmpty.X);
  45. Assert.Equal (0, windowWithFrameRectEmpty.Y);
  46. Assert.Equal (0, windowWithFrameRectEmpty.Width);
  47. Assert.Equal (0, windowWithFrameRectEmpty.Height);
  48. Assert.False (windowWithFrameRectEmpty.IsCurrentTop);
  49. Assert.False (windowWithFrameRectEmpty.WantContinuousButtonPressed);
  50. Assert.False (windowWithFrameRectEmpty.WantMousePositionReports);
  51. Assert.Null (windowWithFrameRectEmpty.SuperView);
  52. Assert.Null (windowWithFrameRectEmpty.MostFocused);
  53. Assert.Equal (TextDirection.LeftRight_TopBottom, windowWithFrameRectEmpty.TextDirection);
  54. // Rect with values
  55. using var windowWithFrame1234 = new Window ();
  56. windowWithFrame1234.Frame = new (1, 2, 3, 4);
  57. windowWithFrame1234.Title = "title";
  58. Assert.Equal ("title", windowWithFrame1234.Title);
  59. Assert.NotNull (windowWithFrame1234);
  60. Assert.Equal ($"Window(){windowWithFrame1234.Frame}", windowWithFrame1234.ToString ());
  61. Assert.True (windowWithFrame1234.CanFocus);
  62. Assert.False (windowWithFrame1234.HasFocus);
  63. Assert.Equal (new (0, 0, 1, 2), windowWithFrame1234.Viewport);
  64. Assert.Equal (new (1, 2, 3, 4), windowWithFrame1234.Frame);
  65. Assert.Null (windowWithFrame1234.Focused);
  66. Assert.NotNull (windowWithFrame1234.GetScheme ());
  67. Assert.Equal (1, windowWithFrame1234.X);
  68. Assert.Equal (2, windowWithFrame1234.Y);
  69. Assert.Equal (3, windowWithFrame1234.Width);
  70. Assert.Equal (4, windowWithFrame1234.Height);
  71. Assert.False (windowWithFrame1234.IsCurrentTop);
  72. Assert.False (windowWithFrame1234.WantContinuousButtonPressed);
  73. Assert.False (windowWithFrame1234.WantMousePositionReports);
  74. Assert.Null (windowWithFrame1234.SuperView);
  75. Assert.Null (windowWithFrame1234.MostFocused);
  76. Assert.Equal (TextDirection.LeftRight_TopBottom, windowWithFrame1234.TextDirection);
  77. }
  78. }