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:
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user