using AcDream.Core.Chat;
using AcDream.Core.Combat;
using AcDream.UI.Abstractions.Panels.Chat;
namespace AcDream.UI.Abstractions.Tests.Panels.Chat;
///
/// Phase I.7: surfaces combat-kind entries through
/// with their original
/// attached so the panel can pick a
/// TextColored color per line.
///
public sealed class ChatVMCombatTests
{
[Fact]
public void FormatEntry_CombatKind_PassesThroughVerbatim()
{
var entry = new ChatEntry(
Kind: ChatKind.Combat,
Sender: "",
Text: "You hit Mosswart for 5 slashing damage (50.0%).",
SenderGuid: 0,
ChannelId: 0)
{ CombatKind = CombatLineKind.Info };
Assert.Equal(
"You hit Mosswart for 5 slashing damage (50.0%).",
ChatVM.FormatEntry(entry));
}
[Fact]
public void RecentLinesDetailed_CombatEntry_RetainsCombatKind()
{
var log = new ChatLog();
var vm = new ChatVM(log);
log.OnCombatLine("Mosswart hit you for 8 fire damage to your chest.",
logTextType: 0x06u, kind: CombatLineKind.Warning);
var lines = vm.RecentLinesDetailed();
var line = Assert.Single(lines);
Assert.Equal(ChatKind.Combat, line.Kind);
Assert.Equal(CombatLineKind.Warning, line.CombatKind);
Assert.Equal("Mosswart hit you for 8 fire damage to your chest.", line.Text);
}
[Fact]
public void RecentLinesDetailed_NonCombatEntry_HasNullCombatKind()
{
var log = new ChatLog();
var vm = new ChatVM(log);
log.OnLocalSpeech("Alice", "hi", senderGuid: 0xAA, isRanged: false, logTextType: 0x02u);
var line = Assert.Single(vm.RecentLinesDetailed());
Assert.Equal(ChatKind.LocalSpeech, line.Kind);
Assert.Null(line.CombatKind);
Assert.Equal("Alice says, \"hi\"", line.Text);
}
[Fact]
public void ChatPanel_RendersCombatLine_ViaTextColored()
{
var log = new ChatLog();
var vm = new ChatVM(log);
log.OnLocalSpeech("Alice", "hi", senderGuid: 0xAA, isRanged: false, logTextType: 0x02u);
log.OnCombatLine("You hit Mosswart for 5 slashing damage (50.0%).",
logTextType: 0x06u, kind: CombatLineKind.Info);
var panel = new ChatPanel(vm);
var bus = new RecordingChatBus();
var renderer = new FakePanelRenderer { InputTextSubmitNextSubmitted = null };
panel.Render(new PanelContext(0.016f, bus), renderer);
// Plain LocalSpeech entry → Text; combat entry → TextColored, now
// sourced from RetailChatColorTable (Campaign CH slice CH1) keyed
// by LogTextType, not ChatPanel.ColorForCombat's severity bucket.
// The 0x06 generic Combat slot (colorDarkRed) is passed explicitly
// above — a registered approximation of retail's per-message
// dispatch (register row AP-176), not a ChatLog default.
Assert.Contains(renderer.Calls, c =>
c.Method == "Text" && (string?)c.Args[0] == "Alice says, \"hi\"");
var coloredCall = Assert.Single(
renderer.Calls,
c => c.Method == "TextColored");
Assert.Equal(
"You hit Mosswart for 5 slashing damage (50.0%).",
(string?)coloredCall.Args[1]);
RetailChatColorTable.TryGetColor(0x06u, out var expectedColor);
Assert.Equal(
expectedColor,
(System.Numerics.Vector4)coloredCall.Args[0]!);
}
private sealed class RecordingChatBus : ICommandBus
{
public void Publish(T command) where T : notnull { /* no-op */ }
}
}