using System.Xml.Linq; using AtomUI.Desktop.Controls.CalendarView; using AtomUI.Desktop.Controls.CalendarView.Infrastructure; using AtomUI.Desktop.Controls.CalendarView.State; using AtomUI.Desktop.Controls.Primitives; using AtomUI.Localization; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Metadata; using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Threading; using Avalonia.VisualTree; using Shouldly; using Xunit; using AvaloniaGrid = Avalonia.Controls.Grid; using AvaloniaWindow = Avalonia.Controls.Window; using PickerCalendar = AtomUI.Desktop.Controls.CalendarView.Calendar; using PickerCalendarMode = AtomUI.Desktop.Controls.CalendarView.CalendarMode; using PickerCalendarButton = AtomUI.Desktop.Controls.CalendarView.CalendarButton; using PickerCalendarItem = AtomUI.Desktop.Controls.CalendarView.CalendarItem; using PickerCalendarDayButton = AtomUI.Desktop.Controls.CalendarView.CalendarDayButton; using PickerDualMonthCalendarItem = AtomUI.Desktop.Controls.CalendarView.DualMonthCalendarItem; namespace AtomUI.Desktop.Controls.Tests.DatePickers; public class CalendarViewStateTests { static CalendarViewStateTests() { AvaloniaTestApp.EnsureInitialized(); } [Fact] public void CalendarItem_Declares_TemplateParts_Used_By_Default_Themes() { RunOnUIThread(() => { var expectedParts = new Dictionary { ["PART_HeaderButton"] = typeof(HeadTextButton), ["PART_HeaderLayout"] = typeof(Panel), ["PART_MonthViewLayout"] = typeof(UniformGrid), ["PART_MonthView"] = typeof(AvaloniaGrid), ["PART_PreviousButton"] = typeof(IconButton), ["PART_PreviousMonthButton"] = typeof(IconButton), ["PART_NextButton"] = typeof(IconButton), ["PART_NextMonthButton"] = typeof(IconButton), ["PART_YearView"] = typeof(AvaloniaGrid) }; AssertTemplateParts(typeof(PickerCalendarItem), expectedParts); }); } [Fact] public void DualMonthCalendarItem_Declares_Secondary_TemplateParts() { RunOnUIThread(() => { var expectedParts = new Dictionary { ["PART_SecondaryMonthView"] = typeof(AvaloniaGrid), ["PART_SecondaryHeaderButton"] = typeof(HeadTextButton), ["PART_SecondaryPreviousButton"] = typeof(IconButton), ["PART_SecondaryPreviousMonthButton"] = typeof(IconButton), ["PART_SecondaryNextButton"] = typeof(IconButton), ["PART_SecondaryNextMonthButton"] = typeof(IconButton), ["PART_YearViewLayout"] = typeof(UniformGrid), ["PART_SecondaryYearView"] = typeof(AvaloniaGrid) }; AssertTemplateParts(typeof(PickerDualMonthCalendarItem), expectedParts); }); } [Fact] public void DualMonthRangeCalendar_Theme_BasedOn_CalendarTheme() { var source = ReadRepoFile("src/AtomUI.Desktop.Controls/DatePicker/Themes/CalendarView/DualMonthRangeCalendarTheme.axaml"); source.ShouldContain(""); source.ShouldNotContain(""); } [Theory] [InlineData("src/AtomUI.Desktop.Controls/DatePicker/Themes/CalendarView/CalendarDayButtonTheme.axaml")] [InlineData("src/AtomUI.Desktop.Controls/DatePicker/Themes/CalendarView/CalendarButtonTheme.axaml")] public void Calendar_Cell_Themes_Define_Explicit_Disabled_Visuals(string relativePath) { var source = ReadRepoFile(relativePath); var document = XDocument.Parse(source); var avaloniaNamespace = XNamespace.Get("https://github.com/avaloniaui"); var disabledStyle = document.Descendants(avaloniaNamespace + "Style") .Single(style => (string?)style.Attribute("Selector") == "^:disabled"); var disabledBackgroundStyle = disabledStyle.Elements(avaloniaNamespace + "Style") .Single(style => (string?)style.Attribute("Selector") == "^ /template/ Border#DisabledBackground"); source.ShouldContain("