acdream/tests/AcDream.App.Tests/UI/UiItemListScrollTests.cs
Erik 366af0c34f feat(ui): D.2b inventory finish — UiItemList clip+scroll via UiScrollable
Grid mode now drives a shared UiScrollable from its content + clips whole rows
to the panel (cells offset by -ScrollY, Visible toggled by whole-row clip,
mirroring UiText). Fill mode (toolbar single cell) unchanged. LayoutCells made
internal for tests; RowCount helper added.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 20:25:11 +02:00

54 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AcDream.App.UI;
using Xunit;
namespace AcDream.App.Tests.UI;
public sealed class UiItemListScrollTests
{
private static UiItemList Grid(int items)
{
var list = new UiItemList { Columns = 6, CellWidth = 32, CellHeight = 32, Width = 192, Height = 96 };
list.Flush(); // drop the default single cell
for (int i = 0; i < items; i++) list.AddItem(new UiItemSlot());
list.LayoutCells(); // drive the scroll model + position cells
return list;
}
[Fact]
public void RowCount_ceils_to_whole_rows()
{
Assert.Equal(0, UiItemList.RowCount(0, 6));
Assert.Equal(1, UiItemList.RowCount(1, 6));
Assert.Equal(7, UiItemList.RowCount(41, 6));
}
[Fact]
public void Grid_drives_scroll_model_from_content()
{
var list = Grid(30); // 5 rows × 32 = 160 content, 96 view
Assert.Equal(160, list.Scroll.ContentHeight);
Assert.Equal(96, list.Scroll.ViewHeight);
Assert.Equal(64, list.Scroll.MaxScroll);
Assert.True(list.Scroll.HasOverflow);
}
[Fact]
public void At_top_first_three_rows_visible_rest_clipped()
{
var list = Grid(30);
Assert.True(list.GetItem(0)!.Visible); // row 0, top 0
Assert.True(list.GetItem(12)!.Visible); // row 2, top 64 (+32 == 96)
Assert.False(list.GetItem(18)!.Visible); // row 3, top 96 (off the bottom)
}
[Fact]
public void Scrolled_one_row_shifts_window_and_clips_top_row()
{
var list = Grid(30);
list.Scroll.SetScrollY(32);
list.LayoutCells();
Assert.False(list.GetItem(0)!.Visible); // row 0 scrolled above
Assert.Equal(0f, list.GetItem(6)!.Top); // row 1 now at the view top
Assert.True(list.GetItem(18)!.Visible); // row 3 now visible
}
}