Files
Terminal.Gui/Tests/UnitTestsParallelizable/View/Navigation/AddRemoveTests.cs
Tig e311cad7ac Partial on #2975 - Replaces Menu v1 in many places with v2 (#4040)
* touching publish.yml

* Fixed UICatalog bugs. Added fluent tests.

* marked v1 menu stuff as obsolte

* Tweaks.
Added View.GetSubMenus<type>().

* fixed unit tests

* general messing around

* general messing around

* Playing with Fluent

* ColorScheme tweaks

* WIP: ColorScheme tweaks

* Playing with Fluent

* Merged from laptop2

* Hacky-ish fixes to:
- #4016
- #4014

* Fixed Region bug preventing menus without borders from working

* Tweaks

* Fixed a bunch of CM issues

* Fixed OoptionSelector

* ip

* FixedCM issues

* Fixed CM issues2

* Revert "FixedCM issues"

This reverts commit dd6c6a70a3.

* Reverted stuff

* Found and fixed bug in AllViews_Center_Properly

* Fixed CM issues2

* removed menuv2 onapplied.
Changed how UICatalog Applys CM

* changed test time out to see if it helkps with ubuntu fails

* reset app on fail?

* back to 1500ms

* Made StatusBar nullable.

* Code Cleanup.

* HexEditor Code Cleanup.

* HexEditor Code Cleanup.

* Back to 3000ms. Sigh.

* Trying different logic

* Trying different logic2

* Fixed potential crash in runlop

* Fixed potential crash in runlop2

* Tweaked Spinner stuff

* Removed TabView from TextEffects scenario. Not needed and possible culprit.

* back to 2000ms

* WIP: Revamping menu scenarios

* Menu Scenario refinements.
Fixed a few bugs.
Code cleanup.

* fixed unit test

* Fixed warnings

* Fixed warnings2

* Fixed File.Exit

* WIP: Dealing with QuitKey struggles

* WIP: Dealing with QuitKey struggles 2

* WIP: Dealing with QuitKey struggles 3

* Fixed ListView collection nav bug

* Fixed a bunch of menu stuff.
Fixed Appv2 stuff.

* Lots of refactoring and fixing

* Lots of unit test issues

* Fixed DebugIDisposable issues

* Fixed release build issue

* Fixed release build issue 2

* DebugIDisposable -> EnableDebugIDisposableAsserts and more

* DebugIDisposable -> EnableDebugIDisposableAsserts and more 2

* Fixed Menus scenario - context menu

* Added @bdisp suggested assert. Commented it out as it breaks tests.

* Code cleanup

* Fixed disposed but

* Fixed UICatalog exit

* Fixed Unit test I broke.
Added 'Minimal' Theme that turns off all borders etc...
2025-05-29 14:08:47 -06:00

244 lines
5.4 KiB
C#

using UnitTests;
using Xunit.Abstractions;
namespace Terminal.Gui.ViewTests;
[Collection ("Global Test Setup")]
public class AddRemoveNavigationTests () : TestsAllViews
{
[Fact]
public void Add_First_SubView_Gets_Focus ()
{
View top = new View ()
{
Id = "top",
CanFocus = true
};
top.SetFocus ();
Assert.True (top.HasFocus);
View subView = new View ()
{
Id = "subView",
CanFocus = true
};
top.Add (subView);
Assert.True (top.HasFocus);
Assert.Equal (subView, top.Focused);
Assert.True (subView.HasFocus);
}
[Fact]
public void Add_Subsequent_SubView_Gets_Focus ()
{
View top = new View ()
{
Id = "top",
CanFocus = true
};
top.SetFocus ();
Assert.True (top.HasFocus);
View subView = new View ()
{
Id = "subView",
CanFocus = true
};
top.Add (subView);
Assert.True (subView.HasFocus);
View subView2 = new View ()
{
Id = "subView2",
CanFocus = true
};
top.Add (subView2);
Assert.True (subView2.HasFocus);
}
[Fact]
public void Add_Nested_SubViews_Deepest_Gets_Focus ()
{
View top = new View ()
{
Id = "top",
CanFocus = true
};
top.SetFocus ();
Assert.True (top.HasFocus);
View subView = new View ()
{
Id = "subView",
CanFocus = true
};
View subSubView = new View ()
{
Id = "subSubView",
CanFocus = true
};
subView.Add (subSubView);
top.Add (subView);
Assert.True (top.HasFocus);
Assert.Equal (subView, top.Focused);
Assert.True (subView.HasFocus);
Assert.True (subSubView.HasFocus);
}
[Fact]
public void Remove_SubView_Raises_HasFocusChanged ()
{
var top = new View
{
Id = "top",
CanFocus = true
};
var subView1 = new View
{
Id = "subView1",
CanFocus = true
};
var subView2 = new View
{
Id = "subView2",
CanFocus = true
};
top.Add (subView1, subView2);
var subView1HasFocusChangedTrueCount = 0;
var subView1HasFocusChangedFalseCount = 0;
subView1.HasFocusChanged += (s, e) =>
{
if (e.NewValue)
{
subView1HasFocusChangedTrueCount++;
}
else
{
subView1HasFocusChangedFalseCount++;
}
};
var subView2HasFocusChangedTrueCount = 0;
var subView2HasFocusChangedFalseCount = 0;
subView2.HasFocusChanged += (s, e) =>
{
if (e.NewValue)
{
subView2HasFocusChangedTrueCount++;
}
else
{
subView2HasFocusChangedFalseCount++;
}
};
top.SetFocus ();
Assert.True (top.HasFocus);
Assert.True (subView1.HasFocus);
Assert.False (subView2.HasFocus);
Assert.Equal (1, subView1HasFocusChangedTrueCount);
Assert.Equal (0, subView1HasFocusChangedFalseCount);
Assert.Equal (0, subView2HasFocusChangedTrueCount);
Assert.Equal (0, subView2HasFocusChangedFalseCount);
top.Remove (subView1); // this should have the same resuilt as top.AdvanceFocus (NavigationDirection.Forward, null);
Assert.False (subView1.HasFocus);
Assert.True (subView2.HasFocus);
Assert.Equal (1, subView1HasFocusChangedTrueCount);
Assert.Equal (1, subView1HasFocusChangedFalseCount);
Assert.Equal (1, subView2HasFocusChangedTrueCount);
Assert.Equal (0, subView2HasFocusChangedFalseCount);
}
[Fact]
public void Remove_Focused_SubView_Keeps_Focus_And_SubView_Looses_Focus ()
{
View top = new View ()
{
Id = "top",
CanFocus = true
};
View subView = new View ()
{
Id = "subView",
CanFocus = true
};
top.Add (subView);
top.SetFocus ();
Assert.True (top.HasFocus);
Assert.Equal (subView, top.Focused);
Assert.True (subView.HasFocus);
top.Remove (subView);
Assert.True (top.HasFocus);
Assert.Null (top.Focused);
Assert.False (subView.HasFocus);
}
[Fact]
public void Remove_Focused_SubView_Keeps_Focus_And_SubView_Looses_Focus_And_Next_Gets_Focus ()
{
View top = new View ()
{
Id = "top",
CanFocus = true
};
View subView1 = new View ()
{
Id = "subView1",
CanFocus = true
};
View subView2 = new View ()
{
Id = "subView2",
CanFocus = true
};
top.Add (subView1, subView2);
top.SetFocus ();
Assert.True (top.HasFocus);
Assert.Equal (subView1, top.Focused);
Assert.True (subView1.HasFocus);
Assert.False (subView2.HasFocus);
top.Remove (subView1);
Assert.True (top.HasFocus);
Assert.True (subView2.HasFocus);
Assert.Equal (subView2, top.Focused);
Assert.False (subView1.HasFocus);
}
}