mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-13 03:53:47 +00:00
Kept the unsent message with its chat (#1049)
This commit is contained in:
1 parent
1c13300988
commit
468d28aa94
18 files changed
+1333
-240
No files matched your search
@@ -0,0 +1,64 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Components;
|
||||
using AIStudio.Settings;
|
||||
|
||||
namespace AIStudio.Tests.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Checks what the composer counts as a message the user started.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// That decides whether a chat template may still fill the composer, and whether leaving the chat
|
||||
/// warns about unsaved changes. A draft brought back from a chat is always the user's own, while a
|
||||
/// chat template only suggests a message.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class ChatComposerStateTests
|
||||
{
|
||||
[Test]
|
||||
public void ADraftBroughtBackIsTheMessageOfTheUser()
|
||||
{
|
||||
var draft = new ChatDraft();
|
||||
draft.SetText("Summarize the meeting");
|
||||
draft.AddAttachments([new FileAttachment(FileAttachmentType.DOCUMENT, "agenda.pdf", "/documents/agenda.pdf", 1024)]);
|
||||
var composer = new ChatComposerState();
|
||||
|
||||
composer.RestoreFromDraft(draft);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(composer.UserInput, Is.EqualTo("Summarize the meeting"));
|
||||
Assert.That(composer.FileAttachments.Select(attachment => attachment.FilePath), Is.EqualTo(new[] { "/documents/agenda.pdf" }));
|
||||
Assert.That(composer.HasUserDraft, Is.True, "A chat template must not replace the message the user came back to.");
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnEmptyDraftLeavesTheComposerFree()
|
||||
{
|
||||
var composer = new ChatComposerState();
|
||||
composer.SetUserInput("A message of the chat before");
|
||||
|
||||
composer.RestoreFromDraft(new ChatDraft());
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(composer.UserInput, Is.Empty, "The message of the chat before belongs to that chat.");
|
||||
Assert.That(composer.HasUserDraft, Is.False, "Nobody started a message in this chat, so a chat template may still fill the composer.");
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheMessageOfAChatTemplateIsNoDraftOfTheUser()
|
||||
{
|
||||
var composer = new ChatComposerState();
|
||||
|
||||
composer.ApplyTemplate(new ChatTemplate { PredefinedUserPrompt = "Translate the following text:" });
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(composer.UserInput, Is.EqualTo("Translate the following text:"));
|
||||
Assert.That(composer.HasUserDraft, Is.False, "Leaving the chat must not warn about a message the user never wrote.");
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user