


























11// Msteams tests cover mentions plugin behavior.
22import { describe, expect, it } from "vitest";
3-import { buildMentionEntities, formatMentionText, parseMentions } from "./mentions.js";
3+import { parseMentions } from "./mentions.js";
4455function requireFirstEntity(result: ReturnType<typeof parseMentions>) {
66const entity = result.entities[0];
@@ -15,29 +15,12 @@ function requireOnlyEntity(result: ReturnType<typeof parseMentions>) {
1515return requireFirstEntity(result);
1616}
171718-const mentionFreeTextCases = [
19-{
20-name: "parseMentions",
21-assert: () => {
22-const result = parseMentions("Hello world!");
23-24-expect(result.text).toBe("Hello world!");
25-expect(result.entities).toHaveLength(0);
26-},
27-},
28-{
29-name: "formatMentionText",
30-assert: () => {
31-const mentions = [{ id: "28:xxx", name: "John" }];
32-33-expect(formatMentionText("Hello world", mentions)).toBe("Hello world");
34-},
35-},
36-];
37-3818describe("mention-free text contract", () => {
39-it.each(mentionFreeTextCases)("$name handles text without mentions", ({ assert }) => {
40-assert();
19+it("parseMentions handles text without mentions", () => {
20+const result = parseMentions("Hello world!");
21+22+expect(result.text).toBe("Hello world!");
23+expect(result.entities).toHaveLength(0);
4124});
4225});
4326@@ -175,81 +158,3 @@ describe("parseMentions", () => {
175158expect(result.text).toBe("See @[docs](https://example.com) for details");
176159});
177160});
178-179-describe("buildMentionEntities", () => {
180-it("builds entities from mention info", () => {
181-const mentions = [
182-{ id: "28:aaa", name: "Alice" },
183-{ id: "28:bbb", name: "Bob" },
184-];
185-186-const entities = buildMentionEntities(mentions);
187-188-expect(entities).toHaveLength(2);
189-expect(entities[0]).toEqual({
190-type: "mention",
191-text: "<at>Alice</at>",
192-mentioned: {
193-id: "28:aaa",
194-name: "Alice",
195-},
196-});
197-expect(entities[1]).toEqual({
198-type: "mention",
199-text: "<at>Bob</at>",
200-mentioned: {
201-id: "28:bbb",
202-name: "Bob",
203-},
204-});
205-});
206-207-it("handles empty list", () => {
208-const entities = buildMentionEntities([]);
209-expect(entities).toHaveLength(0);
210-});
211-});
212-213-describe("formatMentionText", () => {
214-it("formats text with single mention", () => {
215-const text = "Hello @John!";
216-const mentions = [{ id: "28:xxx", name: "John" }];
217-218-const result = formatMentionText(text, mentions);
219-220-expect(result).toBe("Hello <at>John</at>!");
221-});
222-223-it("formats text with multiple mentions", () => {
224-const text = "Hey @Alice and @Bob";
225-const mentions = [
226-{ id: "28:aaa", name: "Alice" },
227-{ id: "28:bbb", name: "Bob" },
228-];
229-230-const result = formatMentionText(text, mentions);
231-232-expect(result).toBe("Hey <at>Alice</at> and <at>Bob</at>");
233-});
234-235-it("handles case-insensitive matching", () => {
236-const text = "Hey @alice and @ALICE";
237-const mentions = [{ id: "28:aaa", name: "Alice" }];
238-239-const result = formatMentionText(text, mentions);
240-241-expect(result).toBe("Hey <at>Alice</at> and <at>Alice</at>");
242-});
243-244-it("escapes regex metacharacters in names", () => {
245-const text = "Hey @John(Test) and @Alice.Smith";
246-const mentions = [
247-{ id: "28:xxx", name: "John(Test)" },
248-{ id: "28:yyy", name: "Alice.Smith" },
249-];
250-251-const result = formatMentionText(text, mentions);
252-253-expect(result).toBe("Hey <at>John(Test)</at> and <at>Alice.Smith</at>");
254-});
255-});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。