96 lines
2.7 KiB
C#
96 lines
2.7 KiB
C#
using AcDream.Core.Chat;
|
|
using AcDream.UI.Abstractions.Panels.Chat;
|
|
|
|
namespace AcDream.UI.Abstractions.Tests.Panels.Chat;
|
|
|
|
/// <summary>
|
|
/// Phase I.4: <see cref="ChatVM.LastIncomingTellSender"/> tracks the
|
|
/// sender of the most recent INCOMING Tell so the chat panel can route
|
|
/// <c>/r</c> replies. Outgoing self-sent Tell echoes (which run through
|
|
/// <see cref="ChatLog.OnSelfSent"/> with <c>SenderGuid = 0</c>) must not
|
|
/// pollute the field.
|
|
/// </summary>
|
|
public sealed class ChatVMLastTellSenderTests
|
|
{
|
|
[Fact]
|
|
public void DisposeDetachesTranscriptSubscriptionExactlyOnce()
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
log.OnTellReceived("Before", "ping", 0x5000_0001u);
|
|
|
|
vm.Dispose();
|
|
vm.Dispose();
|
|
log.OnTellReceived("After", "pong", 0x5000_0002u);
|
|
|
|
Assert.Equal("Before", vm.LastIncomingTellSender);
|
|
}
|
|
|
|
[Fact]
|
|
public void LastIncomingTellSender_StartsNull()
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
|
|
Assert.Null(vm.LastIncomingTellSender);
|
|
}
|
|
|
|
[Fact]
|
|
public void LastIncomingTellSender_PopulatedFromOnTellReceived()
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
|
|
log.OnTellReceived(sender: "Bestie", text: "ping", senderGuid: 0x5000_00AAu);
|
|
|
|
Assert.Equal("Bestie", vm.LastIncomingTellSender);
|
|
}
|
|
|
|
[Fact]
|
|
public void LastIncomingTellSender_UpdatedToMostRecentIncomingTell()
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
|
|
log.OnTellReceived("Bestie", "ping", 0x5000_00AAu);
|
|
log.OnTellReceived("Regal", "yo", 0x5000_00BBu);
|
|
|
|
Assert.Equal("Regal", vm.LastIncomingTellSender);
|
|
}
|
|
|
|
[Fact]
|
|
public void LastIncomingTellSender_IgnoresSelfSentEcho()
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
|
|
// /r reply echo: SenderGuid = 0 (no real GUID for ourselves).
|
|
// Must NOT clobber the captured sender.
|
|
log.OnTellReceived("Bestie", "ping", 0x5000_00AAu);
|
|
log.OnSelfSent(ChatKind.Tell, "back at you", targetOrChannel: "Bestie");
|
|
|
|
Assert.Equal("Bestie", vm.LastIncomingTellSender);
|
|
}
|
|
|
|
[Fact]
|
|
public void LastIncomingTellSender_IgnoresLocalSpeech()
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
|
|
log.OnLocalSpeech("Caith", "hello", 0x5000_00CCu, isRanged: false);
|
|
|
|
Assert.Null(vm.LastIncomingTellSender);
|
|
}
|
|
|
|
[Fact]
|
|
public void LastIncomingTellSender_IgnoresChannelBroadcast()
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
|
|
log.OnChannelBroadcast(channelId: 7, sender: "Caith", text: "raid time");
|
|
|
|
Assert.Null(vm.LastIncomingTellSender);
|
|
}
|
|
}
|