mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-29 09:18:01 +01:00
general messing around
This commit is contained in:
@@ -591,4 +591,70 @@ public class SubViewTests
|
||||
Assert.NotEqual (superView, subView.SuperView);
|
||||
Assert.Empty (superView.SubViews);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveAll_Removes_All_SubViews ()
|
||||
{
|
||||
// Arrange
|
||||
var superView = new View ();
|
||||
var subView1 = new View ();
|
||||
var subView2 = new View ();
|
||||
var subView3 = new View ();
|
||||
|
||||
superView.Add (subView1, subView2, subView3);
|
||||
|
||||
// Act
|
||||
var removedViews = superView.RemoveAll ();
|
||||
|
||||
// Assert
|
||||
Assert.Empty (superView.SubViews);
|
||||
Assert.Equal (3, removedViews.Count);
|
||||
Assert.Contains (subView1, removedViews);
|
||||
Assert.Contains (subView2, removedViews);
|
||||
Assert.Contains (subView3, removedViews);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveAllTView_Removes_All_SubViews_Of_Specific_Type ()
|
||||
{
|
||||
// Arrange
|
||||
var superView = new View ();
|
||||
var subView1 = new View ();
|
||||
var subView2 = new View ();
|
||||
var subView3 = new View ();
|
||||
var subView4 = new Button ();
|
||||
|
||||
superView.Add (subView1, subView2, subView3, subView4);
|
||||
|
||||
// Act
|
||||
var removedViews = superView.RemoveAll<Button> ();
|
||||
|
||||
// Assert
|
||||
Assert.Equal (3, superView.SubViews.Count);
|
||||
Assert.DoesNotContain (subView4, superView.SubViews);
|
||||
Assert.Single (removedViews);
|
||||
Assert.Contains (subView4, removedViews);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveAllTView_Does_Not_Remove_Other_Types ()
|
||||
{
|
||||
// Arrange
|
||||
var superView = new View ();
|
||||
var subView1 = new View ();
|
||||
var subView2 = new Button ();
|
||||
var subView3 = new Label ();
|
||||
|
||||
superView.Add (subView1, subView2, subView3);
|
||||
|
||||
// Act
|
||||
var removedViews = superView.RemoveAll<Button> ();
|
||||
|
||||
// Assert
|
||||
Assert.Equal (2, superView.SubViews.Count);
|
||||
Assert.Contains (subView1, superView.SubViews);
|
||||
Assert.Contains (subView3, superView.SubViews);
|
||||
Assert.Single (removedViews);
|
||||
Assert.Contains (subView2, removedViews);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,124 +1,208 @@
|
||||
|
||||
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_WithEnum_ShouldSetFlags ()
|
||||
{
|
||||
var flagSelector = new FlagSelector();
|
||||
var flagSelector = new FlagSelector ();
|
||||
|
||||
flagSelector.SetFlags<FlagSelectorStyles>();
|
||||
flagSelector.SetFlags<FlagSelectorStyles> ();
|
||||
|
||||
var expectedFlags = Enum.GetValues<FlagSelectorStyles>()
|
||||
.ToDictionary(f => Convert.ToUInt32(f), f => f.ToString());
|
||||
var expectedFlags = Enum.GetValues<FlagSelectorStyles> ()
|
||||
.ToDictionary (f => Convert.ToUInt32 (f), f => f.ToString ());
|
||||
|
||||
Assert.Equal(expectedFlags, flagSelector.Flags);
|
||||
Assert.Equal (expectedFlags, flagSelector.Flags);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetFlags_WithEnumAndCustomNames_ShouldSetFlags()
|
||||
public void SetFlags_WithEnumAndCustomNames_ShouldSetFlags ()
|
||||
{
|
||||
var flagSelector = new FlagSelector();
|
||||
var flagSelector = new FlagSelector ();
|
||||
|
||||
flagSelector.SetFlags<FlagSelectorStyles>(f => f switch
|
||||
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;
|
||||
|
||||
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 Generic_ ()
|
||||
{
|
||||
var flagSelector = new FlagSelector<FlagSelectorStyles> ();
|
||||
|
||||
var flags = flagSelector.Flags;
|
||||
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user