⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
test(web): cover the crash #1580 actually reported
Andrej24108b02c822
diff --git a/apps/web/src/components/task/task-description.test.tsx b/apps/web/src/components/task/task-description.test.tsxindex 6428b4a29..3d2a8b7b7 100644--- a/apps/web/src/components/task/task-description.test.tsx+++ b/apps/web/src/components/task/task-description.test.tsx@@ -1,43 +1,48 @@-import { render } from "@testing-library/react";+import { fireEvent, render, waitFor } from "@testing-library/react";+import { Extension } from "@tiptap/core";+import TaskItem from "@tiptap/extension-task-item";import { describe, expect, it, vi } from "vitest";import TaskDescription from "./task-description";const mocks = vi.hoisted(() => ({- useEditor: vi.fn(),t: (key: string) => key,+ tasks: new Map<string, { id: string; description: string }>(),}));-vi.mock("@tiptap/react", () => ({- useEditor: mocks.useEditor,- EditorContent: () => null,- NodeViewWrapper: ({ children }: { children: unknown }) => children,- ReactNodeViewRenderer: () => () => null,+// Only the extensions that pull in browser-only machinery are replaced, and+// they are replaced with real (inert) Tiptap extensions rather than plain+// objects, so `useEditor` builds a genuine editor. The editor lifecycle is the+// thing under test here; stubbing it out is what let the previous version of+// this file pass while #1580 was still broken.+function inert(name: string) {+ return Extension.create({ name });+}++vi.mock("./extensions/shiki-code-block", () => ({+ ShikiCodeBlock: inert("shikiCodeBlockStub"),}));-vi.mock("@tiptap/react/menus", () => ({ BubbleMenu: () => null }));-vi.mock("./extensions/attachment-card", () => ({- AttachmentCard: { configure: () => ({}) },+vi.mock("./extensions/mermaid-block", () => ({+ MermaidBlock: inert("mermaidBlockStub"),}));vi.mock("./extensions/embed-block", () => ({- EmbedBlock: { configure: () => ({}) },+ EmbedBlock: inert("embedBlockStub"),}));-vi.mock("./extensions/kaneo-issue-link", () => ({- KaneoIssueLink: { configure: () => ({}) },-}));-vi.mock("./extensions/mermaid-block", () => ({- MermaidBlock: { configure: () => ({}) },+vi.mock("./extensions/attachment-card", () => ({+ AttachmentCard: inert("attachmentCardStub"),}));-vi.mock("./extensions/shiki-code-block", () => ({- ShikiCodeBlock: { configure: () => ({}) },+vi.mock("./extensions/kaneo-issue-link", () => ({+ KaneoIssueLink: inert("kaneoIssueLinkStub"),}));vi.mock("./extensions/task-item-with-checkbox", () => ({- TaskItemWithCheckbox: { configure: () => ({}) },+ TaskItemWithCheckbox: TaskItem,}));+vi.mock("react-i18next", () => ({useTranslation: () => ({ t: mocks.t }),initReactI18next: { type: "3rdParty", init: () => {} },}));vi.mock("@/hooks/queries/task/use-get-task", () => ({- default: () => ({ data: undefined }),+ default: (taskId: string) => ({ data: mocks.tasks.get(taskId) }),}));vi.mock("@/hooks/mutations/task/use-update-task-description", () => ({useUpdateTaskDescription: () => ({ mutateAsync: vi.fn() }),@@ -55,29 +60,76 @@ vi.mock("@/lib/toast", () => ({}));vi.mock("@/lib/upload-task-image", () => ({ uploadTaskImage: vi.fn() }));vi.mock("@/lib/shiki-highlighter", () => ({- getSharedShikiHighlighter: () => Promise.resolve({}),+ getSharedShikiHighlighter: () => new Promise(() => {}),}));describe("TaskDescription", () => {- it("keeps the useEditor deps stable when the task id changes", () => {- const depsPerRender: unknown[][] = [];- mocks.useEditor.mockImplementation((_options: unknown, deps: unknown[]) => {- depsPerRender.push(deps);- return null;+ it("renders the parent description when navigating from a subtask (#1580)", async () => {+ mocks.tasks.set("child-task", {+ id: "child-task",+ description: "child body",+ });+ mocks.tasks.set("parent-task", {+ id: "parent-task",+ description: "parent body",+ });++ const { container, rerender } = render(+ <TaskDescription taskId="child-task" />,+ );++ await waitFor(() => {+ expect(container.textContent).toContain("child body");});- const { rerender } = render(<TaskDescription taskId="task-a" />);- rerender(<TaskDescription taskId="task-b" />);- rerender(<TaskDescription taskId="task-c" />);+ // The "Subtask of X" backlink: the same component instance is handed a+ // different task id. Before #1580 was fixed this destroyed the editor and+ // the hydration effect then read `commands` off the destroyed instance.+ rerender(<TaskDescription taskId="parent-task" />);- expect(depsPerRender.length).toBeGreaterThanOrEqual(3);+ await waitFor(() => {+ expect(container.textContent).toContain("parent body");+ });+ expect(container.textContent).not.toContain("child body");+ });++ it("does not let undo pull the previous task's description back (#1580)", async () => {+ mocks.tasks.set("child-task", {+ id: "child-task",+ description: "child body",+ });+ mocks.tasks.set("parent-task", {+ id: "parent-task",+ description: "parent body",+ });++ const { container, rerender } = render(+ <TaskDescription taskId="child-task" />,+ );+ await waitFor(() => {+ expect(container.textContent).toContain("child body");+ });++ rerender(<TaskDescription taskId="parent-task" />);+ await waitFor(() => {+ expect(container.textContent).toContain("parent body");+ });++ // The editor now survives the task switch, so its undo stack would still+ // hold the previous task's document unless hydration is kept out of the+ // history. Undoing into it would also schedule a save of the child's+ // markdown against the parent's id.+ const editable = container.querySelector<HTMLElement>(+ '[contenteditable="true"]',+ );+ expect(editable).not.toBeNull();+ fireEvent.keyDown(editable as HTMLElement, {+ key: "z",+ code: "KeyZ",+ ctrlKey: true,+ });- const [first, ...rest] = depsPerRender;- for (const deps of rest) {- expect(deps).toHaveLength(first.length);- deps.forEach((dep, index) => {- expect(dep).toBe(first[index]);- });- }+ expect(container.textContent).toContain("parent body");+ expect(container.textContent).not.toContain("child body");});});