Files
Terminal.Gui/UnitTests/Views/DatePickerTests.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

93 lines
3.1 KiB
C#

using System.Globalization;
namespace Terminal.Gui.ViewsTests;
public class DatePickerTests
{
[Fact]
public void DatePicker_ChangingCultureChangesFormat ()
{
var date = new DateTime (2000, 7, 23);
var datePicker = new DatePicker (date);
datePicker.Culture = CultureInfo.GetCultureInfo ("en-GB");
Assert.Equal ("23/07/2000", datePicker.Text);
datePicker.Culture = CultureInfo.GetCultureInfo ("pl-PL");
Assert.Equal ("23.07.2000", datePicker.Text);
// Deafult date format for en-US is M/d/yyyy but we are using StandardizeDateFormat method
// to convert it to the format that has 2 digits for month and day.
datePicker.Culture = CultureInfo.GetCultureInfo ("en-US");
Assert.Equal ("07/23/2000", datePicker.Text);
}
[Fact]
public void DatePicker_Initialize_ShouldSetCurrentDate ()
{
var datePicker = new DatePicker ();
Assert.Equal (DateTime.Now.Date.Day, datePicker.Date.Day);
Assert.Equal (DateTime.Now.Date.Month, datePicker.Date.Month);
Assert.Equal (DateTime.Now.Date.Year, datePicker.Date.Year);
}
[Fact]
public void DatePicker_SetDate_ShouldChangeText ()
{
var datePicker = new DatePicker { Culture = CultureInfo.GetCultureInfo ("en-GB") };
var newDate = new DateTime (2024, 1, 15);
string format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
datePicker.Date = newDate;
Assert.Equal (newDate.ToString (format), datePicker.Text);
}
[Fact]
[AutoInitShutdown]
public void DatePicker_ShouldNot_SetDateOutOfRange_UsingNextMonthButton ()
{
var date = new DateTime (9999, 11, 15);
var datePicker = new DatePicker (date);
Application.Top.Add (datePicker);
Application.Begin (Application.Top);
// Set focus to next month button
datePicker.FocusNext ();
datePicker.FocusNext ();
datePicker.FocusNext ();
// Change month to December
Assert.True (datePicker.NewKeyDownEvent (Key.Enter));
Assert.Equal (12, datePicker.Date.Month);
// Date should not change as next month button is disabled
Assert.False (datePicker.NewKeyDownEvent (Key.Enter));
Assert.Equal (12, datePicker.Date.Month);
}
[Fact]
[AutoInitShutdown]
public void DatePicker_ShouldNot_SetDateOutOfRange_UsingPreviousMonthButton ()
{
var date = new DateTime (1, 2, 15);
var datePicker = new DatePicker (date);
// Move focus to previous month button
Application.Top.Add (datePicker);
Application.Begin (Application.Top);
// set focus to the previous month button
datePicker.FocusNext ();
datePicker.FocusNext ();
// Change month to January
Assert.True (datePicker.NewKeyDownEvent (Key.Enter));
Assert.Equal (1, datePicker.Date.Month);
// Date should not change as previous month button is disabled
Assert.False (datePicker.NewKeyDownEvent (Key.Enter));
Assert.Equal (1, datePicker.Date.Month);
}
}