| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using UnitTests;
- using Xunit.Abstractions;
- namespace ViewBaseTests.Mouse;
- public class HighlightStatesTests (ITestOutputHelper output)
- {
- [Fact]
- public void HighlightStates_SubView_With_Single_Runnable_WorkAsExpected ()
- {
- IApplication app = Application.Create ();
- app.Init ("fake");
- app.Driver?.SetScreenSize (6, 1);
- Attribute focus = new (ColorName16.White, ColorName16.Black, TextStyle.None);
- Attribute highlight = new (ColorName16.Blue, ColorName16.Black, TextStyle.Italic);
- Runnable superview = new () { Width = Dim.Fill (), Height = Dim.Fill () };
- superview.SetScheme (new () { Focus = focus, Highlight = highlight });
- View view = new () { Width = Dim.Fill (), Height = Dim.Fill (), Text = "| Hi |", HighlightStates = MouseState.In };
- superview.Add (view);
- app.Begin (superview);
- for (var i = 0; i < app.Driver?.Cols; i++)
- {
- Assert.Equal (focus, app.Driver.Contents? [0, i].Attribute);
- }
- DriverAssert.AssertDriverContentsAre ("| Hi |", output, app.Driver);
- app.Mouse.RaiseMouseEvent (new () { ScreenPosition = new (2, 0), Flags = MouseFlags.ReportMousePosition });
- app.LayoutAndDraw ();
- for (var i = 0; i < app.Driver?.Cols; i++)
- {
- Assert.Equal (highlight, app.Driver.Contents? [0, i].Attribute);
- }
- DriverAssert.AssertDriverContentsAre ("| Hi |", output, app.Driver);
- app.Dispose ();
- }
- [Fact]
- public void HighlightStates_SubView_With_Multiple_Runnable_WorkAsExpected ()
- {
- IApplication app = Application.Create ();
- app.Init ("fake");
- app.Driver?.SetScreenSize (9, 5);
- Attribute focus = new (ColorName16.White, ColorName16.Black, TextStyle.None);
- Attribute highlight = new (ColorName16.Blue, ColorName16.Black, TextStyle.Italic);
- Runnable superview = new () { Width = Dim.Fill (), Height = Dim.Fill () };
- superview.SetScheme (new () { Focus = focus, Highlight = highlight });
- View view = new () { Width = Dim.Fill (), Height = Dim.Fill (), Text = "| Hi |", HighlightStates = MouseState.In };
- superview.Add (view);
- app.Begin (superview);
- Attribute normal = new (ColorName16.Green, ColorName16.Magenta, TextStyle.None);
- Attribute highlight2 = new (ColorName16.Red, ColorName16.Yellow, TextStyle.Italic);
- Runnable modalSuperview = new () { Y = 1, Width = 9, Height = 4, BorderStyle = LineStyle.Single };
- modalSuperview.SetScheme (new () { Normal = normal, Highlight = highlight2 });
- View view2 = new () { Width = Dim.Fill (), Height = Dim.Fill (), Text = "| Hey |", HighlightStates = MouseState.In };
- modalSuperview.Add (view2);
- app.Begin (modalSuperview);
- for (var i = 0; i < app.Driver?.Cols; i++)
- {
- Assert.Equal (focus, app.Driver.Contents? [0, i].Attribute);
- }
- for (var i = 0; i < app.Driver?.Cols; i++)
- {
- Assert.Equal (normal, app.Driver.Contents? [2, i].Attribute);
- }
- DriverAssert.AssertDriverContentsAre ("""
- | Hi |
- ┌───────┐
- │| Hey |│
- │ │
- └───────┘
- """
- , output, app.Driver);
- app.Mouse.RaiseMouseEvent (new () { ScreenPosition = new (2, 2), Flags = MouseFlags.ReportMousePosition });
- app.LayoutAndDraw ();
- for (var i = 0; i < app.Driver?.Cols; i++)
- {
- Assert.Equal (focus, app.Driver.Contents? [0, i].Attribute);
- }
- for (var i = 1; i < app.Driver?.Cols - 1; i++)
- {
- Assert.Equal (highlight2, app.Driver?.Contents? [2, i].Attribute);
- }
- DriverAssert.AssertDriverContentsAre ("""
- | Hi |
- ┌───────┐
- │| Hey |│
- │ │
- └───────┘
- """,
- output, app.Driver);
- app.Dispose ();
- }
- }
|