Files
outline/shared/editor/nodes/Mention.test.ts
T
Tom MoorandClaude Opus 5.5 9e2565184e chore: Prune stale comments, TODOs, and type suppressions (#14092)
* chore: Remove unused lint disable directives

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Replace TODO type suppressions with typed code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Remove obsolete workaround comments in tests and MediaDimension

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Remove Tippy compatibility props from Tooltip

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Decouple DropdownMenu props from Tooltip and clarify sharing styles

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Remove stale retention TODOs from cleanup tasks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Register relations synchronously and clarify workaround comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

* chore: Replace Notion import TODOs with descriptive comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-15 08:54:37 -04:00

164 lines
4.8 KiB
TypeScript

import { MentionType } from "../../types";
import { schema, serializer } from "../../test/editor";
const id = "0c440212-8b40-49fa-8a64-2548d6b60d59";
const modelId = "c85a0d80-3a89-4b25-a0cd-e7fc83f0d226";
const serializeMention = (
attrs: Record<string, unknown>,
options?: { commonMark?: boolean }
) => {
const doc = schema.nodeFromJSON({
type: "doc",
content: [
{
type: "paragraph",
content: [{ type: "mention", attrs: { id, modelId, ...attrs } }],
},
],
});
return serializer.serialize(doc, options).trim();
};
describe("Mention serialization", () => {
describe("markdown leaving Outline", () => {
it("serializes an issue mention as an @ prefixed link to the external url", () => {
expect(
serializeMention(
{
type: MentionType.Issue,
label: "Epic 1: Control plane Helm chart",
href: "https://github.com/acme/infra/issues/2",
},
{ commonMark: true }
)
).toBe(
"@[Epic 1: Control plane Helm chart](https://github.com/acme/infra/issues/2)"
);
});
it("serializes a pull request mention as an @ prefixed link to the external url", () => {
expect(
serializeMention(
{
type: MentionType.PullRequest,
label: "Add Helm chart",
href: "https://github.com/acme/infra/pull/42",
},
{ commonMark: true }
)
).toBe("@[Add Helm chart](https://github.com/acme/infra/pull/42)");
});
it("serializes a project mention as an @ prefixed link to the external url", () => {
expect(
serializeMention(
{
type: MentionType.Project,
label: "Q3 Roadmap",
href: "https://github.com/orgs/acme/projects/7",
},
{ commonMark: true }
)
).toBe("@[Q3 Roadmap](https://github.com/orgs/acme/projects/7)");
});
it("serializes a url mention as an @ prefixed link", () => {
expect(
serializeMention(
{
type: MentionType.URL,
label: "Example",
href: "https://example.com/page",
},
{ commonMark: true }
)
).toBe("@[Example](https://example.com/page)");
});
it("sanitizes an unsafe url", () => {
const markdown = serializeMention(
{
type: MentionType.Issue,
label: "Epic 1",
href: "javascript:alert(1)",
},
{ commonMark: true }
);
expect(markdown).not.toContain("(javascript:");
});
it("keeps the mention:// format when there is no url to link to", () => {
expect(
serializeMention(
{ type: MentionType.Issue, label: "Epic 1" },
{ commonMark: true }
)
).toBe(`@[Epic 1](mention://${id}/issue/${modelId})`);
});
it("keeps the mention:// format for internal mentions", () => {
expect(
serializeMention(
{ type: MentionType.User, label: "John Doe" },
{ commonMark: true }
)
).toBe(`@[John Doe](mention://${id}/user/${modelId})`);
});
});
describe("markdown staying within Outline", () => {
it("keeps the mention:// format for an issue mention", () => {
expect(
serializeMention({
type: MentionType.Issue,
label: "Epic 1: Control plane Helm chart",
href: "https://github.com/acme/infra/issues/2",
})
).toBe(
`@[Epic 1: Control plane Helm chart](mention://${id}/issue/${modelId})`
);
});
it("keeps the mention:// format for a pull request mention", () => {
expect(
serializeMention({
type: MentionType.PullRequest,
label: "Add Helm chart",
href: "https://github.com/acme/infra/pull/42",
})
).toBe(`@[Add Helm chart](mention://${id}/pull_request/${modelId})`);
});
it("keeps the mention:// format for a project mention", () => {
expect(
serializeMention({
type: MentionType.Project,
label: "Q3 Roadmap",
href: "https://github.com/orgs/acme/projects/7",
})
).toBe(`@[Q3 Roadmap](mention://${id}/project/${modelId})`);
});
});
describe("document and collection mentions", () => {
it("serializes a document mention as an internal link", () => {
expect(
serializeMention(
{ type: MentionType.Document, label: "Onboarding" },
{ commonMark: true }
)
).toBe(`[Onboarding](/doc/${modelId})`);
});
it("serializes a collection mention as an internal link", () => {
expect(
serializeMention(
{ type: MentionType.Collection, label: "Engineering" },
{ commonMark: true }
)
).toBe(`[Engineering](/collection/${modelId})`);
});
});
});