From a1b3cdc1ce4487d514f72554efbccaa4c651a280 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 6 Oct 2026 07:44:27 +0000 Subject: [PATCH] test(import): judge whole texts with the layout engine's own measure The formatted-text estimate ignored the numeral and formatting options the cells use and called a fully shown session time cut; a probe TextBlock with the same properties is measured instead. The CI screenshot shows the times whole at 1200 px. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC --- .../Import/ImportScreenSmokeTests.cs | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) 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;