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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
1 file changed
+23
-8
@@ -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<ListBoxItem> DeviceItems(ScreenSmokeTests.SampleApp app) =>
|
||||
app.FindAll<ListBoxItem>().Where(i => i.IsVisible && i.DataContext is ImportSource);
|
||||
|
||||
/// <summary>The text is shown whole: its formatted width fits the width the layout gave it.</summary>
|
||||
/// <summary>
|
||||
/// 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).
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user