Files
Terminal.Gui/UnitTests/View/TitleTests.cs
Tig 16055c53b0 Fixes #3039. Fix View.HotKey (#3249)
* Added View.DefaultCommand etc... Started on dedicated scenario

* Fixed un-shifted hotkeys -> Fixed Key Equals. Fixed WindowsDriver passing wrong key. Etc.

* Fixed Key Bindings and HotKeys

* Fixed Key Bindings and HotKeys

* Label now correctly supports hotkey

* Disabled unix hot keys because they are annoying and get in the way

* Updated nuget. fixed warnings

* Trying to fix ci/ci issue

* Trying to fix ci/ci issue

* Trying to fix ci/ci issue

* Changed TextChangingEventArgs to inherit from CancelEventArgs

* TextChangingEventArgs -> TextEventArgs

* Simplified Text events by having only on args class

* Fixed unit tests fail

* Simplified by removing TitleEventArgs

* POC of Title being primary for hotkey. Label and Button hacked to work

* POC of Title being primary for hotkey. Label and Button hacked to work - all unit tests pass

* Dropped Microsoft.NETFramework.ReferenceAssemblies

* Fixed Dialogs scenario hotkeys

* Fixed build warnings

* Fixed Border Title render bug

* Regiggering default command handling

* Regiggering default command handling

* Checkbox clean up

* Added StateEventArgs POC

* Command.Default -> Command.HotKey

* Command.Default -> Command.HotKey - fixed TableView

* Command.Default -> Command.HotKey - fixed TableView

* Updated reactive example

* Fixed Toplevel.BringOverlappedTopToFront - was reordering SubViews when it shouldn't

* WIP - broke

* Finished impl of StateEventArgs

* Deleted ToggleEventArgs.cs. Added StateEventArgs.cs

* XML doc fix

* Removed old code

* Removed commented out code

* Label.Clicked -> Label.Accept (missed this before)

* Removed Labels as Buttons scenario as it's not really  useful

* Moved SubView tests to own file

* Moved SubView tests to own file

* Simplified Text test

* Added OnAccept test

* Deleted DefaultCommand

* Modernized CheckBox

* New button test

* Cleaned up RadioGroup; added tests

* KeyCode->Key in ListView

* Added ListView unit tests

* ListView now does Accept correctly

* TreeView now does Accept correctly

* Cleaned up some TextField tests

* TextView now handles Accept properly; updated CharMap and Adornments scenarios to test

* Fixed ComboBox to deal with TextView now handles Accept properly; updated CharMap and Adornments scenarios to test

* Removed un-needed using statement
2024-02-22 15:11:26 -07:00

80 lines
2.3 KiB
C#

using System.Text;
using Xunit.Abstractions;
//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
// Alias Console to MockConsole so we don't accidentally use Console
namespace Terminal.Gui.ViewTests;
public class TitleTests
{
private readonly ITestOutputHelper output;
public TitleTests (ITestOutputHelper output) { this.output = output; }
[Fact]
public void Set_Title_Fires_TitleChanged ()
{
var r = new View ();
Assert.Equal (string.Empty, r.Title);
string expectedOld = null;
string expected = null;
r.TitleChanged += (s, args) =>
{
Assert.Equal (expectedOld, args.OldValue);
Assert.Equal (r.Title, args.NewValue);
};
expected = "title";
expectedOld = r.Title;
r.Title = expected;
Assert.Equal (expected, r.Title);
r.Dispose ();
}
[Fact]
public void Set_Title_Fires_TitleChanging ()
{
var r = new View ();
Assert.Equal (string.Empty, r.Title);
string expectedOld = null;
string expectedDuring = null;
string expectedAfter = null;
var cancel = false;
r.TitleChanging += (s, args) =>
{
Assert.Equal (expectedOld, args.OldValue);
Assert.Equal (expectedDuring, args.NewValue);
args.Cancel = cancel;
};
expectedOld = string.Empty;
r.Title = expectedDuring = expectedAfter = "title";
Assert.Equal (expectedAfter, r.Title);
expectedOld = r.Title;
r.Title = expectedDuring = expectedAfter = "a different title";
Assert.Equal (expectedAfter, r.Title);
// Now setup cancelling the change and change it back to "title"
cancel = true;
expectedOld = r.Title;
r.Title = expectedDuring = "title";
Assert.Equal (expectedAfter, r.Title);
r.Dispose ();
}
// Setting Text does NOT set the HotKey
[Fact]
public void Title_Does_Set_HotKey ()
{
var view = new View { HotKeySpecifier = (Rune)'_', Title = "_Hello World" };
Assert.Equal (Key.H, view.HotKey);
}
}