tests: make the wheel-scroll check independent of font metrics
agent-review agent review: pass

On Linux the window selector already fits in the viewport, so the page
stays at offset 0 and a wheel up cannot scroll it: the test assumed a
positive offset that only Windows fonts produced. It now centres the
selector with room in both directions and checks a wheel up and down
without the selection changing.

Refs #5
This commit is contained in:
Florian Schmidt
2026-10-15 10:13:39 +02:00
parent 07a645657d
commit d477321943
+19 -4
View File
@@ -60,14 +60,29 @@ public sealed class HeadlessTests
panel.GetVisualDescendants().OfType<ComboBox>().Single().SelectedIndex = 1; panel.GetVisualDescendants().OfType<ComboBox>().Single().SelectedIndex = 1;
Assert.Contains(panel.GetVisualDescendants().OfType<TextBlock>(), t => t.Text == "Claude · Week · Fable"); Assert.Contains(panel.GetVisualDescendants().OfType<TextBlock>(), t => t.Text == "Claude · Week · Fable");
var wheelSelector = panel.GetVisualDescendants().OfType<ComboBox>().Single(); var wheelSelector = panel.GetVisualDescendants().OfType<ComboBox>().Single();
wheelSelector.BringIntoView(); Dispatcher.UIThread.RunJobs(); using (panel.CaptureRenderedFrame()) { }
wheelSelector.Focus();
var wheelViewport = panel.GetVisualDescendants().OfType<ScrollViewer>().First(); var wheelViewport = panel.GetVisualDescendants().OfType<ScrollViewer>().First();
Dispatcher.UIThread.RunJobs(); using (panel.CaptureRenderedFrame()) { }
var maximumOffset = wheelViewport.Extent.Height - wheelViewport.Viewport.Height;
const double scrollRoom = 80;
Assert.True(maximumOffset > scrollRoom * 2);
var selectorTop = wheelSelector.TranslatePoint(default, wheelViewport)!.Value.Y + wheelViewport.Offset.Y;
// BringIntoView can leave offset zero with Linux fonts. Centre the selector with room both ways.
var centredOffset = selectorTop - (wheelViewport.Viewport.Height - wheelSelector.Bounds.Height) / 2;
wheelViewport.Offset = new Vector(0, Math.Clamp(centredOffset, scrollRoom, maximumOffset - scrollRoom));
Dispatcher.UIThread.RunJobs(); wheelSelector.Focus();
foreach (var direction in new[] { 1, -1 })
{
using (panel.CaptureRenderedFrame()) { }
var selectorY = wheelSelector.TranslatePoint(default, wheelViewport)!.Value.Y;
Assert.InRange(selectorY, 0, wheelViewport.Viewport.Height - wheelSelector.Bounds.Height);
var beforeWheel = wheelViewport.Offset.Y; var beforeWheel = wheelViewport.Offset.Y;
panel.MouseWheel(wheelSelector.TranslatePoint(new Point(20, 16), panel)!.Value, new Vector(0, 1)); Assert.InRange(beforeWheel, 1, maximumOffset - 1);
panel.MouseWheel(wheelSelector.TranslatePoint(new Point(20, 16), panel)!.Value, new Vector(0, direction));
Dispatcher.UIThread.RunJobs(); Dispatcher.UIThread.RunJobs();
Assert.Equal(1, wheelSelector.SelectedIndex); Assert.Equal(1, wheelSelector.SelectedIndex);
Assert.True(wheelViewport.Offset.Y < beforeWheel); Assert.True(direction > 0 ? wheelViewport.Offset.Y < beforeWheel : wheelViewport.Offset.Y > beforeWheel,
$"Wheel {direction}: before={beforeWheel}, after={wheelViewport.Offset.Y}");
}
foreach (var segment in panel.GetVisualDescendants().OfType<ToggleButton>().Where(b => b.Classes.Contains("segment"))) foreach (var segment in panel.GetVisualDescendants().OfType<ToggleButton>().Where(b => b.Classes.Contains("segment")))
{ {
segment.Focus(); var rangeBefore = model.Range; var providerBefore = model.ProviderFilter; segment.Focus(); var rangeBefore = model.Range; var providerBefore = model.ProviderFilter;