Skip to content

Commit

Permalink
Added test from gui-cs#3136
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Jan 7, 2024
1 parent 5ab8d4d commit 98024dc
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions UnitTests/Views/MenuBarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2755,4 +2755,58 @@ public void Separators_Does_Not_Throws_Pressing_Menu_Shortcut ()
var exception = Record.Exception (() => Assert.True (menu.NewKeyDownEvent (new Key (KeyCode.AltMask | KeyCode.Q))));
Assert.Null (exception);
}

[Fact]
public void RemoveAndThenAddMenuBar_ShouldNotChangeWidth ()
{
MenuBar menuBar;
MenuBar menuBar2;

// TODO: When https: //github.com/gui-cs/Terminal.Gui/issues/3136 is fixed,
// TODO: Change this to Window
var w = new View ();
menuBar2 = new Terminal.Gui.MenuBar ();
menuBar = new Terminal.Gui.MenuBar ();
w.Width = Dim.Fill (0);
w.Height = Dim.Fill (0);
w.X = 0;
w.Y = 0;

w.Visible = true;
// TODO: When https: //github.com/gui-cs/Terminal.Gui/issues/3136 is fixed,
// TODO: uncomment this.
//w.Modal = false;
w.Title = "";
menuBar.Width = Dim.Fill (0);
menuBar.Height = 1;
menuBar.X = 0;
menuBar.Y = 0;
menuBar.Visible = true;
w.Add (menuBar);

menuBar2.Width = Dim.Fill (0);
menuBar2.Height = 1;
menuBar2.X = 0;
menuBar2.Y = 4;
menuBar2.Visible = true;
w.Add (menuBar2);


var menuBars = w.Subviews.OfType<MenuBar> ().ToArray ();
Assert.Equal (2, menuBars.Length);

Assert.Equal (Dim.Fill (0), menuBars [0].Width);
Assert.Equal (Dim.Fill (0), menuBars [1].Width);

// Goes wrong here
w.Remove (menuBar);
w.Remove (menuBar2);

w.Add (menuBar);
w.Add (menuBar2);

// These assertions fail
Assert.Equal (Dim.Fill (0), menuBars [0].Width);
Assert.Equal (Dim.Fill (0), menuBars [1].Width);
}
}

0 comments on commit 98024dc

Please sign in to comment.