channelMentionContent.test.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // @vitest-environment jsdom
  2. import { createElement } from "react";
  3. import { renderToStaticMarkup } from "react-dom/server";
  4. import { describe, expect, it } from "vitest";
  5. import { ChannelMentionContent, BotChannelMessageContent } from "@/v4/ChannelMentionContent.js";
  6. import type { ChannelContentPart } from "@zcode/shared";
  7. const parts: ChannelContentPart[] = [
  8. { type: "text", text: "帮我 " },
  9. {
  10. type: "channelMention",
  11. refId: "m1",
  12. name: "Ryan Bot",
  13. channel: "feishu",
  14. targetId: "ou_target",
  15. idType: "open_id",
  16. entityType: "unknown",
  17. },
  18. ];
  19. describe("native channel mention rendering", () => {
  20. it("renders a native node without exposing platform IDs", () => {
  21. const html = renderToStaticMarkup(
  22. createElement(ChannelMentionContent, { parts, text: "帮我 @Ryan Bot" }),
  23. );
  24. expect(html).toContain('data-channel-mention="feishu"');
  25. expect(html).toContain("Ryan Bot");
  26. expect(html).not.toContain("ou_target");
  27. });
  28. it("renders original mentions in a multi-user queue projection", () => {
  29. const source = {
  30. botId: "bot",
  31. provider: "feishu" as const,
  32. chatId: "chat",
  33. threadId: "topic",
  34. senderId: "bob",
  35. senderName: "Bob",
  36. messageId: "b",
  37. messages: [
  38. {
  39. senderId: "alice",
  40. senderName: "Alice",
  41. messageId: "a",
  42. text: "帮我 @Ryan Bot",
  43. contentParts: parts,
  44. attachmentIndexes: [],
  45. },
  46. { senderId: "bob", senderName: "Bob", messageId: "b", text: "补充", attachmentIndexes: [] },
  47. ],
  48. };
  49. const html = renderToStaticMarkup(
  50. createElement(BotChannelMessageContent, {
  51. source,
  52. text: "Alice: 帮我 @Ryan Bot\n\nBob: 补充",
  53. }),
  54. );
  55. expect(html).toContain('data-channel-mention="feishu"');
  56. expect(html).toContain("Bob: 补充");
  57. });
  58. it("does not reuse identity after text is edited", () => {
  59. const html = renderToStaticMarkup(
  60. createElement(ChannelMentionContent, { parts, text: "帮我 @Alice" }),
  61. );
  62. expect(html).not.toContain("data-channel-mention");
  63. expect(html).toContain("Alice");
  64. });
  65. });