- Rename UiChatInput → UiField (UIElement_Field, RegisterElementClass(3) @ :126190); update doc to cite retail's CatchDroppedItem/MouseOverTop drag-drop hooks for future item windows. BackgroundColor default → transparent (controller sets the translucent 0.35α value explicitly, matching UiText pattern). - Register Type 3 in DatWidgetFactory.Create: `3 => new UiField()`. - ChatWindowController.Bind (Variant B): factory now builds 0x10000016 as an invisible UiText placeholder (Type 12); Bind removes that placeholder via FindElement(InputId).Parent.RemoveChild and places a UiField at the same rect. Result: exactly ONE input widget in the input bar, no stray UiText duplicate. - Input property type changed from UiChatInput to UiField; GameWindow.cs:1861 UiField.Keyboard assignment compiles unchanged (field exists). - Tests: UiChatInputTests → UiFieldTests (class + all ctor refs renamed); DatWidgetFactoryTests: new Type3_Field_MakesUiField test; ChatWindowControllerTests: updated stale "skipped by factory" comments; LayoutConformanceTests: updated VitalsTree_ChromeCornerHasExpectedSprite — Type-3 chrome-corner elements are now UiField (sprite rendering for Type-3 dat image elements is a known limitation, tracked for post-Task-8 UiField.BackgroundSprite follow-up). - Full suite: 404 passed, 2 skipped, 0 failed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
72 lines
2 KiB
C#
72 lines
2 KiB
C#
using AcDream.App.UI;
|
|
using Xunit;
|
|
|
|
namespace AcDream.App.Tests.UI;
|
|
|
|
public class UiFieldTests
|
|
{
|
|
[Fact]
|
|
public void InsertChar_AdvancesCaret()
|
|
{
|
|
var input = new UiField();
|
|
input.InsertChar('h'); input.InsertChar('i');
|
|
Assert.Equal("hi", input.Text);
|
|
Assert.Equal(2, input.CaretPos);
|
|
}
|
|
|
|
[Fact]
|
|
public void Backspace_DeletesBeforeCaret()
|
|
{
|
|
var input = new UiField();
|
|
foreach (var c in "abc") input.InsertChar(c);
|
|
input.MoveCaret(-1);
|
|
input.Backspace();
|
|
Assert.Equal("ac", input.Text);
|
|
Assert.Equal(1, input.CaretPos);
|
|
}
|
|
|
|
[Fact]
|
|
public void Submit_FiresCallback_ClearsText_PushesHistory()
|
|
{
|
|
string? sent = null;
|
|
var input = new UiField { OnSubmit = t => sent = t };
|
|
foreach (var c in "hello") input.InsertChar(c);
|
|
input.Submit();
|
|
Assert.Equal("hello", sent);
|
|
Assert.Equal("", input.Text);
|
|
Assert.Equal(0, input.CaretPos);
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptySubmit_DoesNotFire()
|
|
{
|
|
int n = 0;
|
|
var input = new UiField { OnSubmit = _ => n++ };
|
|
input.Submit();
|
|
Assert.Equal(0, n);
|
|
}
|
|
|
|
[Fact]
|
|
public void History_UpDownBrowsesPreviousSubmissions()
|
|
{
|
|
var input = new UiField { OnSubmit = _ => {} };
|
|
foreach (var c in "first") input.InsertChar(c); input.Submit();
|
|
foreach (var c in "second") input.InsertChar(c); input.Submit();
|
|
input.HistoryPrev();
|
|
Assert.Equal("second", input.Text);
|
|
input.HistoryPrev();
|
|
Assert.Equal("first", input.Text);
|
|
input.HistoryNext();
|
|
Assert.Equal("second", input.Text);
|
|
input.HistoryNext();
|
|
Assert.Equal("", input.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void History_CapsAt100()
|
|
{
|
|
var input = new UiField { OnSubmit = _ => {} };
|
|
for (int i = 0; i < 150; i++) { input.InsertChar('x'); input.Submit(); }
|
|
Assert.True(input.HistoryCount <= 100);
|
|
}
|
|
}
|