Expand the typed client-command boundary across travel, character queries, local UI and layout controls, AFK and consent, emotes, friends, squelch and filters, and fill-components. Preserve retail packet layouts and queue ownership, import the confirmation dialog, and keep authoritative social state in Core. Co-Authored-By: Codex <codex@openai.com>
130 lines
4.2 KiB
C#
130 lines
4.2 KiB
C#
using AcDream.Core.Chat;
|
|
using AcDream.UI.Abstractions;
|
|
using AcDream.UI.Abstractions.Panels.Chat;
|
|
using Xunit;
|
|
|
|
namespace AcDream.UI.Abstractions.Tests.Panels.Chat;
|
|
|
|
public class ChatCommandRouterTests
|
|
{
|
|
private sealed class CaptureBus : ICommandBus
|
|
{
|
|
public List<object> Published { get; } = new();
|
|
|
|
public void Publish<T>(T command) where T : notnull
|
|
=> Published.Add(command);
|
|
}
|
|
|
|
private static (ChatVM vm, ChatLog log, CaptureBus bus) Fixture()
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log, displayLimit: 50);
|
|
return (vm, log, new CaptureBus());
|
|
}
|
|
|
|
[Fact]
|
|
public void PlainText_PublishesOnDefaultChannel()
|
|
{
|
|
var (vm, _, bus) = Fixture();
|
|
var outcome = ChatCommandRouter.Submit("hello there", vm, bus, ChatChannelKind.Say);
|
|
|
|
Assert.Equal(SubmitOutcome.Sent, outcome);
|
|
var command = Assert.IsType<SendChatCmd>(Assert.Single(bus.Published));
|
|
Assert.Equal(ChatChannelKind.Say, command.Channel);
|
|
Assert.Equal("hello there", command.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultChannel_IsHonored()
|
|
{
|
|
var (vm, _, bus) = Fixture();
|
|
ChatCommandRouter.Submit("hi", vm, bus, ChatChannelKind.Fellowship);
|
|
|
|
var command = Assert.IsType<SendChatCmd>(Assert.Single(bus.Published));
|
|
Assert.Equal(ChatChannelKind.Fellowship, command.Channel);
|
|
}
|
|
|
|
[Fact]
|
|
public void ClearCommand_PublishesTypedRetailCommand()
|
|
{
|
|
var (vm, log, bus) = Fixture();
|
|
log.OnSystemMessage("x", chatType: 0);
|
|
|
|
var outcome = ChatCommandRouter.Submit("/clear", vm, bus, ChatChannelKind.Say);
|
|
|
|
Assert.Equal(SubmitOutcome.ClientHandled, outcome);
|
|
var command = Assert.IsType<ExecuteClientCommandCmd>(Assert.Single(bus.Published));
|
|
Assert.Equal(ClientCommandId.ClearChat, command.Command);
|
|
Assert.Equal("", command.Arguments);
|
|
Assert.Single(log.Snapshot());
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("/lifestone")]
|
|
[InlineData("/lif")]
|
|
[InlineData("/ls")]
|
|
[InlineData("@LS")]
|
|
public void LifestoneAliases_PublishTypedClientCommand(string input)
|
|
{
|
|
var (vm, _, bus) = Fixture();
|
|
|
|
var outcome = ChatCommandRouter.Submit(input, vm, bus, ChatChannelKind.Fellowship);
|
|
|
|
Assert.Equal(SubmitOutcome.ClientHandled, outcome);
|
|
var command = Assert.IsType<ExecuteClientCommandCmd>(Assert.Single(bus.Published));
|
|
Assert.Equal(ClientCommandId.LifestoneRecall, command.Command);
|
|
}
|
|
|
|
[Fact]
|
|
public void LifestoneWithArguments_ShowsUsageAndPublishesNothing()
|
|
{
|
|
var (vm, log, bus) = Fixture();
|
|
|
|
var outcome = ChatCommandRouter.Submit("/ls now", vm, bus, ChatChannelKind.Say);
|
|
|
|
Assert.Equal(SubmitOutcome.ClientHandled, outcome);
|
|
Assert.Empty(bus.Published);
|
|
Assert.Contains(log.Snapshot(), entry => entry.Text == "Usage: /lifestone");
|
|
}
|
|
|
|
[Fact]
|
|
public void UnknownSlashVerb_RoutesThroughExplicitServerCommand()
|
|
{
|
|
var (vm, log, bus) = Fixture();
|
|
|
|
var outcome = ChatCommandRouter.Submit(
|
|
"/notacommand", vm, bus, ChatChannelKind.Say);
|
|
|
|
Assert.Equal(SubmitOutcome.Sent, outcome);
|
|
var command = Assert.IsType<SendServerCommandCmd>(Assert.Single(bus.Published));
|
|
Assert.Equal("@notacommand", command.Text);
|
|
Assert.DoesNotContain(log.Snapshot(), entry => entry.Text.Contains("Unknown command"));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("/ci 629 5")]
|
|
[InlineData("@ci 629 5")]
|
|
public void ServerCommandWithArgs_PublishesCanonicalAtForm_EvenOnChannelDefault(
|
|
string input)
|
|
{
|
|
var (vm, _, bus) = Fixture();
|
|
|
|
var outcome = ChatCommandRouter.Submit(
|
|
input, vm, bus, ChatChannelKind.Fellowship);
|
|
|
|
Assert.Equal(SubmitOutcome.Sent, outcome);
|
|
var command = Assert.IsType<SendServerCommandCmd>(Assert.Single(bus.Published));
|
|
Assert.Equal("@ci 629 5", command.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyInput_DoesNothing()
|
|
{
|
|
var (vm, _, bus) = Fixture();
|
|
|
|
var outcome = ChatCommandRouter.Submit(" ", vm, bus, ChatChannelKind.Say);
|
|
|
|
Assert.Equal(SubmitOutcome.Empty, outcome);
|
|
Assert.Empty(bus.Published);
|
|
}
|
|
}
|