Browse Source

Tweak now-failing test.

Change the the test to check that the element is outside of the viewport, instead of asserting its exact coordinates - that's the important part.
pull/21975/head
grokys 1 month ago
parent
commit
424264402e
  1. 27
      tests/Avalonia.Controls.UnitTests/VirtualizingStackPanelTests.cs

27
tests/Avalonia.Controls.UnitTests/VirtualizingStackPanelTests.cs

@ -1,4 +1,4 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -1683,7 +1683,7 @@ namespace Avalonia.Controls.UnitTests
} }
[Fact] [Fact]
public void Focused_Container_Is_Positioned_Correctly_When_Scrolled_Past_Items_With_Different_Heights() public void Focused_Container_Is_Positioned_Outside_Viewport_When_Scrolled_Past_Items_With_Different_Heights()
{ {
using var app = App(); using var app = App();
@ -1691,7 +1691,7 @@ namespace Avalonia.Controls.UnitTests
.Select(x => new ItemWithHeight(x, x < 10 ? 10 : 50)) .Select(x => new ItemWithHeight(x, x < 10 ? 10 : 50))
.ToList(); .ToList();
var (target, _, _) = CreateTarget(items: items, itemTemplate: CanvasWithHeightTemplate); var (target, scroll, _) = CreateTarget(items: items, itemTemplate: CanvasWithHeightTemplate);
var focused = Assert.IsType<ContentPresenter>(target.ContainerFromIndex(5)); var focused = Assert.IsType<ContentPresenter>(target.ContainerFromIndex(5));
focused.Focusable = true; focused.Focusable = true;
@ -1702,18 +1702,19 @@ namespace Avalonia.Controls.UnitTests
Assert.True(target.FirstRealizedIndex > 5); Assert.True(target.FirstRealizedIndex > 5);
var firstIndex = target.FirstRealizedIndex; var firstRealized = Assert.IsType<ContentPresenter>(
var firstRealized = Assert.IsType<ContentPresenter>(target.ContainerFromIndex(firstIndex)); target.ContainerFromIndex(target.FirstRealizedIndex));
var realized = target.GetRealizedElements() focused = Assert.IsType<ContentPresenter>(target.ContainerFromIndex(5));
.Where(x => x is not null)
.Cast<Control>()
.ToList();
var estimatedSize = realized.Average(x => x.DesiredSize.Height); // The focused container's position is estimated, as it's outside the realized range.
var expectedTop = firstRealized.Bounds.Top - ((firstIndex - 5) * estimatedSize); // The estimate must never place it before the panel origin...
Assert.True(focused.Bounds.Top >= 0);
focused = Assert.IsType<ContentPresenter>(target.ContainerFromIndex(5)); // ...must keep it above the realized range rather than overlapping it...
Assert.Equal(expectedTop, focused.Bounds.Top, 3); Assert.True(focused.Bounds.Bottom <= firstRealized.Bounds.Top);
// ...and must keep it out of the viewport, so it can't appear as a ghost item.
Assert.True(focused.Bounds.Bottom <= scroll.Offset.Y);
} }
[Theory] [Theory]

Loading…
Cancel
Save