botGroupSourceLabel.test.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it } from "vitest";
  4. import { BotGroupMemberNamesContext } from "@/v4/BotGroupMemberNamesContext.js";
  5. import { BotGroupSourceLabel } from "@/v4/BotGroupSourceLabel.js";
  6. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  7. describe("group input attribution", () => {
  8. it.each(["zh-CN", "en-US"] as const)(
  9. "renders provider and stable sender in %s without exposing routing ids",
  10. (locale) => {
  11. const html = renderToStaticMarkup(
  12. createElement(
  13. ZCodeIntlProvider,
  14. { initialLocale: locale },
  15. createElement(BotGroupSourceLabel, {
  16. source: {
  17. botId: "secret-bot-id",
  18. provider: "feishu",
  19. chatId: "secret-chat-id",
  20. senderId: "ou_member",
  21. senderName: "",
  22. messageId: "om_input",
  23. },
  24. }),
  25. ),
  26. );
  27. expect(html).toContain("ou_member");
  28. expect(html).toContain(locale === "zh-CN" ? "飞书" : "Feishu");
  29. expect(html).not.toContain("secret-chat-id");
  30. expect(html).not.toContain("secret-bot-id");
  31. },
  32. );
  33. });
  34. it("shows a short fallback instead of the raw ID as visible label", () => {
  35. const html = renderToStaticMarkup(
  36. createElement(
  37. ZCodeIntlProvider,
  38. { initialLocale: "zh-CN" },
  39. createElement(BotGroupSourceLabel, {
  40. source: {
  41. provider: "feishu",
  42. botId: "bot",
  43. chatId: "chat",
  44. senderId: "ou_abcdef123456",
  45. senderName: "ou_abcdef123456",
  46. messageId: "m",
  47. },
  48. }),
  49. ),
  50. );
  51. expect(html).toContain("飞书 · 123456");
  52. expect(html).not.toContain("成员");
  53. expect(html).toContain('title="ou_abcdef123456"');
  54. expect(html).not.toContain("飞书 · ou_abcdef123456");
  55. });
  56. const historicalSource = {
  57. provider: "feishu" as const,
  58. botId: "bot",
  59. chatId: "chat",
  60. senderId: "ou_abcdef123456",
  61. senderName: "ou_abcdef123456",
  62. messageId: "m",
  63. };
  64. it.each(["bot", "other"])("isolates historical name overlay for %s", (botId) => {
  65. const html = renderToStaticMarkup(
  66. createElement(
  67. ZCodeIntlProvider,
  68. { initialLocale: "en-US" },
  69. createElement(
  70. BotGroupMemberNamesContext.Provider,
  71. { value: { botId, chatId: "chat", names: { ou_abcdef123456: "Alice" } } },
  72. createElement(BotGroupSourceLabel, { source: historicalSource }),
  73. ),
  74. ),
  75. );
  76. expect(html.includes("Feishu · Alice")).toBe(botId === "bot");
  77. expect(historicalSource.senderName).toBe(historicalSource.senderId);
  78. });