postUpdateReleaseNotesDialog.test.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. vi.mock("@/components/ai-elements/message.js", () => ({
  5. MessageResponse: ({ children }: { children: unknown }) =>
  6. createElement("div", { "data-testid": "markdown" }, children),
  7. }));
  8. vi.mock("@/components/ui/button.js", () => ({
  9. Button: ({ children }: { children: unknown }) =>
  10. createElement("button", { type: "button" }, children),
  11. }));
  12. vi.mock("@/components/ui/GlmMonochromeIcon.js", () => ({
  13. GlmMonochromeIcon: () => createElement("span", { "data-testid": "glm-icon" }),
  14. }));
  15. vi.mock("@/components/ui/dialog.js", () => ({
  16. Dialog: ({ open, children }: { open: boolean; children: unknown }) =>
  17. (open ? createElement("div", { "data-testid": "dialog-root" }, children) : null),
  18. DialogContent: ({ children, ...props }: Record<string, unknown>) =>
  19. createElement("div", props, children),
  20. DialogTitle: ({ children }: { children: unknown }) => createElement("h1", null, children),
  21. }));
  22. vi.mock("@/i18n/IntlProvider.js", () => ({
  23. useZCodeIntl: () => ({
  24. intl: {
  25. formatMessage: vi.fn((descriptor: { id: string }) => {
  26. if (descriptor.id === "postUpdateReleaseNotes.acknowledge") {
  27. return "I know";
  28. }
  29. if (descriptor.id === "postUpdateReleaseNotes.title") {
  30. return "Release notes";
  31. }
  32. return descriptor.id;
  33. }),
  34. },
  35. }),
  36. }));
  37. describe("PostUpdateReleaseNotesDialog", () => {
  38. it("renders title row, markdown body and acknowledge button", async () => {
  39. const { PostUpdateReleaseNotesDialog } = await import(
  40. "@/root/PostUpdateReleaseNotesDialog.js"
  41. );
  42. const html = renderToStaticMarkup(
  43. createElement(PostUpdateReleaseNotesDialog, {
  44. payload: {
  45. version: "0.1.25",
  46. title: "Release v0.1.25",
  47. markdown: "## New Features\n\n- add popup",
  48. },
  49. onAcknowledge: vi.fn(),
  50. }),
  51. );
  52. expect(html).toContain('data-testid="post-update-release-notes-dialog"');
  53. expect(html).toContain("Release v0.1.25");
  54. expect(html).toContain("## New Features");
  55. expect(html).toContain("I know");
  56. });
  57. it("falls back to localized default title when payload title is empty", async () => {
  58. const { PostUpdateReleaseNotesDialog } = await import(
  59. "@/root/PostUpdateReleaseNotesDialog.js"
  60. );
  61. const html = renderToStaticMarkup(
  62. createElement(PostUpdateReleaseNotesDialog, {
  63. payload: {
  64. version: "0.1.25",
  65. title: " ",
  66. markdown: "## New Features\n\n- add popup",
  67. },
  68. onAcknowledge: vi.fn(),
  69. }),
  70. );
  71. expect(html).toContain("Release notes");
  72. });
  73. });