test(gutenberg-to-portable-text): add transform tests (#332)

* test(gutenberg-to-portable-text): add transform tests

This adds a bunch of tests, mostly for the transformers but also some
minor edge cases in the inline parser, too.

It also enables `noUnusedLocals` in `tsconfig.json` which caught a
couple of unused things.

* chore: add domain to each

* style: format

* chore: remove some figures

---------

Co-authored-by: emdashbot[bot] <emdashbot[bot]@users.noreply.github.com>
This commit is contained in:
James Garbutt
2026-04-07 07:36:14 +01:00
committed by GitHub
parent dbaf8c6f85
commit a996387de4
5 changed files with 401 additions and 9 deletions

View File

@@ -253,6 +253,34 @@ describe("parseInlineContent", () => {
expect(span?.marks).toContain("strong");
expect(span?.marks?.length).toBe(2); // strong + link key
});
it("handles links with empty href", () => {
const result = parseInlineContent('<a href="">empty link</a>', generateKey);
expect(result.markDefs).toHaveLength(1);
expect(result.markDefs[0]).toMatchObject({
_type: "link",
href: "",
});
const linkSpan = result.children.find((c) =>
c.marks?.includes(result.markDefs[0]?._key ?? ""),
);
expect(linkSpan?.text).toBe("empty link");
});
it("ignores unknown schemes in links", () => {
const result = parseInlineContent('<a href="ftp://foo.bar">bad link</a>', generateKey);
expect(result.markDefs).toHaveLength(1);
expect(result.markDefs[0]).toMatchObject({
_type: "link",
href: "",
});
const linkSpan = result.children.find((c) => c.marks?.includes(result.markDefs[0]!._key));
expect(linkSpan?.text).toBe("bad link");
});
});
describe("line breaks", () => {