Skip to content

[Testing] Feature Matrix UITest Cases for DatePicker Control #30159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public override string ToString()
new GalleryPageFactory(() => new CarouselViewCoreGalleryPage(), "CarouselView Gallery"),
new GalleryPageFactory(() => new CheckBoxCoreGalleryPage(), "CheckBox Gallery"),
new GalleryPageFactory(() => new CollectionViewCoreGalleryPage(), "CollectionView Gallery"),
new GalleryPageFactory(() => new DatePickerControlPage(), "Date Picker Feature Matrix"),
new GalleryPageFactory(() => new DatePickerCoreGalleryPage(), "Date Picker Gallery"),
new GalleryPageFactory(() => new EditorCoreGalleryPage(), "Editor Gallery"),
new GalleryPageFactory(() => new EntryCoreGalleryPage(), "Entry Gallery"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Maui.Controls.Sample"
x:Class="Maui.Controls.Sample.DatePickerMainControlPage"
x:DataType="local:DatePickerViewModel"
Title="DatePickerControlPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Options"
Clicked="NavigateToOptionsPage_Clicked"
AutomationId="Options"/>
</ContentPage.ToolbarItems>
<VerticalStackLayout
Spacing="20">
<VerticalStackLayout x:Name="DatePickerLayout"
Padding="20,100,20,100">
<DatePicker AutomationId="DatePickerControl"
CharacterSpacing="{Binding CharacterSpacing}"
Date="{Binding Date}"
DateSelected="OnDateSelected"
FlowDirection="{Binding FlowDirection}"
Format="{Binding Format}"
FontAttributes="{Binding FontAttributes}"
FontFamily="{Binding FontFamily}"
FontSize="{Binding FontSize}"
IsEnabled="{Binding IsEnabled}"
IsVisible="{Binding IsVisible}"
MinimumDate="{Binding MinimumDate}"
MaximumDate="{Binding MaximumDate}"
Shadow="{Binding Shadow}"
TextColor="{Binding TextColor}"/>
</VerticalStackLayout>

<Label Text="DateSelected Event"
HorizontalOptions="Center"/>
<HorizontalStackLayout HorizontalOptions="Center">
<Label Text="New Date: "/>
<Label x:Name="NewDateSelectedLabel"
AutomationId="NewDateSelectedLabel"/>
</HorizontalStackLayout>
<HorizontalStackLayout HorizontalOptions="Center">
<Label Text="Old Date: "/>
<Label x:Name="OldDateSelectedLabel"
AutomationId="OldDateSelectedLabel"/>
</HorizontalStackLayout>

<Label Text="Culture Format Display"
HorizontalOptions="Center"
FontAttributes="Bold"
Margin="0,10,0,0"/>
<Label x:Name="CultureFormatLabel"
HorizontalOptions="Center"
AutomationId="CultureFormatLabel"
Margin="0,0,0,10"/>
</VerticalStackLayout>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System.Globalization;

namespace Maui.Controls.Sample;

public class DatePickerControlPage : NavigationPage
{
private DatePickerViewModel _viewModel;
public DatePickerControlPage()
{
_viewModel = new DatePickerViewModel();
PushAsync(new DatePickerMainControlPage(_viewModel));
}
}

public partial class DatePickerMainControlPage : ContentPage
{
private DatePickerViewModel _viewModel;

public DatePickerMainControlPage(DatePickerViewModel viewModel)
{
InitializeComponent();
_viewModel = viewModel;
BindingContext = _viewModel;

// Display initial culture formatting information
DisplayCultureSpecificDate(_viewModel.Date, _viewModel.Culture);
}

protected override void OnAppearing()
{
base.OnAppearing();
// Refresh culture display when returning to the page
DisplayCultureSpecificDate(_viewModel.Date, _viewModel.Culture);
}

private async void NavigateToOptionsPage_Clicked(object sender, EventArgs e)
{
// Reset culture to default when navigating to options page
_viewModel.Culture = System.Globalization.CultureInfo.CurrentCulture;

BindingContext = _viewModel = new DatePickerViewModel();
ReinitializeDatePicker();
await Navigation.PushAsync(new DatePickerOptionsPage(_viewModel));
}

private void ReinitializeDatePicker()
{
DatePickerLayout.Children.Clear();
var datePickerControl = new DatePicker
{
AutomationId = "DatePickerControl"
};

datePickerControl.SetBinding(DatePicker.CharacterSpacingProperty, new Binding(nameof(DatePickerViewModel.CharacterSpacing)));
datePickerControl.SetBinding(DatePicker.DateProperty, new Binding(nameof(DatePickerViewModel.Date)));
datePickerControl.DateSelected += OnDateSelected;
datePickerControl.SetBinding(DatePicker.FlowDirectionProperty, new Binding(nameof(DatePickerViewModel.FlowDirection)));
datePickerControl.SetBinding(DatePicker.FormatProperty, new Binding(nameof(DatePickerViewModel.Format)));
datePickerControl.SetBinding(DatePicker.FontAttributesProperty, new Binding(nameof(DatePickerViewModel.FontAttributes)));
datePickerControl.SetBinding(DatePicker.FontFamilyProperty, new Binding(nameof(DatePickerViewModel.FontFamily)));
datePickerControl.SetBinding(DatePicker.FontSizeProperty, new Binding(nameof(DatePickerViewModel.FontSize)));
datePickerControl.SetBinding(DatePicker.IsEnabledProperty, new Binding(nameof(DatePickerViewModel.IsEnabled)));
datePickerControl.SetBinding(DatePicker.IsVisibleProperty, new Binding(nameof(DatePickerViewModel.IsVisible)));
datePickerControl.SetBinding(DatePicker.MinimumDateProperty, new Binding(nameof(DatePickerViewModel.MinimumDate)));
datePickerControl.SetBinding(DatePicker.MaximumDateProperty, new Binding(nameof(DatePickerViewModel.MaximumDate)));
datePickerControl.SetBinding(DatePicker.ShadowProperty, new Binding(nameof(DatePickerViewModel.Shadow)));
datePickerControl.SetBinding(DatePicker.TextColorProperty, new Binding(nameof(DatePickerViewModel.TextColor)));

// Set culture directly and update when the view model's culture changes
datePickerControl.PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(DatePicker.Date))
{
DisplayCultureSpecificDate(datePickerControl.Date, _viewModel.Culture);
}
};
_viewModel.PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(DatePickerViewModel.Culture))
{
DisplayCultureSpecificDate(datePickerControl.Date, _viewModel.Culture);
}
};

DatePickerLayout.Children.Add(datePickerControl);
}

private void DisplayCultureSpecificDate(DateTime date, CultureInfo culture)
{
if (culture != null)
{
// Apply the culture to the current thread
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;

// Set default culture for new threads
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
}

CultureFormatLabel.Text = $"Culture: {culture.Name}, Date: {date.ToString(culture)}";
}

public void OnDateSelected(object sender, DateChangedEventArgs e)
{
if (e.OldDate.Date != DateTime.Now.Date && e.NewDate != e.OldDate)
{
OldDateSelectedLabel.Text = e.OldDate.ToString();
NewDateSelectedLabel.Text = e.NewDate.ToString();
}
}
}
Loading
Loading