42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using AcDream.App.UI;
|
|
using Xunit;
|
|
|
|
namespace AcDream.App.Tests.UI;
|
|
|
|
public class DragDropSpineTests
|
|
{
|
|
// A spy handler used across the spine tests.
|
|
private sealed class SpyHandler : IItemListDragHandler
|
|
{
|
|
public bool AcceptResult = true;
|
|
public (UiItemList list, UiItemSlot cell, ItemDragPayload payload)? LastOver;
|
|
public (UiItemList list, UiItemSlot cell, ItemDragPayload payload)? LastDrop;
|
|
|
|
public bool OnDragOver(UiItemList list, UiItemSlot cell, ItemDragPayload p)
|
|
{ LastOver = (list, cell, p); return AcceptResult; }
|
|
|
|
public void HandleDropRelease(UiItemList list, UiItemSlot cell, ItemDragPayload p)
|
|
{ LastDrop = (list, cell, p); }
|
|
}
|
|
|
|
[Fact]
|
|
public void Payload_holdsAllFields()
|
|
{
|
|
var src = new UiItemSlot();
|
|
var p = new ItemDragPayload(0x5001u, ItemDragSource.ShortcutBar, 3, src);
|
|
Assert.Equal(0x5001u, p.ObjId);
|
|
Assert.Equal(ItemDragSource.ShortcutBar, p.SourceKind);
|
|
Assert.Equal(3, p.SourceSlot);
|
|
Assert.Same(src, p.SourceCell);
|
|
}
|
|
|
|
[Fact]
|
|
public void UiItemList_registerDragHandler_roundtrips()
|
|
{
|
|
var list = new UiItemList(_ => (0u, 0, 0));
|
|
Assert.Null(list.DragHandler);
|
|
var h = new SpyHandler();
|
|
list.RegisterDragHandler(h);
|
|
Assert.Same(h, list.DragHandler);
|
|
}
|
|
}
|