| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667 |
- namespace ViewBaseTests.Mouse;
- /// <summary>
- /// Parallelizable tests for mouse drag functionality on movable and resizable views.
- /// These tests validate mouse drag behavior without Application.Init or global state.
- /// </summary>
- [Trait ("Category", "Input")]
- public class MouseDragTests
- {
- #region Movable View Drag Tests
- [Fact]
- public void MovableView_MouseDrag_UpdatesPosition ()
- {
- // Arrange
- using IApplication app = Application.Create ();
- app.Init ("fake");
- View superView = new ()
- {
- Width = 50,
- Height = 50,
- App = app
- };
- View movableView = new ()
- {
- X = 10,
- Y = 10,
- Width = 10,
- Height = 10,
- Arrangement = ViewArrangement.Movable,
- BorderStyle = LineStyle.Single,
- App = app
- };
- superView.Add (movableView);
- // Add to a runnable so the views are part of the application
- var runnable = new Runnable { App = app, Frame = new (0, 0, 80, 25) };
- runnable.Add (superView);
- app.Begin (runnable);
- // Simulate mouse press on border to start drag
- MouseEventArgs pressEvent = new ()
- {
- ScreenPosition = new (10, 10), // Screen position
- Flags = MouseFlags.Button1Pressed
- };
- // Act - Start drag
- app.Mouse.RaiseMouseEvent (pressEvent);
- // Simulate mouse drag
- MouseEventArgs dragEvent = new ()
- {
- ScreenPosition = new (15, 15), // New screen position
- Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
- };
- app.Mouse.RaiseMouseEvent (dragEvent);
- // Assert - View should have moved
- Assert.Equal (15, movableView.Frame.X);
- Assert.Equal (15, movableView.Frame.Y);
- Assert.Equal (10, movableView.Frame.Width);
- Assert.Equal (10, movableView.Frame.Height);
- app.End (app.SessionStack!.First ());
- runnable.Dispose ();
- superView.Dispose ();
- }
- [Fact]
- public void MovableView_MouseDrag_WithSuperview_UsesCorrectCoordinates ()
- {
- // Arrange
- using IApplication app = Application.Create ();
- app.Init ("fake");
- View superView = new ()
- {
- X = 5,
- Y = 5,
- Width = 50,
- Height = 50
- };
- View movableView = new ()
- {
- X = 10,
- Y = 10,
- Width = 10,
- Height = 10,
- Arrangement = ViewArrangement.Movable,
- BorderStyle = LineStyle.Single
- };
- superView.Add (movableView);
- // Add to a runnable so the views are part of the application
- var runnable = new Runnable { App = app, Frame = new (0, 0, 80, 25) };
- runnable.Add (superView);
- app.Begin (runnable);
- // Simulate mouse press on border
- MouseEventArgs pressEvent = new ()
- {
- ScreenPosition = new (15, 15), // 5+10 offset
- Flags = MouseFlags.Button1Pressed
- };
- app.Mouse.RaiseMouseEvent (pressEvent);
- // Simulate mouse drag
- MouseEventArgs dragEvent = new ()
- {
- ScreenPosition = new (18, 18), // Moved 3,3
- Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
- };
- app.Mouse.RaiseMouseEvent (dragEvent);
- // Assert - View should have moved relative to superview
- Assert.Equal (13, movableView.Frame.X); // 10 + 3
- Assert.Equal (13, movableView.Frame.Y); // 10 + 3
- app.End (app.SessionStack!.First ());
- runnable.Dispose ();
- superView.Dispose ();
- }
- [Fact]
- public void MovableView_MouseRelease_StopsDrag ()
- {
- // Arrange
- using IApplication app = Application.Create ();
- app.Init ("fake");
- View superView = new ()
- {
- Width = 50,
- Height = 50
- };
- View movableView = new ()
- {
- X = 10,
- Y = 10,
- Width = 10,
- Height = 10,
- Arrangement = ViewArrangement.Movable,
- BorderStyle = LineStyle.Single
- };
- superView.Add (movableView);
- // Add to a runnable so the views are part of the application
- var runnable = new Runnable { App = app, Frame = new (0, 0, 80, 25) };
- runnable.Add (superView);
- app.Begin (runnable);
- // Start drag
- MouseEventArgs pressEvent = new ()
- {
- ScreenPosition = new (10, 10),
- Flags = MouseFlags.Button1Pressed
- };
- app.Mouse.RaiseMouseEvent (pressEvent);
- // Drag
- MouseEventArgs dragEvent = new ()
- {
- ScreenPosition = new (15, 15),
- Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
- };
- app.Mouse.RaiseMouseEvent (dragEvent);
- // Release
- MouseEventArgs releaseEvent = new ()
- {
- ScreenPosition = new (15, 15),
- Flags = MouseFlags.Button1Released
- };
- app.Mouse.RaiseMouseEvent (releaseEvent);
- // Assert - Position should remain at dragged location
- Assert.Equal (15, movableView.Frame.X);
- Assert.Equal (15, movableView.Frame.Y);
- app.End (app.SessionStack!.First ());
- runnable.Dispose ();
- superView.Dispose ();
- }
- #endregion
- #region Resizable View Drag Tests
- [Fact]
- public void ResizableView_RightResize_Drag_IncreasesWidth ()
- {
- // Arrange
- using IApplication app = Application.Create ();
- app.Init ("fake");
- View superView = new ()
- {
- Width = 50,
- Height = 50
- };
- View resizableView = new ()
- {
- X = 10,
- Y = 10,
- Width = 10,
- Height = 10,
- Arrangement = ViewArrangement.RightResizable,
- BorderStyle = LineStyle.Single
- };
- superView.Add (resizableView);
- // Add to a runnable so the views are part of the application
- var runnable = new Runnable { App = app, Frame = new (0, 0, 80, 25) };
- runnable.Add (superView);
- app.Begin (runnable);
- // Simulate mouse press on right border
- MouseEventArgs pressEvent = new ()
- {
- ScreenPosition = new (19, 15),
- Flags = MouseFlags.Button1Pressed
- };
- app.Mouse.RaiseMouseEvent (pressEvent);
- // Simulate mouse drag to the right
- MouseEventArgs dragEvent = new ()
- {
- ScreenPosition = new (24, 15),
- Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
- };
- app.Mouse.RaiseMouseEvent (dragEvent);
- // Assert - Width should have increased
- Assert.Equal (10, resizableView.Frame.X); // X unchanged
- Assert.Equal (10, resizableView.Frame.Y); // Y unchanged
- Assert.Equal (15, resizableView.Frame.Width); // Width increased by 5
- Assert.Equal (10, resizableView.Frame.Height); // Height unchanged
- app.End (app.SessionStack!.First ());
- runnable.Dispose ();
- superView.Dispose ();
- }
- [Fact]
- public void ResizableView_BottomResize_Drag_IncreasesHeight ()
- {
- // Arrange
- using IApplication app = Application.Create ();
- app.Init ("fake");
- View superView = new ()
- {
- Width = 50,
- Height = 50
- };
- View resizableView = new ()
- {
- X = 10,
- Y = 10,
- Width = 10,
- Height = 10,
- Arrangement = ViewArrangement.BottomResizable,
- BorderStyle = LineStyle.Single
- };
- superView.Add (resizableView);
- // Add to a runnable so the views are part of the application
- var runnable = new Runnable { App = app, Frame = new (0, 0, 80, 25) };
- runnable.Add (superView);
- app.Begin (runnable);
- // Simulate mouse press on bottom border
- MouseEventArgs pressEvent = new ()
- {
- ScreenPosition = new (15, 19),
- Flags = MouseFlags.Button1Pressed
- };
- app.Mouse.RaiseMouseEvent (pressEvent);
- // Simulate mouse drag down
- MouseEventArgs dragEvent = new ()
- {
- ScreenPosition = new (15, 24),
- Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
- };
- app.Mouse.RaiseMouseEvent (dragEvent);
- // Assert - Height should have increased
- Assert.Equal (10, resizableView.Frame.X); // X unchanged
- Assert.Equal (10, resizableView.Frame.Y); // Y unchanged
- Assert.Equal (10, resizableView.Frame.Width); // Width unchanged
- Assert.Equal (15, resizableView.Frame.Height); // Height increased by 5
- app.End (app.SessionStack!.First ());
- runnable.Dispose ();
- superView.Dispose ();
- }
- [Fact]
- public void ResizableView_LeftResize_Drag_MovesAndResizes ()
- {
- // Arrange
- using IApplication app = Application.Create ();
- app.Init ("fake");
- View superView = new ()
- {
- Width = 50,
- Height = 50
- };
- View resizableView = new ()
- {
- X = 10,
- Y = 10,
- Width = 10,
- Height = 10,
- Arrangement = ViewArrangement.LeftResizable,
- BorderStyle = LineStyle.Single
- };
- superView.Add (resizableView);
- // Add to a runnable so the views are part of the application
- var runnable = new Runnable { App = app, Frame = new (0, 0, 80, 25) };
- runnable.Add (superView);
- app.Begin (runnable);
- // Simulate mouse press on left border
- MouseEventArgs pressEvent = new ()
- {
- ScreenPosition = new (10, 15),
- Flags = MouseFlags.Button1Pressed
- };
- app.Mouse.RaiseMouseEvent (pressEvent);
- // Simulate mouse drag to the left
- MouseEventArgs dragEvent = new ()
- {
- ScreenPosition = new (7, 15),
- Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
- };
- app.Mouse.RaiseMouseEvent (dragEvent);
- // Assert - Should move left and resize
- Assert.Equal (7, resizableView.Frame.X); // X moved left by 3
- Assert.Equal (10, resizableView.Frame.Y); // Y unchanged
- Assert.Equal (13, resizableView.Frame.Width); // Width increased by 3
- Assert.Equal (10, resizableView.Frame.Height); // Height unchanged
- app.End (app.SessionStack!.First ());
- runnable.Dispose ();
- superView.Dispose ();
- }
- [Fact]
- public void ResizableView_TopResize_Drag_MovesAndResizes ()
- {
- // Arrange
- using IApplication app = Application.Create ();
- app.Init ("fake");
- View superView = new ()
- {
- Width = 50,
- Height = 50
- };
- View resizableView = new ()
- {
- X = 10,
- Y = 10,
- Width = 10,
- Height = 10,
- Arrangement = ViewArrangement.TopResizable,
- BorderStyle = LineStyle.Single
- };
- superView.Add (resizableView);
- // Add to a runnable so the views are part of the application
- var runnable = new Runnable { App = app, Frame = new (0, 0, 80, 25) };
- runnable.Add (superView);
- app.Begin (runnable);
- // Simulate mouse press on top border
- MouseEventArgs pressEvent = new ()
- {
- ScreenPosition = new (15, 10),
- Flags = MouseFlags.Button1Pressed
- };
- app.Mouse.RaiseMouseEvent (pressEvent);
- // Simulate mouse drag up
- MouseEventArgs dragEvent = new ()
- {
- ScreenPosition = new (15, 8),
- Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
- };
- app.Mouse.RaiseMouseEvent (dragEvent);
- // Assert - Should move up and resize
- Assert.Equal (10, resizableView.Frame.X); // X unchanged
- Assert.Equal (8, resizableView.Frame.Y); // Y moved up by 2
- Assert.Equal (10, resizableView.Frame.Width); // Width unchanged
- Assert.Equal (12, resizableView.Frame.Height); // Height increased by 2
- app.End (app.SessionStack!.First ());
- runnable.Dispose ();
- superView.Dispose ();
- }
- #endregion
- #region Corner Resize Tests
- [Fact]
- public void ResizableView_BottomRightCornerResize_Drag_ResizesBothDimensions ()
- {
- // Arrange
- using IApplication app = Application.Create ();
- app.Init ("fake");
- View superView = new ()
- {
- Width = 50,
- Height = 50
- };
- View resizableView = new ()
- {
- X = 10,
- Y = 10,
- Width = 10,
- Height = 10,
- Arrangement = ViewArrangement.BottomResizable | ViewArrangement.RightResizable,
- BorderStyle = LineStyle.Single
- };
- superView.Add (resizableView);
- // Add to a runnable so the views are part of the application
- var runnable = new Runnable { App = app, Frame = new (0, 0, 80, 25) };
- runnable.Add (superView);
- app.Begin (runnable);
- // Simulate mouse press on bottom-right corner
- MouseEventArgs pressEvent = new ()
- {
- ScreenPosition = new (19, 19),
- Flags = MouseFlags.Button1Pressed
- };
- app.Mouse.RaiseMouseEvent (pressEvent);
- // Simulate mouse drag diagonally
- MouseEventArgs dragEvent = new ()
- {
- ScreenPosition = new (24, 24),
- Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
- };
- app.Mouse.RaiseMouseEvent (dragEvent);
- // Assert - Both dimensions should increase
- Assert.Equal (10, resizableView.Frame.X); // X unchanged
- Assert.Equal (10, resizableView.Frame.Y); // Y unchanged
- Assert.Equal (15, resizableView.Frame.Width); // Width increased by 5
- Assert.Equal (15, resizableView.Frame.Height); // Height increased by 5
- app.End (app.SessionStack!.First ());
- runnable.Dispose ();
- superView.Dispose ();
- }
- [Fact]
- public void ResizableView_TopLeftCornerResize_Drag_MovesAndResizes ()
- {
- // Arrange
- using IApplication app = Application.Create ();
- app.Init ("fake");
- View superView = new ()
- {
- Width = 50,
- Height = 50
- };
- View resizableView = new ()
- {
- X = 10,
- Y = 10,
- Width = 10,
- Height = 10,
- Arrangement = ViewArrangement.TopResizable | ViewArrangement.LeftResizable,
- BorderStyle = LineStyle.Single
- };
- superView.Add (resizableView);
- // Add to a runnable so the views are part of the application
- var runnable = new Runnable { App = app, Frame = new (0, 0, 80, 25) };
- runnable.Add (superView);
- app.Begin (runnable);
- // Simulate mouse press on top-left corner
- MouseEventArgs pressEvent = new ()
- {
- ScreenPosition = new (10, 10),
- Flags = MouseFlags.Button1Pressed
- };
- app.Mouse.RaiseMouseEvent (pressEvent);
- // Simulate mouse drag diagonally up and left
- MouseEventArgs dragEvent = new ()
- {
- ScreenPosition = new (7, 8),
- Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
- };
- app.Mouse.RaiseMouseEvent (dragEvent);
- // Assert - Should move and resize
- Assert.Equal (7, resizableView.Frame.X); // X moved left by 3
- Assert.Equal (8, resizableView.Frame.Y); // Y moved up by 2
- Assert.Equal (13, resizableView.Frame.Width); // Width increased by 3
- Assert.Equal (12, resizableView.Frame.Height); // Height increased by 2
- app.End (app.SessionStack!.First ());
- runnable.Dispose ();
- superView.Dispose ();
- }
- #endregion
- #region Minimum Size Constraints
- [Fact]
- public void ResizableView_Drag_RespectsMinimumWidth ()
- {
- // Arrange
- using IApplication app = Application.Create ();
- app.Init ("fake");
- View superView = new ()
- {
- Width = 50,
- Height = 50
- };
- View resizableView = new ()
- {
- X = 10,
- Y = 10,
- Width = 10,
- Height = 10,
- Arrangement = ViewArrangement.LeftResizable,
- BorderStyle = LineStyle.Single
- };
- superView.Add (resizableView);
- // Add to a runnable so the views are part of the application
- var runnable = new Runnable { App = app, Frame = new (0, 0, 80, 25) };
- runnable.Add (superView);
- app.Begin (runnable);
- // Try to drag far to the right (making width very small)
- MouseEventArgs dragEvent = new ()
- {
- Position = new (8, 5), // Drag 8 units right, would make width 2
- ScreenPosition = new (18, 15),
- Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
- };
- // Act
- resizableView.Border!.HandleDragOperation (dragEvent);
- // Assert - Width should be constrained to minimum
- // Minimum width = border thickness + margin right
- int expectedMinWidth = resizableView.Border!.Thickness.Horizontal + resizableView.Margin!.Thickness.Right;
- Assert.True (resizableView.Frame.Width >= expectedMinWidth);
- app.End (app.SessionStack!.First ());
- runnable.Dispose ();
- superView.Dispose ();
- }
- [Fact]
- public void ResizableView_Drag_RespectsMinimumHeight ()
- {
- // Arrange
- using IApplication app = Application.Create ();
- app.Init ("fake");
- View superView = new ()
- {
- Width = 50,
- Height = 50
- };
- View resizableView = new ()
- {
- X = 10,
- Y = 10,
- Width = 10,
- Height = 10,
- Arrangement = ViewArrangement.TopResizable,
- BorderStyle = LineStyle.Single
- };
- superView.Add (resizableView);
- // Add to a runnable so the views are part of the application
- var runnable = new Runnable { App = app, Frame = new (0, 0, 80, 25) };
- runnable.Add (superView);
- app.Begin (runnable);
- // Try to drag far down (making height very small)
- MouseEventArgs dragEvent = new ()
- {
- Position = new (5, 8), // Drag 8 units down, would make height 2
- ScreenPosition = new (15, 18),
- Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
- };
- // Act
- resizableView.Border!.HandleDragOperation (dragEvent);
- // Assert - Height should be constrained to minimum
- int expectedMinHeight = resizableView.Border!.Thickness.Vertical + resizableView.Margin!.Thickness.Bottom;
- Assert.True (resizableView.Frame.Height >= expectedMinHeight);
- app.End (app.SessionStack!.First ());
- runnable.Dispose ();
- superView.Dispose ();
- }
- #endregion
- }
|