Skip to content

Commit

Permalink
Add failing tests.
Browse files Browse the repository at this point in the history
We're not correctly handling the focused item being removed while it's scrolled outside the viewport.
  • Loading branch information
grokys committed Sep 3, 2024
1 parent 45fa70b commit 018718d
Showing 1 changed file with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,78 @@ public void Handles_Removing_Row_Range_That_Invalidates_Current_Viewport()
Assert.Equal(new Size(100, 100), target.Bounds.Size);
}

[AvaloniaFact(Timeout = 10000)]
public void Handles_Removing_Focused_Row_While_Outside_Viewport()
{
var (target, scroll, items) = CreateTarget();
var element = target.RealizedElements.ElementAt(0)!;

element.Focusable = true;
element.Focus();

// Scroll down one item.
scroll.Offset = new Vector(0, 10);
Layout(target);

// Remove the focused element.
items.RemoveAt(0);

// Scroll back to the beginning.
scroll.Offset = new Vector(0, 0);
Layout(target);

// The correct element should be shown.
Assert.Same(items[0], target.RealizedElements.ElementAt(0)!.DataContext);
}

[AvaloniaFact(Timeout = 10000)]
public void Handles_Replacing_Focused_Row_While_Outside_Viewport()
{
var (target, scroll, items) = CreateTarget();
var element = target.RealizedElements.ElementAt(0)!;

element.Focusable = true;
element.Focus();

// Scroll down one item.
scroll.Offset = new Vector(0, 10);
Layout(target);

// Replace the focused element.
items[0] = new Model { Id = 100, Title = "New Item" };

// Scroll back to the beginning.
scroll.Offset = new Vector(0, 0);
Layout(target);

// The correct element should be shown.
Assert.Same(items[0], target.RealizedElements.ElementAt(0)!.DataContext);
}

[AvaloniaFact(Timeout = 10000)]
public void Handles_Moving_Focused_Row_While_Outside_Viewport()
{
var (target, scroll, items) = CreateTarget();
var element = target.RealizedElements.ElementAt(0)!;

element.Focusable = true;
element.Focus();

// Scroll down one item.
scroll.Offset = new Vector(0, 10);
Layout(target);

// Move the focused element.
items.Move(0, items.Count - 1);

// Scroll back to the beginning.
scroll.Offset = new Vector(0, 0);
Layout(target);

// The correct element should be shown.
Assert.Same(items[0], target.RealizedElements.ElementAt(0)!.DataContext);
}

[AvaloniaFact(Timeout = 10000)]
public void Updates_Star_Column_ActualWidth()
{
Expand Down

0 comments on commit 018718d

Please sign in to comment.