mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-31 02:08:03 +01:00
* 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...
This commit is contained in:
@@ -5,6 +5,7 @@ using Xunit.Abstractions;
|
||||
|
||||
namespace Terminal.Gui.ViewsTests;
|
||||
|
||||
[Collection ("Global Test Setup")]
|
||||
public class AllViewsTests (ITestOutputHelper output) : TestsAllViews
|
||||
{
|
||||
[Theory]
|
||||
@@ -25,6 +26,8 @@ public class AllViewsTests (ITestOutputHelper output) : TestsAllViews
|
||||
{
|
||||
Assert.True (type.FullName == view.GetType ().FullName);
|
||||
}
|
||||
|
||||
view?.Dispose ();
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -72,11 +75,12 @@ public class AllViewsTests (ITestOutputHelper output) : TestsAllViews
|
||||
Assert.Equal (1, selectingCount);
|
||||
Assert.Equal (0, acceptedCount);
|
||||
}
|
||||
view?.Dispose ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData (nameof (AllViewTypes))]
|
||||
public void AllViews_Command_Accept_Raises_Accepted (Type viewType)
|
||||
public void AllViews_Command_Accept_Raises_Accepting (Type viewType)
|
||||
{
|
||||
var view = CreateInstanceIfNotGeneric (viewType);
|
||||
|
||||
@@ -95,14 +99,15 @@ public class AllViewsTests (ITestOutputHelper output) : TestsAllViews
|
||||
var selectingCount = 0;
|
||||
view.Selecting += (s, e) => selectingCount++;
|
||||
|
||||
var acceptedCount = 0;
|
||||
view.Accepting += (s, e) => { acceptedCount++; };
|
||||
var acceptingCount = 0;
|
||||
view.Accepting += (s, e) => { acceptingCount++; };
|
||||
|
||||
if (view.InvokeCommand (Command.Accept) == true)
|
||||
{
|
||||
Assert.Equal (0, selectingCount);
|
||||
Assert.Equal (1, acceptedCount);
|
||||
Assert.Equal (1, acceptingCount);
|
||||
}
|
||||
view?.Dispose ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -138,5 +143,6 @@ public class AllViewsTests (ITestOutputHelper output) : TestsAllViews
|
||||
Assert.Equal (1, handlingHotKeyCount);
|
||||
Assert.Equal (0, acceptedCount);
|
||||
}
|
||||
view?.Dispose ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,124 +1,214 @@
|
||||
|
||||
namespace Terminal.Gui.ViewsTests;
|
||||
|
||||
public class FlagSelectorTests
|
||||
{
|
||||
[Fact]
|
||||
public void Initialization_ShouldSetDefaults()
|
||||
public void Initialization_ShouldSetDefaults ()
|
||||
{
|
||||
var flagSelector = new FlagSelector();
|
||||
var flagSelector = new FlagSelector ();
|
||||
|
||||
Assert.True(flagSelector.CanFocus);
|
||||
Assert.Equal(Dim.Auto(DimAutoStyle.Content), flagSelector.Width);
|
||||
Assert.Equal(Dim.Auto(DimAutoStyle.Content), flagSelector.Height);
|
||||
Assert.Equal(Orientation.Vertical, flagSelector.Orientation);
|
||||
Assert.True (flagSelector.CanFocus);
|
||||
Assert.Equal (Dim.Auto (DimAutoStyle.Content), flagSelector.Width);
|
||||
Assert.Equal (Dim.Auto (DimAutoStyle.Content), flagSelector.Height);
|
||||
Assert.Equal (Orientation.Vertical, flagSelector.Orientation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetFlags_WithDictionary_ShouldSetFlags()
|
||||
public void SetFlags_WithDictionary_ShouldSetFlags ()
|
||||
{
|
||||
var flagSelector = new FlagSelector();
|
||||
var flagSelector = new FlagSelector ();
|
||||
var flags = new Dictionary<uint, string>
|
||||
{
|
||||
{ 1, "Flag1" },
|
||||
{ 2, "Flag2" }
|
||||
};
|
||||
|
||||
flagSelector.SetFlags(flags);
|
||||
flagSelector.SetFlags (flags);
|
||||
|
||||
Assert.Equal(flags, flagSelector.Flags);
|
||||
Assert.Equal (flags, flagSelector.Flags);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetFlags_WithEnum_ShouldSetFlags()
|
||||
public void SetFlags_WithDictionary_ShouldSetValue ()
|
||||
{
|
||||
var flagSelector = new FlagSelector();
|
||||
var flagSelector = new FlagSelector ();
|
||||
var flags = new Dictionary<uint, string>
|
||||
{
|
||||
{ 1, "Flag1" },
|
||||
{ 2, "Flag2" }
|
||||
};
|
||||
|
||||
flagSelector.SetFlags<FlagSelectorStyles>();
|
||||
flagSelector.SetFlags (flags);
|
||||
|
||||
var expectedFlags = Enum.GetValues<FlagSelectorStyles>()
|
||||
.ToDictionary(f => Convert.ToUInt32(f), f => f.ToString());
|
||||
|
||||
Assert.Equal(expectedFlags, flagSelector.Flags);
|
||||
Assert.Equal ((uint)1, flagSelector.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetFlags_WithEnumAndCustomNames_ShouldSetFlags()
|
||||
public void SetFlags_WithEnum_ShouldSetFlags ()
|
||||
{
|
||||
var flagSelector = new FlagSelector();
|
||||
var flagSelector = new FlagSelector ();
|
||||
|
||||
flagSelector.SetFlags<FlagSelectorStyles>(f => f switch
|
||||
flagSelector.SetFlags<FlagSelectorStyles> ();
|
||||
|
||||
var expectedFlags = Enum.GetValues<FlagSelectorStyles> ()
|
||||
.ToDictionary (f => Convert.ToUInt32 (f), f => f.ToString ());
|
||||
|
||||
Assert.Equal (expectedFlags, flagSelector.Flags);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetFlags_WithEnumAndCustomNames_ShouldSetFlags ()
|
||||
{
|
||||
var flagSelector = new FlagSelector ();
|
||||
|
||||
flagSelector.SetFlags<FlagSelectorStyles> (f => f switch
|
||||
{
|
||||
FlagSelectorStyles.ShowNone => "Show None Value",
|
||||
FlagSelectorStyles.ShowValueEdit => "Show Value Editor",
|
||||
FlagSelectorStyles.All => "Everything",
|
||||
_ => f.ToString()
|
||||
_ => f.ToString ()
|
||||
});
|
||||
|
||||
var expectedFlags = Enum.GetValues<FlagSelectorStyles>()
|
||||
.ToDictionary(f => Convert.ToUInt32(f), f => f switch
|
||||
var expectedFlags = Enum.GetValues<FlagSelectorStyles> ()
|
||||
.ToDictionary (f => Convert.ToUInt32 (f), f => f switch
|
||||
{
|
||||
FlagSelectorStyles.ShowNone => "Show None Value",
|
||||
FlagSelectorStyles.ShowValueEdit => "Show Value Editor",
|
||||
FlagSelectorStyles.All => "Everything",
|
||||
_ => f.ToString()
|
||||
_ => f.ToString ()
|
||||
});
|
||||
|
||||
Assert.Equal(expectedFlags, flagSelector.Flags);
|
||||
Assert.Equal (expectedFlags, flagSelector.Flags);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Value_Set_ShouldUpdateCheckedState()
|
||||
public void Value_Set_ShouldUpdateCheckedState ()
|
||||
{
|
||||
var flagSelector = new FlagSelector();
|
||||
var flagSelector = new FlagSelector ();
|
||||
var flags = new Dictionary<uint, string>
|
||||
{
|
||||
{ 1, "Flag1" },
|
||||
{ 2, "Flag2" }
|
||||
};
|
||||
|
||||
flagSelector.SetFlags(flags);
|
||||
flagSelector.SetFlags (flags);
|
||||
flagSelector.Value = 1;
|
||||
|
||||
var checkBox = flagSelector.SubViews.OfType<CheckBox>().First(cb => (uint)cb.Data == 1);
|
||||
Assert.Equal(CheckState.Checked, checkBox.CheckedState);
|
||||
var checkBox = flagSelector.SubViews.OfType<CheckBox> ().First (cb => (uint)cb.Data == 1);
|
||||
Assert.Equal (CheckState.Checked, checkBox.CheckedState);
|
||||
|
||||
checkBox = flagSelector.SubViews.OfType<CheckBox>().First(cb => (uint)cb.Data == 2);
|
||||
Assert.Equal(CheckState.UnChecked, checkBox.CheckedState);
|
||||
checkBox = flagSelector.SubViews.OfType<CheckBox> ().First (cb => (uint)cb.Data == 2);
|
||||
Assert.Equal (CheckState.UnChecked, checkBox.CheckedState);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Styles_Set_ShouldCreateSubViews()
|
||||
public void Styles_Set_ShouldCreateSubViews ()
|
||||
{
|
||||
var flagSelector = new FlagSelector();
|
||||
var flagSelector = new FlagSelector ();
|
||||
var flags = new Dictionary<uint, string>
|
||||
{
|
||||
{ 1, "Flag1" },
|
||||
{ 2, "Flag2" }
|
||||
};
|
||||
|
||||
flagSelector.SetFlags(flags);
|
||||
flagSelector.SetFlags (flags);
|
||||
flagSelector.Styles = FlagSelectorStyles.ShowNone;
|
||||
|
||||
Assert.Contains(flagSelector.SubViews, sv => sv is CheckBox cb && cb.Title == "None");
|
||||
Assert.Contains (flagSelector.SubViews, sv => sv is CheckBox cb && cb.Title == "None");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValueChanged_Event_ShouldBeRaised()
|
||||
public void ValueChanged_Event_ShouldBeRaised ()
|
||||
{
|
||||
var flagSelector = new FlagSelector();
|
||||
var flagSelector = new FlagSelector ();
|
||||
var flags = new Dictionary<uint, string>
|
||||
{
|
||||
{ 1, "Flag1" },
|
||||
{ 2, "Flag2" }
|
||||
};
|
||||
|
||||
flagSelector.SetFlags(flags);
|
||||
flagSelector.SetFlags (flags);
|
||||
bool eventRaised = false;
|
||||
flagSelector.ValueChanged += (sender, args) => eventRaised = true;
|
||||
|
||||
flagSelector.Value = 1;
|
||||
flagSelector.Value = 2;
|
||||
|
||||
Assert.True(eventRaised);
|
||||
Assert.True (eventRaised);
|
||||
}
|
||||
|
||||
// Tests for FlagSelector<TEnum>
|
||||
[Fact]
|
||||
public void GenericInitialization_ShouldSetDefaults ()
|
||||
{
|
||||
var flagSelector = new FlagSelector<FlagSelectorStyles> ();
|
||||
|
||||
Assert.True (flagSelector.CanFocus);
|
||||
Assert.Equal (Dim.Auto (DimAutoStyle.Content), flagSelector.Width);
|
||||
Assert.Equal (Dim.Auto (DimAutoStyle.Content), flagSelector.Height);
|
||||
Assert.Equal (Orientation.Vertical, flagSelector.Orientation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Generic_SetFlags_Methods_Throw ()
|
||||
{
|
||||
var flagSelector = new FlagSelector<FlagSelectorStyles> ();
|
||||
|
||||
Assert.Throws<InvalidOperationException> (() => flagSelector.SetFlags (new Dictionary<uint, string> ()));
|
||||
Assert.Throws<InvalidOperationException> (() => flagSelector.SetFlags<FlagSelectorStyles> ());
|
||||
Assert.Throws<InvalidOperationException> (() => flagSelector.SetFlags<FlagSelectorStyles> (styles => null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenericSetFlagNames_ShouldSetFlagNames ()
|
||||
{
|
||||
var flagSelector = new FlagSelector<FlagSelectorStyles> ();
|
||||
|
||||
flagSelector.SetFlagNames (f => f switch
|
||||
{
|
||||
FlagSelectorStyles.ShowNone => "Show None Value",
|
||||
FlagSelectorStyles.ShowValueEdit => "Show Value Editor",
|
||||
FlagSelectorStyles.All => "Everything",
|
||||
_ => f.ToString ()
|
||||
});
|
||||
|
||||
var expectedFlags = Enum.GetValues<FlagSelectorStyles> ()
|
||||
.ToDictionary (f => Convert.ToUInt32 (f), f => f switch
|
||||
{
|
||||
FlagSelectorStyles.ShowNone => "Show None Value",
|
||||
FlagSelectorStyles.ShowValueEdit => "Show Value Editor",
|
||||
FlagSelectorStyles.All => "Everything",
|
||||
_ => f.ToString ()
|
||||
});
|
||||
|
||||
Assert.Equal (expectedFlags, flagSelector.Flags);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenericValue_Set_ShouldUpdateCheckedState ()
|
||||
{
|
||||
var flagSelector = new FlagSelector<FlagSelectorStyles> ();
|
||||
|
||||
flagSelector.SetFlagNames (f => f.ToString ());
|
||||
flagSelector.Value = FlagSelectorStyles.ShowNone;
|
||||
|
||||
var checkBox = flagSelector.SubViews.OfType<CheckBox> ().First (cb => (uint)cb.Data == Convert.ToUInt32 (FlagSelectorStyles.ShowNone));
|
||||
Assert.Equal (CheckState.Checked, checkBox.CheckedState);
|
||||
|
||||
checkBox = flagSelector.SubViews.OfType<CheckBox> ().First (cb => (uint)cb.Data == Convert.ToUInt32 (FlagSelectorStyles.ShowValueEdit));
|
||||
Assert.Equal (CheckState.UnChecked, checkBox.CheckedState);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenericValueChanged_Event_ShouldBeRaised ()
|
||||
{
|
||||
var flagSelector = new FlagSelector<FlagSelectorStyles> ();
|
||||
|
||||
flagSelector.SetFlagNames (f => f.ToString ());
|
||||
bool eventRaised = false;
|
||||
flagSelector.ValueChanged += (sender, args) => eventRaised = true;
|
||||
|
||||
flagSelector.Value = FlagSelectorStyles.ShowNone;
|
||||
|
||||
Assert.True (eventRaised);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Terminal.Gui.ViewsTests;
|
||||
|
||||
[Collection ("Global Test Setup")]
|
||||
|
||||
[TestSubject (typeof (Shortcut))]
|
||||
public class ShortcutTests
|
||||
{
|
||||
@@ -420,7 +422,7 @@ public class ShortcutTests
|
||||
Assert.False (shortcut.CommandView.CanFocus);
|
||||
|
||||
shortcut.CommandView = new () { CanFocus = true };
|
||||
Assert.False (shortcut.CommandView.CanFocus);
|
||||
Assert.True (shortcut.CommandView.CanFocus);
|
||||
|
||||
shortcut.CommandView.CanFocus = true;
|
||||
Assert.True (shortcut.CommandView.CanFocus);
|
||||
|
||||
Reference in New Issue
Block a user