Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

1.6 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.

import { describe, expect, it } from "vitest";
import { documentHasImages } from "./tiptap";

describe("documentHasImages", () => {
  it("returns false for empty / textless documents", () => {
    expect(documentHasImages(null)).toBe(false);
    expect(documentHasImages(undefined)).toBe(false);
    expect(documentHasImages({})).toBe(false);
    expect(documentHasImages({ type: "doc", content: [] })).toBe(false);
    expect(
      documentHasImages({
        type: "doc",
        content: [
          { type: "paragraph", content: [{ type: "text", text: "hello" }] }
        ]
      })
    ).toBe(false);
  });

  it("detects a top-level image node (image-only description)", () => {
    expect(
      documentHasImages({
        type: "doc",
        content: [
          { type: "image", attrs: { src: "/file/preview/private/x.png" } }
        ]
      })
    ).toBe(true);
  });

  it("detects updatedImage and deeply nested images", () => {
    expect(
      documentHasImages({
        type: "doc",
        content: [{ type: "updatedImage", attrs: { src: "a.png" } }]
      })
    ).toBe(true);
    expect(
      documentHasImages({
        type: "doc",
        content: [
          {
            type: "bulletList",
            content: [
              {
                type: "listItem",
                content: [{ type: "image", attrs: { src: "b.png" } }]
              }
            ]
          }
        ]
      })
    ).toBe(true);
  });
});