Files
HellionChat/HellionChat/SelfTests/TypingIpcStateStep.cs
T

74 lines
2.2 KiB
C#

using Dalamud.Bindings.ImGui;
using Dalamud.Plugin.SelfTest;
namespace HellionChat.SelfTests;
internal sealed class TypingIpcStateStep : ISelfTestStep
{
private readonly Plugin _plugin;
public TypingIpcStateStep(Plugin plugin)
{
_plugin = plugin;
}
public string Name => "Hellion Chat - TypingIpc state reflects input bar";
public SelfTestStepResult RunStep()
{
// /xlperf typically runs without MainWindow open. TypingIpc.BuildState gates
// InputFocused on MainWindow.IsOpen (stale-state guard); without this setup
// InputFocused would be false regardless of the hook. Restore in finally so
// the test leaves no UI side-effect.
var initialMainWindowOpen = _plugin.MainWindow.IsOpen;
if (!initialMainWindowOpen)
{
_plugin.MainWindow.Toggle();
}
// Snapshot pending so we restore in-flight user input verbatim.
var initialPendingMessage = _plugin.InputBar.PendingMessage;
_plugin.InputBar.TestSetPendingMessageForSelfTest("hello");
_plugin.InputBar.TestSetFocusedForSelfTest(true);
try
{
var state = _plugin.TypingIpc.GetState();
if (!state.HasText)
{
ImGui.Text("HasText should be true");
return SelfTestStepResult.Fail;
}
if (!state.IsTyping)
{
ImGui.Text("IsTyping should be true");
return SelfTestStepResult.Fail;
}
if (state.TextLength != 5)
{
ImGui.Text($"TextLength should be 5, got {state.TextLength}");
return SelfTestStepResult.Fail;
}
if (!state.InputFocused)
{
ImGui.Text("InputFocused should be true");
return SelfTestStepResult.Fail;
}
return SelfTestStepResult.Pass;
}
finally
{
_plugin.InputBar.TestSetPendingMessageForSelfTest(initialPendingMessage);
_plugin.InputBar.TestSetFocusedForSelfTest(null);
if (!initialMainWindowOpen)
{
_plugin.MainWindow.Toggle();
}
}
}
public void CleanUp() { }
}