HighlightStatesTests.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using UnitTests;
  2. using Xunit.Abstractions;
  3. namespace ViewBaseTests.Mouse;
  4. public class HighlightStatesTests (ITestOutputHelper output)
  5. {
  6. [Fact]
  7. public void HighlightStates_SubView_With_Single_Runnable_WorkAsExpected ()
  8. {
  9. IApplication app = Application.Create ();
  10. app.Init ("fake");
  11. app.Driver?.SetScreenSize (6, 1);
  12. Attribute focus = new (ColorName16.White, ColorName16.Black, TextStyle.None);
  13. Attribute highlight = new (ColorName16.Blue, ColorName16.Black, TextStyle.Italic);
  14. Runnable superview = new () { Width = Dim.Fill (), Height = Dim.Fill () };
  15. superview.SetScheme (new () { Focus = focus, Highlight = highlight });
  16. View view = new () { Width = Dim.Fill (), Height = Dim.Fill (), Text = "| Hi |", HighlightStates = MouseState.In };
  17. superview.Add (view);
  18. app.Begin (superview);
  19. for (var i = 0; i < app.Driver?.Cols; i++)
  20. {
  21. Assert.Equal (focus, app.Driver.Contents? [0, i].Attribute);
  22. }
  23. DriverAssert.AssertDriverContentsAre ("| Hi |", output, app.Driver);
  24. app.Mouse.RaiseMouseEvent (new () { ScreenPosition = new (2, 0), Flags = MouseFlags.ReportMousePosition });
  25. app.LayoutAndDraw ();
  26. for (var i = 0; i < app.Driver?.Cols; i++)
  27. {
  28. Assert.Equal (highlight, app.Driver.Contents? [0, i].Attribute);
  29. }
  30. DriverAssert.AssertDriverContentsAre ("| Hi |", output, app.Driver);
  31. app.Dispose ();
  32. }
  33. [Fact]
  34. public void HighlightStates_SubView_With_Multiple_Runnable_WorkAsExpected ()
  35. {
  36. IApplication app = Application.Create ();
  37. app.Init ("fake");
  38. app.Driver?.SetScreenSize (9, 5);
  39. Attribute focus = new (ColorName16.White, ColorName16.Black, TextStyle.None);
  40. Attribute highlight = new (ColorName16.Blue, ColorName16.Black, TextStyle.Italic);
  41. Runnable superview = new () { Width = Dim.Fill (), Height = Dim.Fill () };
  42. superview.SetScheme (new () { Focus = focus, Highlight = highlight });
  43. View view = new () { Width = Dim.Fill (), Height = Dim.Fill (), Text = "| Hi |", HighlightStates = MouseState.In };
  44. superview.Add (view);
  45. app.Begin (superview);
  46. Attribute normal = new (ColorName16.Green, ColorName16.Magenta, TextStyle.None);
  47. Attribute highlight2 = new (ColorName16.Red, ColorName16.Yellow, TextStyle.Italic);
  48. Runnable modalSuperview = new () { Y = 1, Width = 9, Height = 4, BorderStyle = LineStyle.Single };
  49. modalSuperview.SetScheme (new () { Normal = normal, Highlight = highlight2 });
  50. View view2 = new () { Width = Dim.Fill (), Height = Dim.Fill (), Text = "| Hey |", HighlightStates = MouseState.In };
  51. modalSuperview.Add (view2);
  52. app.Begin (modalSuperview);
  53. for (var i = 0; i < app.Driver?.Cols; i++)
  54. {
  55. Assert.Equal (focus, app.Driver.Contents? [0, i].Attribute);
  56. }
  57. for (var i = 0; i < app.Driver?.Cols; i++)
  58. {
  59. Assert.Equal (normal, app.Driver.Contents? [2, i].Attribute);
  60. }
  61. DriverAssert.AssertDriverContentsAre ("""
  62. | Hi |
  63. ┌───────┐
  64. │| Hey |│
  65. │ │
  66. └───────┘
  67. """
  68. , output, app.Driver);
  69. app.Mouse.RaiseMouseEvent (new () { ScreenPosition = new (2, 2), Flags = MouseFlags.ReportMousePosition });
  70. app.LayoutAndDraw ();
  71. for (var i = 0; i < app.Driver?.Cols; i++)
  72. {
  73. Assert.Equal (focus, app.Driver.Contents? [0, i].Attribute);
  74. }
  75. for (var i = 1; i < app.Driver?.Cols - 1; i++)
  76. {
  77. Assert.Equal (highlight2, app.Driver?.Contents? [2, i].Attribute);
  78. }
  79. DriverAssert.AssertDriverContentsAre ("""
  80. | Hi |
  81. ┌───────┐
  82. │| Hey |│
  83. │ │
  84. └───────┘
  85. """,
  86. output, app.Driver);
  87. app.Dispose ();
  88. }
  89. }