| 1 | using CascadeIDE.Features.Chat; |
| 2 | using CascadeIDE.ViewModels; |
| 3 | using Xunit; |
| 4 | |
| 5 | namespace CascadeIDE.Tests; |
| 6 | |
| 7 | public sealed class ChatSlashForkPersistenceTests |
| 8 | { |
| 9 | [Fact] |
| 10 | public void SlashAfterFork_PayloadThreadIdMatchesAssignedThread() |
| 11 | { |
| 12 | var mainId = Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); |
| 13 | var topicId = Guid.Parse("cccccccc-cccc-cccc-cccc-cccccccccccc"); |
| 14 | |
| 15 | var cmdMsg = ChatMessageViewModel.CreateSlashCommand("/topic create ADR", "ADR", mainId); |
| 16 | cmdMsg.AssignThread(topicId); |
| 17 | cmdMsg.ApplySlashCommandResult( |
| 18 | new ChatSlashCommandRunResult(true, true, "/topic create", "ADR", "Создана тема: ADR")); |
| 19 | |
| 20 | var payload = ChatHistoryPayloadMapping.ToMessagePayload(cmdMsg); |
| 21 | Assert.Equal(topicId.ToString("N"), payload.ThreadId); |
| 22 | } |
| 23 | |
| 24 | [Fact] |
| 25 | public void TopicCreateFlow_CompositorShowsSyntheticTopic() |
| 26 | { |
| 27 | var mainId = Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); |
| 28 | var topicId = Guid.Parse("cccccccc-cccc-cccc-cccc-cccccccccccc"); |
| 29 | var titles = new Dictionary<Guid, string> { [topicId] = "ADR" }; |
| 30 | |
| 31 | var slashMsg = new ChatConversationMessage( |
| 32 | Guid.NewGuid(), |
| 33 | "slash_command", |
| 34 | "Создана тема: ADR", |
| 35 | topicId, |
| 36 | null, |
| 37 | 0, |
| 38 | "/topic create", |
| 39 | "ADR", |
| 40 | ChatSlashCommandStatus.Succeeded); |
| 41 | |
| 42 | var snapshot = new ChatSurfaceCompositor().Compose(new ChatSurfaceIntent( |
| 43 | [slashMsg], |
| 44 | ActiveClarificationBatch: null, |
| 45 | SelectedMessageIndex: 0, |
| 46 | MainThreadId: mainId, |
| 47 | ActiveThreadId: topicId, |
| 48 | ThreadBranchHint: "ADR", |
| 49 | ThreadDisplayTitles: titles, |
| 50 | ThreadForks: [new ChatThreadForkRecord(topicId, mainId, null)])); |
| 51 | |
| 52 | var topic = Assert.Single(snapshot.State.Threads, t => t.ThreadId == topicId); |
| 53 | Assert.Equal("ADR", topic.Title); |
| 54 | Assert.Equal(mainId, topic.ParentThreadId); |
| 55 | Assert.Contains(snapshot.Layout.Overview, item => item.ThreadId == topicId); |
| 56 | } |
| 57 | } |
| 58 | |