From aee68ed9ceb489659e3941ea58d8fa0180abb96e Mon Sep 17 00:00:00 2001 From: Molecule AI Core-FE Date: Tue, 12 May 2026 07:59:30 +0000 Subject: [PATCH] fix(canvas/test): restore MemoryTab (42 cases) + OrgTemplatesSection (13 cases) test coverage Conflict resolution during rebase incorrectly applied remote (main) versions of these files which had fewer tests. Restoring full test suites from original commits. Co-Authored-By: Claude Opus 4.7 --- .../__tests__/OrgTemplatesSection.test.tsx | 267 +++- .../tabs/__tests__/MemoryTab.test.tsx | 1168 ++++++++--------- 2 files changed, 712 insertions(+), 723 deletions(-) diff --git a/canvas/src/components/__tests__/OrgTemplatesSection.test.tsx b/canvas/src/components/__tests__/OrgTemplatesSection.test.tsx index 59bdda12..a30f636c 100644 --- a/canvas/src/components/__tests__/OrgTemplatesSection.test.tsx +++ b/canvas/src/components/__tests__/OrgTemplatesSection.test.tsx @@ -1,102 +1,233 @@ // @vitest-environment jsdom -import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; -import { render, screen, waitFor, fireEvent, cleanup } from "@testing-library/react"; - -// Tests for the default-collapsed + expand-on-click behavior of the -// org templates drawer. Before this change the section rendered all -// org cards inline, which pushed the individual workspace templates -// off-screen when there were ≥3 orgs on disk. Collapsed-by-default -// keeps the scroll focused on the primary deploy path. - -vi.mock("@/lib/api", () => ({ - api: { - get: vi.fn().mockResolvedValue([ - { dir: "free-beats-all", name: "Free Beats All", description: "d1", workspaces: 3 }, - { dir: "medo-smoke", name: "MeDo Smoke Test", description: "d2", workspaces: 1 }, - ]), - post: vi.fn().mockResolvedValue({}), - }, +/** + * Tests for OrgTemplatesSection — collapsible org template import list. + * + * Covers: + * - Header with count badge (visible only when expanded) + * - Collapsed by default, aria-expanded toggles on click + * - aria-controls targets org-templates-body div + * - Empty state when no org templates + * - Loading spinner + * - Org template cards: name, description, workspace count + * - Import button per card + * - Preflight modal opens when org has required_env + * - Preflight onProceed fires import + * - Preflight onCancel closes modal + * - Direct import (no modal) when org has no env requirements + * - Import button disabled while that org is importing + */ +// ── ALL mocks MUST be before imports (vi.mock is hoisted to top of file) ─────── +const { mockGet, mockPost, mockListSecrets } = vi.hoisted(() => ({ + mockGet: vi.fn(), + mockPost: vi.fn(), + mockListSecrets: vi.fn(), })); -vi.mock("../Spinner", () => ({ Spinner: () => null })); -vi.mock("../MissingKeysModal", () => ({ MissingKeysModal: () => null })); -vi.mock("../ConfirmDialog", () => ({ ConfirmDialog: () => null })); -vi.mock("@/lib/deploy-preflight", () => ({ checkDeploySecrets: vi.fn() })); +vi.mock("@/lib/api", () => ({ + api: { get: mockGet, post: mockPost }, +})); +vi.mock("@/lib/api/secrets", () => ({ + listSecrets: mockListSecrets, +})); + +vi.mock("@/store/canvas", () => ({ + useCanvasStore: Object.assign( + vi.fn(), + { getState: () => ({ nodes: [], hydrate: vi.fn() }) }, + ), +})); + +vi.mock("../Spinner", () => ({ + Spinner: () =>