b3a7f98e5a
CI / E2E Cloudflare (4/8) (push) Failing after 0s
CI / E2E Cloudflare (8/8) (push) Failing after 1s
CI / Lint (push) Failing after 1s
Auto Extract / Extract (push) Failing after 4s
CI / Version Check (push) Failing after 9s
CI / Integration Tests (push) Failing after 1s
CI / E2E tests (1/8) (push) Failing after 1s
CI / E2E tests (2/8) (push) Failing after 2s
CI / E2E tests (3/8) (push) Failing after 2s
CI / Browser Tests (push) Failing after 1s
CI / E2E tests (5/8) (push) Failing after 1s
CI / E2E Cloudflare (2/8) (push) Failing after 2s
CI / Typecheck (push) Failing after 1s
CI / Changeset Validation (push) Failing after 2s
CI / E2E Cloudflare (5/8) (push) Failing after 1s
CI / E2E Cloudflare (6/8) (push) Failing after 1s
CI / E2E Cloudflare (7/8) (push) Failing after 1s
CodeQL / Analyze (javascript-typescript) (push) Failing after 1s
Format / Format (push) Failing after 0s
CodeQL / Analyze (actions) (push) Failing after 4s
CI / E2E tests (4/8) (push) Failing after 1s
CI / E2E tests (6/8) (push) Failing after 1s
CI / E2E tests (7/8) (push) Failing after 2s
CI / E2E tests (8/8) (push) Failing after 1s
CI / E2E Cloudflare (1/8) (push) Failing after 1s
CI / E2E Cloudflare (3/8) (push) Failing after 2s
Preview Releases / Publish Preview (push) Failing after 0s
zizmor / Run zizmor (push) Failing after 1s
Release / Release (push) Failing after 2s
CI / Smoke Tests (push) Failing after 5m36s
CI / Tests (push) Failing after 6m36s
Release / Sync Templates (push) Has been skipped
CI / E2E Tests (push) Has been cancelled
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
|
|
import { portableTextToProsemirror } from "../../../src/content/converters/portable-text-to-prosemirror.js";
|
|
import { prosemirrorToPortableText } from "../../../src/content/converters/prosemirror-to-portable-text.js";
|
|
import type { PortableTextImageBlock } from "../../../src/content/converters/types.js";
|
|
|
|
describe("Image dimension round-trip", () => {
|
|
const imageBlock: PortableTextImageBlock = {
|
|
_type: "image",
|
|
_key: "abc123",
|
|
asset: { _ref: "media-123", url: "https://example.com/photo.jpg" },
|
|
alt: "A photo",
|
|
caption: "My caption",
|
|
width: 1920,
|
|
height: 1080,
|
|
displayWidth: 400,
|
|
displayHeight: 225,
|
|
};
|
|
|
|
it("preserves displayWidth and displayHeight through PT → PM → PT", () => {
|
|
// PT → PM
|
|
const pm = portableTextToProsemirror([imageBlock]);
|
|
const imageNode = pm.content[0];
|
|
|
|
expect(imageNode.type).toBe("image");
|
|
expect(imageNode.attrs?.displayWidth).toBe(400);
|
|
expect(imageNode.attrs?.displayHeight).toBe(225);
|
|
expect(imageNode.attrs?.width).toBe(1920);
|
|
expect(imageNode.attrs?.height).toBe(1080);
|
|
|
|
// PM → PT
|
|
const pt = prosemirrorToPortableText(pm);
|
|
const restored = pt[0] as PortableTextImageBlock;
|
|
|
|
expect(restored._type).toBe("image");
|
|
expect(restored.displayWidth).toBe(400);
|
|
expect(restored.displayHeight).toBe(225);
|
|
expect(restored.width).toBe(1920);
|
|
expect(restored.height).toBe(1080);
|
|
});
|
|
|
|
it("handles images without display dimensions", () => {
|
|
const noDisplayDims: PortableTextImageBlock = {
|
|
_type: "image",
|
|
_key: "def456",
|
|
asset: { _ref: "media-456", url: "https://example.com/other.jpg" },
|
|
width: 800,
|
|
height: 600,
|
|
};
|
|
|
|
const pm = portableTextToProsemirror([noDisplayDims]);
|
|
const pt = prosemirrorToPortableText(pm);
|
|
const restored = pt[0] as PortableTextImageBlock;
|
|
|
|
expect(restored.displayWidth).toBeUndefined();
|
|
expect(restored.displayHeight).toBeUndefined();
|
|
expect(restored.width).toBe(800);
|
|
expect(restored.height).toBe(600);
|
|
});
|
|
});
|