Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/desktop/src/chat/components/input/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe("serializeDraftMessage", () => {
{
kind: "human",
key: "human:manual:human-1",
label: "john",
source: "draft",
humanId: "human-1",
},
Expand Down Expand Up @@ -83,6 +84,7 @@ describe("serializeDraftMessage", () => {
{
kind: "organization",
key: "organization:manual:org-1",
label: "Acme",
source: "draft",
organizationId: "org-1",
},
Expand Down
24 changes: 24 additions & 0 deletions apps/desktop/src/chat/components/message/normal.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { render, screen } from "@testing-library/react";
import { describe, expect, test } from "vitest";

import { NormalMessage } from "./normal";

describe("NormalMessage", () => {
test("renders markdown in user messages", async () => {
render(
<NormalMessage
message={{
id: "message-1",
role: "user",
parts: [{ type: "text", text: "[Docs](https://example.com/docs)" }],
}}
/>,
);

const link = await screen.findByRole("link", {
name: "Docs",
});

expect(link.getAttribute("href")).toBe("https://example.com/docs");
});
});
112 changes: 112 additions & 0 deletions apps/desktop/src/chat/components/message/user-text.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { describe, expect, test } from "vitest";

import { buildUserMessageSegments } from "./user-text";

describe("buildUserMessageSegments", () => {
test("replaces matching mention tokens inline", () => {
expect(
buildUserMessageSegments("chat with @adhit@janet.ai about this", [
{
key: "human:manual:1",
kind: "human",
entityId: "1",
displayLabel: "adhit@janet.ai",
tokens: ["@adhit@janet.ai"],
},
]),
).toEqual([
{ type: "text", text: "chat with " },
{
type: "mention",
mention: {
key: "human:manual:1",
kind: "human",
entityId: "1",
displayLabel: "adhit@janet.ai",
tokens: ["@adhit@janet.ai"],
},
},
{ type: "text", text: " about this" },
]);
});

test("renders repeated mentions from a single ref", () => {
expect(
buildUserMessageSegments("@Sam follow up with @Sam tomorrow", [
{
key: "human:manual:1",
kind: "human",
entityId: "1",
displayLabel: "Sam",
tokens: ["@Sam"],
},
]),
).toEqual([
{
type: "mention",
mention: {
key: "human:manual:1",
kind: "human",
entityId: "1",
displayLabel: "Sam",
tokens: ["@Sam"],
},
},
{ type: "text", text: " follow up with " },
{
type: "mention",
mention: {
key: "human:manual:1",
kind: "human",
entityId: "1",
displayLabel: "Sam",
tokens: ["@Sam"],
},
},
{ type: "text", text: " tomorrow" },
]);
});

test("prefers the longest token when mentions overlap", () => {
expect(
buildUserMessageSegments("@Sam Lee and @Sam", [
{
key: "human:manual:1",
kind: "human",
entityId: "1",
displayLabel: "Sam",
tokens: ["@Sam"],
},
{
key: "human:manual:2",
kind: "human",
entityId: "2",
displayLabel: "Sam Lee",
tokens: ["@Sam Lee", "@Sam"],
},
]),
).toEqual([
{
type: "mention",
mention: {
key: "human:manual:2",
kind: "human",
entityId: "2",
displayLabel: "Sam Lee",
tokens: ["@Sam Lee", "@Sam"],
},
},
{ type: "text", text: " and " },
{
type: "mention",
mention: {
key: "human:manual:1",
kind: "human",
entityId: "1",
displayLabel: "Sam",
tokens: ["@Sam"],
},
},
]);
});
});
Loading
Loading