Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.ComponentModel;
using System.Threading.Tasks;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using Microsoft.UI.Xaml.Controls;
using Xunit;
using WSolidColorBrush = Microsoft.UI.Xaml.Media.SolidColorBrush;

namespace Microsoft.Maui.DeviceTests;

public partial class DatePickerTests
{
[Fact]
[Description("The DatePicker Text and Icon Color should work properly on PointerOver")]
public async Task DatePickerTextAndIconColorShouldWorkProperlyOnPointerOver()
{
SetupBuilder();

var datePicker = new Controls.DatePicker
{
TextColor = Colors.Red
};
var expectedValue = datePicker.TextColor;

var handler = await CreateHandlerAsync<DatePickerHandler>(datePicker);
var platformView = GetPlatformControl(handler);

await InvokeOnMainThreadAsync(() =>
{
var foregroundPointerOverBrush = platformView.Resources["CalendarDatePickerTextForegroundPointerOver"] as WSolidColorBrush;
var foregroundPointerOverColor = foregroundPointerOverBrush.Color.ToColor();
Assert.Equal(expectedValue, foregroundPointerOverColor);

var glyphForegroundPointerOverBrush = platformView.Resources["CalendarDatePickerCalendarGlyphForegroundPointerOver"] as WSolidColorBrush;
var glyphForegroundPointerOverColor = glyphForegroundPointerOverBrush.Color.ToColor();
Assert.Equal(expectedValue, glyphForegroundPointerOverColor);
});
}

static CalendarDatePicker GetPlatformControl(DatePickerHandler handler) =>
handler.PlatformView;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;

namespace Microsoft.Maui.DeviceTests;

[Category(TestCategory.DatePicker)]
public partial class DatePickerTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
EnsureHandlerCreated(builder =>
{
builder.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler<DatePicker, DatePickerHandler>();
});
});
}
}
1 change: 1 addition & 0 deletions src/Controls/tests/DeviceTests/TestCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static class TestCategory
public const string CollectionView = "CollectionView";
public const string Compatibility = "Compatibility";
public const string ContentView = "ContentView";
public const string DatePicker = nameof(DatePicker);
public const string Dispatcher = "Dispatcher";
public const string Editor = "Editor";
public const string Element = "Element";
Expand Down
31 changes: 31 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue22987.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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"
x:Class="Maui.Controls.Sample.Issues.Issue22987">
<ContentPage.Resources>
<Style TargetType="DatePicker">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal">
<VisualState.Setters>
<Setter Property="TextColor" Value="white" />
</VisualState.Setters>
</VisualState>

<VisualState Name="PointerOver">
<VisualState.Setters>
<Setter Property="TextColor" Value="yellow" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
</ContentPage.Resources>

<VerticalStackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Label Text="DatePicker" AutomationId="Label"/>
<DatePicker BackgroundColor="Black" Date="01/15/2025" />
</VerticalStackLayout>
</ContentPage>
10 changes: 10 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue22987.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 22987, "DatePicker Color Icon", PlatformAffected.UWP)]
public partial class Issue22987 : ContentPage
{
public Issue22987()
{
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#if TEST_FAILS_ON_WINDOWS && TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_IOS
// In MacCatalyst, DatePicker Text color property is not working MacOS https://github.com/dotnet/maui/issues/20904
// In Windows, Once this PR https://github.com/dotnet/maui/pull/27477 merged, we can implement the MoveCursor and enable the test
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue22987 : _IssuesUITest
{
public Issue22987(TestDevice device) : base(device) { }

public override string Issue => "DatePicker Color Icon";

[Test]
[Category(UITestCategories.DatePicker)]
public void DatePickerTextandIconColorShouldWorkProperlyOnPointerOver()
{
App.WaitForElement("Label");

//need to include something like a MovePointer and MovePointerToCoordinate methods for hovering.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have done tests with different approaches:

Using the Hover command https://github.com/appium/appium-windows-driver?tab=readme-ov-file#windows-hover is not available in the used version:

 An exception of type 'System.NotImplementedException' occurred in WebDriver.dll but was not handled in user code
Unknown windows command 'hover'. Only startRecordingScreen,stopRecordingScreen,deleteFile,deleteFolder commands are supported.

Trying to move the cursor fails because using PointerKind.Mouse:
OpenQA.Selenium.WebDriverException: 'Currently only pen and touch pointer input source types are supported'

Can give a way to move the cursor using Win32, but want to test more options.

So, for now, can avoid the test, or use a Device Test to verify the color in the added resources.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your response. I have looked into the device test for the DatePicker hovering test case but couldn't find any relevant references for it. Could you please share any related references for hovering testcase if available, or can we avoid this test for now? @jsuarezruiz

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @mattleibow has a PR here that provides this behavior

#27477


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending snapshot on Windows:
image
Could you commit it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image is incorrect. I have restricted the test for now. Once implementation PR #27477 is merged, we can add MoveCursor and enable the test. @jsuarezruiz

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

VerifyScreenshot();
}
}
#endif
10 changes: 9 additions & 1 deletion src/Core/src/Platform/Windows/DatePickerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,16 @@ public static void UpdateTextColor(this CalendarDatePicker platformDatePicker, I
static readonly string[] TextColorResourceKeys =
{
"CalendarDatePickerTextForeground",
"CalendarDatePickerTextForegroundPointerOver",
"CalendarDatePickerTextForegroundPressed",
"CalendarDatePickerTextForegroundDisabled",
"CalendarDatePickerTextForegroundSelected"
"CalendarDatePickerTextForegroundSelected",

// below resource keys are used for the calendar icon
"CalendarDatePickerCalendarGlyphForeground",
"CalendarDatePickerCalendarGlyphForegroundPointerOver",
"CalendarDatePickerCalendarGlyphForegroundPressed",
"CalendarDatePickerCalendarGlyphForegroundDisabled",
};

// TODO NET8 add to public API
Expand Down