Files
Terminal.Gui/Tests/UnitTestsParallelizable/Views/DatePickerTests.cs
Copilot ed64f5773e Fixes #4282 - Migrate tests from UnitTests to UnitTests.Parallelizable (67 tests migrated + comprehensive documentation) (#4293)
* Initial plan

* Add 31 parallelizable LineCanvas unit tests

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Add 4 parallelizable Ruler unit tests

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Complete Category A migration - 35 tests migrated

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Remove duplicate tests from UnitTests after migration to Parallelizable

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Migrate 6 pure unit tests from ColorPicker and DatePicker to Parallelizable

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix duplicate test names between UnitTests and Parallelizable

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Migrate 11 Label tests to Parallelizable (52 tests total)

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix documentation: SetupFakeDriver tests CAN be parallelized

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Add comprehensive parallelization rules to documentation

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Update README and start migrating Button/CheckBox/RadioGroup tests

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Remove duplicate Button tests from UnitTests

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Migrate 5 CheckBox unit tests to Parallelizable (27 with Theory expansion)

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Migrate 4 more CheckBox tests to Parallelizable (67 tests total, 9,478 passing)

Co-authored-by: tig <585482+tig@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: Tig <tig@users.noreply.github.com>
2025-10-19 19:04:43 -06:00

67 lines
2.5 KiB
C#

using System.Globalization;
namespace Terminal.Gui.ViewsTests;
/// <summary>
/// Pure unit tests for <see cref="DatePicker"/> that don't require Application.Driver or View context.
/// These tests can run in parallel without interference.
/// </summary>
public class DatePickerTests : UnitTests.Parallelizable.ParallelizableBase
{
[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_Default_Constructor_ShouldSetCurrenDate ()
{
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_Constrctor_Now_ShouldSetCurrenDate ()
{
var datePicker = new DatePicker (DateTime.Now);
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_X_Y_Init ()
{
var datePicker = new DatePicker { Y = Pos.Center (), X = Pos.Center () };
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);
}
}