Skip to content

Commit

Permalink
test: Add runtime test for NumberBox NumberFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
morning4coffe-dev committed Oct 23, 2024
1 parent e711b22 commit 5bb4755
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Uno.UI.RuntimeTests.Helpers;
using Windows.Globalization.NumberFormatting;
using static Private.Infrastructure.TestServices;

#if WINAPPSDK
Expand Down Expand Up @@ -54,5 +55,34 @@ public async Task When_NB_Fluent_And_Theme_Changed()

Assert.AreEqual(lightThemeForeground, (placeholderTextContentPresenter.Foreground as SolidColorBrush)?.Color);
}

[TestMethod]
public async Task NumberBox_Should_Apply_CustomFormatter()
{
var numberBox = new NumberBox();

WindowHelper.WindowContent = numberBox;
await WindowHelper.WaitForLoaded(numberBox);

var customFormatter = new CustomNumberFormatter();
numberBox.NumberFormatter = customFormatter;

numberBox.Value = 123.456;
var formattedText = numberBox.Text;

Assert.AreEqual("123.46 units", formattedText);
}
}

internal class CustomNumberFormatter : INumberFormatter2, INumberParser
{
public string FormatDouble(double value) => value.ToString("0.00") + " units";
public double? ParseDouble(string text) => throw new NotImplementedException();

public string FormatInt(long value) => throw new NotImplementedException();
public string FormatUInt(ulong value) => throw new NotImplementedException();

public long? ParseInt(string text) => throw new NotImplementedException();
public ulong? ParseUInt(string text) => throw new NotImplementedException();
}
#endif

0 comments on commit 5bb4755

Please sign in to comment.