* Initial plan * Add comprehensive tests for 5 controls: Avatar, Clock, ClockTicks, AspectRatioLayout, AspectRatioLayoutItem Co-authored-by: rabbitism <14807942+rabbitism@users.noreply.github.com> * Complete comprehensive headless tests for all 10 controls - added 72 more tests Co-authored-by: rabbitism <14807942+rabbitism@users.noreply.github.com> * Add requested test cases for MultiComboBox and TreeComboBox - ItemsSource, Remove, Clear, hierarchical data Co-authored-by: rabbitism <14807942+rabbitism@users.noreply.github.com> * test: open dropdown to trigger materialization. * test: set CurrentCulture to en-US for calendar view tests --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rabbitism <14807942+rabbitism@users.noreply.github.com> Co-authored-by: rabbitism <dongbin@irihi.tech>
97 lines
3.1 KiB
C#
97 lines
3.1 KiB
C#
using System.Globalization;
|
|
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Headless;
|
|
using Avalonia.Headless.XUnit;
|
|
using Avalonia.Input;
|
|
using Ursa.Controls;
|
|
|
|
namespace HeadlessTest.Ursa.Controls.DateTimePicker;
|
|
|
|
public class CalendarYearButtonTests
|
|
{
|
|
[AvaloniaFact]
|
|
public void SetContext_YearMode_SetsContentToAbbreviatedMonthName()
|
|
{
|
|
CultureInfo.CurrentCulture = new CultureInfo("en-US");
|
|
var button = new CalendarYearButton();
|
|
var context = new CalendarContext(null, 5);
|
|
button.SetContext(CalendarViewMode.Year, context);
|
|
Assert.Equal("May", button.Content);
|
|
}
|
|
|
|
[AvaloniaFact]
|
|
public void SetContext_YearMode_SetsContentToAbbreviatedMonthName_Chinese()
|
|
{
|
|
CultureInfo.CurrentCulture = new CultureInfo("zh-CN");
|
|
var button = new CalendarYearButton();
|
|
var context = new CalendarContext(null, 5);
|
|
button.SetContext(CalendarViewMode.Year, context);
|
|
Assert.Equal("5月", button.Content);
|
|
}
|
|
|
|
[AvaloniaFact]
|
|
public void SetContext_DecadeMode_SetsContentToYear()
|
|
{
|
|
var button = new CalendarYearButton();
|
|
var context = new CalendarContext(2023);
|
|
button.SetContext(CalendarViewMode.Decade, context);
|
|
Assert.Equal("2023", button.Content);
|
|
}
|
|
|
|
[AvaloniaFact]
|
|
public void SetContext_CenturyMode_SetsContentToYearRange()
|
|
{
|
|
var button = new CalendarYearButton();
|
|
var context = new CalendarContext(null, null, 1900, 1999);
|
|
button.SetContext(CalendarViewMode.Century, context);
|
|
Assert.Equal("1900-1999", button.Content);
|
|
}
|
|
|
|
[AvaloniaFact]
|
|
public void SetContext_InvalidYear_DisablesButton()
|
|
{
|
|
var button = new CalendarYearButton();
|
|
var context = new CalendarContext(null, null, -1);
|
|
button.SetContext(CalendarViewMode.Decade, context);
|
|
Assert.False(button.IsEnabled);
|
|
}
|
|
|
|
[AvaloniaFact]
|
|
public void SetContext_Month_Mode_DisablesButton()
|
|
{
|
|
var button = new CalendarYearButton();
|
|
var context = new CalendarContext(1, 1);
|
|
button.SetContext(CalendarViewMode.Month, context);
|
|
Assert.False(button.IsEnabled);
|
|
}
|
|
|
|
[AvaloniaFact]
|
|
public void OnPointerReleased_RaisesItemSelectedEvent()
|
|
{
|
|
|
|
var button = new CalendarYearButton();
|
|
var context = new CalendarContext(2023, 5);
|
|
button.SetContext(CalendarViewMode.Year, context);
|
|
int eventRaised = 0;
|
|
CalendarContext? eventContext = null;
|
|
void OnItemSelected( object? sender, CalendarYearButtonEventArgs args)
|
|
{
|
|
eventRaised++;
|
|
eventContext = args.Context;
|
|
}
|
|
button.ItemSelected += OnItemSelected;
|
|
Window window = new Window();
|
|
window.Content = button;
|
|
window.Show();
|
|
window.MouseUp(new Point(10, 10), MouseButton.Left);
|
|
Assert.Equal(1, eventRaised);
|
|
Assert.Equal(context, eventContext);
|
|
button.ItemSelected -= OnItemSelected;
|
|
eventContext = null;
|
|
window.MouseUp(new Point(10, 10), MouseButton.Left);
|
|
Assert.Null(eventContext);
|
|
Assert.Equal(1, eventRaised);
|
|
|
|
}
|
|
} |