mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-31 02:08:03 +01:00
* Create POC of DatePicker * Move DatePicker to dialog * Move DatePicker to separate view * Support user specified date format * Added code documentation for public API * Select day on calendar based on currently selected date * Add new constuctors for DatePicker * Fix constructors * Add month navigation buttons * Added support for user to specify a range of years in the calendar * Update default format date in unit tests * Add some more unit tests * Improve UICatalog DatePicker example * Change default date format to CultureInfo.CurrentCulture * Address code review comments * Fix DatePicker height and width * Fix crashes on 'Esc' key during open combobox * Add DatePicker to localizable strings * Generate calendar labels based on current culture * Replace Month enum with localized DateTime month names * Remove setting culture to polish (used for test purposes) * Prevent choosing not existing day from calendar * Update DatePicker layout * Handle year out of range * Make DatePicker standalone view and simplfy code and component look * Handle clicking on no exisitng days in calendar * Add missing rows to calendar * Update example in UICatalog * Dispose SubViews of DatePicker * Add case for DatePicker --------- Co-authored-by: Tig <tig@users.noreply.github.com>
55 lines
1.4 KiB
C#
55 lines
1.4 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using Terminal.Gui.Views;
|
|
using Xunit;
|
|
|
|
namespace Terminal.Gui.ViewsTests;
|
|
|
|
public class DatePickerTests {
|
|
|
|
[Fact]
|
|
public void DatePicker_SetFormat_ShouldChangeFormat ()
|
|
{
|
|
var datePicker = new DatePicker {
|
|
Format = "dd/MM/yyyy"
|
|
};
|
|
Assert.Equal ("dd/MM/yyyy", datePicker.Format);
|
|
}
|
|
|
|
[Fact]
|
|
public void DatePicker_Initialize_ShouldSetCurrentDate ()
|
|
{
|
|
var datePicker = new DatePicker ();
|
|
var format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
|
|
Assert.Equal (DateTime.Now.ToString (format), datePicker.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void DatePicker_SetDate_ShouldChangeText ()
|
|
{
|
|
var datePicker = new DatePicker ();
|
|
var newDate = new DateTime (2024, 1, 15);
|
|
var format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
|
|
|
|
datePicker.Date = newDate;
|
|
Assert.Equal (newDate.ToString (format), datePicker.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void DatePicker_ShowDatePickerDialog_ShouldChangeDate ()
|
|
{
|
|
var datePicker = new DatePicker ();
|
|
var format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
|
|
var originalDate = datePicker.Date;
|
|
|
|
datePicker.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked, X = 4, Y = 1 });
|
|
|
|
var newDate = new DateTime (2024, 2, 20);
|
|
datePicker.Date = newDate;
|
|
|
|
Assert.Equal (newDate.ToString (format), datePicker.Text);
|
|
|
|
datePicker.Date = originalDate;
|
|
}
|
|
}
|