mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +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...
215 lines
7.1 KiB
C#
215 lines
7.1 KiB
C#
namespace Terminal.Gui.ViewsTests;
|
|
|
|
public class FlagSelectorTests
|
|
{
|
|
[Fact]
|
|
public void Initialization_ShouldSetDefaults ()
|
|
{
|
|
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);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetFlags_WithDictionary_ShouldSetFlags ()
|
|
{
|
|
var flagSelector = new FlagSelector ();
|
|
var flags = new Dictionary<uint, string>
|
|
{
|
|
{ 1, "Flag1" },
|
|
{ 2, "Flag2" }
|
|
};
|
|
|
|
flagSelector.SetFlags (flags);
|
|
|
|
Assert.Equal (flags, flagSelector.Flags);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetFlags_WithDictionary_ShouldSetValue ()
|
|
{
|
|
var flagSelector = new FlagSelector ();
|
|
var flags = new Dictionary<uint, string>
|
|
{
|
|
{ 1, "Flag1" },
|
|
{ 2, "Flag2" }
|
|
};
|
|
|
|
flagSelector.SetFlags (flags);
|
|
|
|
Assert.Equal ((uint)1, flagSelector.Value);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetFlags_WithEnum_ShouldSetFlags ()
|
|
{
|
|
var flagSelector = new FlagSelector ();
|
|
|
|
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 ()
|
|
});
|
|
|
|
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 Value_Set_ShouldUpdateCheckedState ()
|
|
{
|
|
var flagSelector = new FlagSelector ();
|
|
var flags = new Dictionary<uint, string>
|
|
{
|
|
{ 1, "Flag1" },
|
|
{ 2, "Flag2" }
|
|
};
|
|
|
|
flagSelector.SetFlags (flags);
|
|
flagSelector.Value = 1;
|
|
|
|
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);
|
|
}
|
|
|
|
[Fact]
|
|
public void Styles_Set_ShouldCreateSubViews ()
|
|
{
|
|
var flagSelector = new FlagSelector ();
|
|
var flags = new Dictionary<uint, string>
|
|
{
|
|
{ 1, "Flag1" },
|
|
{ 2, "Flag2" }
|
|
};
|
|
|
|
flagSelector.SetFlags (flags);
|
|
flagSelector.Styles = FlagSelectorStyles.ShowNone;
|
|
|
|
Assert.Contains (flagSelector.SubViews, sv => sv is CheckBox cb && cb.Title == "None");
|
|
}
|
|
|
|
[Fact]
|
|
public void ValueChanged_Event_ShouldBeRaised ()
|
|
{
|
|
var flagSelector = new FlagSelector ();
|
|
var flags = new Dictionary<uint, string>
|
|
{
|
|
{ 1, "Flag1" },
|
|
{ 2, "Flag2" }
|
|
};
|
|
|
|
flagSelector.SetFlags (flags);
|
|
bool eventRaised = false;
|
|
flagSelector.ValueChanged += (sender, args) => eventRaised = true;
|
|
|
|
flagSelector.Value = 2;
|
|
|
|
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);
|
|
}
|
|
}
|