MarginTests.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #nullable enable
  2. using UnitTests;
  3. using Xunit.Abstractions;
  4. namespace ViewBaseTests.Adornments;
  5. public class MarginTests (ITestOutputHelper output)
  6. {
  7. [Fact]
  8. public void Margin_Is_Transparent ()
  9. {
  10. IApplication? app = Application.Create ();
  11. app.Init ("fake");
  12. app.Driver!.SetScreenSize (5, 5);
  13. var view = new View { Height = 3, Width = 3 };
  14. view.Margin!.Diagnostics = ViewDiagnosticFlags.Thickness;
  15. view.Margin.Thickness = new (1);
  16. Runnable<bool> runnable = new ();
  17. app.Begin (runnable);
  18. runnable.SetScheme (new ()
  19. {
  20. Normal = new (Color.Red, Color.Green), Focus = new (Color.Green, Color.Red)
  21. });
  22. runnable.Add (view);
  23. Assert.Equal (ColorName16.Red, view.Margin.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ());
  24. Assert.Equal (ColorName16.Red, runnable.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ());
  25. app.LayoutAndDraw ();
  26. DriverAssert.AssertDriverContentsAre (
  27. @"",
  28. output,
  29. app.Driver
  30. );
  31. DriverAssert.AssertDriverAttributesAre ("0", output, app.Driver, runnable.GetAttributeForRole (VisualRole.Normal));
  32. }
  33. [Fact]
  34. public void Margin_ViewPortSettings_Not_Transparent_Is_NotTransparent ()
  35. {
  36. IApplication? app = Application.Create ();
  37. app.Init ("fake");
  38. app.Driver!.SetScreenSize (5, 5);
  39. var view = new View { Height = 3, Width = 3 };
  40. view.Margin!.Diagnostics = ViewDiagnosticFlags.Thickness;
  41. view.Margin.Thickness = new (1);
  42. view.Margin.ViewportSettings = ViewportSettingsFlags.None;
  43. Runnable<bool> runnable = new ();
  44. app.Begin (runnable);
  45. runnable.SetScheme (new ()
  46. {
  47. Normal = new (Color.Red, Color.Green), Focus = new (Color.Green, Color.Red)
  48. });
  49. runnable.Add (view);
  50. Assert.Equal (ColorName16.Red, view.Margin.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ());
  51. Assert.Equal (ColorName16.Red, runnable.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ());
  52. app.LayoutAndDraw ();
  53. DriverAssert.AssertDriverContentsAre (
  54. @"
  55. MMM
  56. M M
  57. MMM",
  58. output,
  59. app.Driver
  60. );
  61. DriverAssert.AssertDriverAttributesAre ("0", output, app.Driver, runnable.GetAttributeForRole (VisualRole.Normal));
  62. }
  63. [Fact]
  64. public void Is_Visually_Transparent ()
  65. {
  66. var view = new View { Height = 3, Width = 3 };
  67. Assert.True(view.Margin!.ViewportSettings.HasFlag(ViewportSettingsFlags.Transparent), "Margin should be transparent by default.");
  68. }
  69. [Fact]
  70. public void Is_Transparent_To_Mouse ()
  71. {
  72. var view = new View { Height = 3, Width = 3 };
  73. Assert.True (view.Margin!.ViewportSettings.HasFlag (ViewportSettingsFlags.TransparentMouse), "Margin should be transparent to mouse by default.");
  74. }
  75. [Fact]
  76. public void When_Not_Visually_Transparent ()
  77. {
  78. var view = new View { Height = 3, Width = 3 };
  79. // Give the Margin some size
  80. view.Margin!.Thickness = new Thickness (1, 1, 1, 1);
  81. // Give it Text
  82. view.Margin!.Text = "Test";
  83. // Strip off ViewportSettings.Transparent
  84. view.Margin!.ViewportSettings &= ~ViewportSettingsFlags.Transparent;
  85. //
  86. }
  87. [Fact]
  88. public void Thickness_Is_Empty_By_Default ()
  89. {
  90. var view = new View { Height = 3, Width = 3 };
  91. Assert.Equal (Thickness.Empty, view.Margin!.Thickness);
  92. }
  93. // ShadowStyle
  94. [Fact]
  95. public void Margin_Uses_ShadowStyle_Transparent ()
  96. {
  97. var view = new View { Height = 3, Width = 3, ShadowStyle = ShadowStyle.Transparent };
  98. Assert.Equal (ShadowStyle.Transparent, view.Margin!.ShadowStyle);
  99. Assert.True (view.Margin!.ViewportSettings.HasFlag (ViewportSettingsFlags.TransparentMouse), "Margin should be transparent to mouse when ShadowStyle is Transparent.");
  100. Assert.True (view.Margin!.ViewportSettings.HasFlag (ViewportSettingsFlags.Transparent), "Margin should be transparent when ShadowStyle is Transparent..");
  101. }
  102. [Fact]
  103. public void Margin_Uses_ShadowStyle_Opaque ()
  104. {
  105. var view = new View { Height = 3, Width = 3, ShadowStyle = ShadowStyle.Opaque };
  106. Assert.Equal (ShadowStyle.Opaque, view.Margin!.ShadowStyle);
  107. Assert.True (view.Margin!.ViewportSettings.HasFlag (ViewportSettingsFlags.TransparentMouse), "Margin should be transparent to mouse when ShadowStyle is Opaque.");
  108. Assert.True (view.Margin!.ViewportSettings.HasFlag (ViewportSettingsFlags.Transparent), "Margin should be transparent when ShadowStyle is Opaque..");
  109. }
  110. }