diff --git a/tests/Titano.App.Tests/Import/ImportScreenSmokeTests.cs b/tests/Titano.App.Tests/Import/ImportScreenSmokeTests.cs index 55835471..ffbd140a 100644 --- a/tests/Titano.App.Tests/Import/ImportScreenSmokeTests.cs +++ b/tests/Titano.App.Tests/Import/ImportScreenSmokeTests.cs @@ -1,4 +1,3 @@ -using System.Globalization; using System.Windows; using System.Windows.Automation; using System.Windows.Controls; @@ -277,18 +276,34 @@ public sealed class ImportScreenSmokeTests private static IEnumerable DeviceItems(ScreenSmokeTests.SampleApp app) => app.FindAll().Where(i => i.IsVisible && i.DataContext is ImportSource); - /// The text is shown whole: its formatted width fits the width the layout gave it. + /// + /// The text is shown whole: a copy with the same font, numerals and padding, measured by the same layout engine, + /// needs no more room than the layout gave the shown one (a formatted-text estimate differs by a few pixels). + /// private static bool Fits(TextBlock text) { - var typeface = new Typeface(text.FontFamily, text.FontStyle, text.FontWeight, text.FontStretch); - var formatted = new FormattedText(text.Text, CultureInfo.CurrentUICulture, text.FlowDirection, typeface, text.FontSize, Brushes.Black, - VisualTreeHelper.GetDpi(text).PixelsPerDip); + var probe = new TextBlock + { + Text = text.Text, + FontFamily = text.FontFamily, + FontSize = text.FontSize, + FontStyle = text.FontStyle, + FontWeight = text.FontWeight, + FontStretch = text.FontStretch, + FlowDirection = text.FlowDirection, + Language = text.Language, + Padding = text.Padding, + TextWrapping = text.TextWrapping, + }; + System.Windows.Documents.Typography.SetNumeralAlignment(probe, System.Windows.Documents.Typography.GetNumeralAlignment(text)); + TextOptions.SetTextFormattingMode(probe, TextOptions.GetTextFormattingMode(text)); if (text.TextWrapping != TextWrapping.NoWrap) { - formatted.MaxTextWidth = System.Math.Max(1, text.ActualWidth - text.Padding.Left - text.Padding.Right + 1); - return formatted.Height <= text.ActualHeight + 0.5; + probe.Measure(new Size(text.ActualWidth, double.PositiveInfinity)); + return probe.DesiredSize.Height <= text.ActualHeight + 0.5; } - return formatted.WidthIncludingTrailingWhitespace <= text.ActualWidth - text.Padding.Left - text.Padding.Right + 1; + probe.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); + return probe.DesiredSize.Width <= text.ActualWidth + 1; } private static double Left(ScreenSmokeTests.SampleApp app, FrameworkElement element) => element.TranslatePoint(new Point(0, 0), View(app)).X;