Skip to content

Commit

Permalink
feat(UmbracoRichText): added tests for handling of inline blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
fbosch committed Jun 17, 2024
1 parent f807c35 commit d1b895f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/__tests__/UmbracoRichText.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,37 @@ it("should render a block element using the renderBlock prop", () => {
`);
});

it("should render an inline block element using the renderBlock prop", () => {
expect(() =>
render(
<UmbracoRichText
data={{
tag: "#root",
blocks: [{ content: { id: "1", properties: {} } }],
elements: [
{
tag: "umb-rte-block-inline",
attributes: { "content-id": "1" },
elements: [],
},
],
}}
renderBlock={(block) => (
<div data-testid="umb-rte-block-inline">{block?.content?.id}</div>
)}
/>,
),
).not.toThrowError();

expect(screen.getByTestId("umb-rte-block-inline")).toMatchInlineSnapshot(`
<div
data-testid="umb-rte-block-inline"
>
1
</div>
`);
});

it("should handle route-specific path attribute for the anchor href", () => {
render(
<UmbracoRichText
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/__fixtures__/UmbracoRichText.fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
"attributes": { "content-id": "1" },
"elements": []
},
{
"tag": "p",
"attributes": {},
"elements": [
{
"tag": "umb-rte-block-inline",
"attributes": { "content-id": "1" },
"elements": []
}
]
},
{
"tag": "p",
"attributes": {},
Expand Down
10 changes: 10 additions & 0 deletions src/__tests__/__snapshots__/UmbracoRichText.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ exports[`should render fixture content correctly 1`] = `
<div
data-testid="block"
/>
<p>
<div
data-testid="block"
/>
</p>
<p>
What follows from here is just a bunch of absolute nonsense I've written to dogfood the plugin itself. It includes every sensible typographic element I could think of, like
<strong>
Expand Down Expand Up @@ -488,6 +493,11 @@ exports[`should render fixture content correctly 1`] = `
<div
data-testid="block"
/>
<p>
<div
data-testid="block"
/>
</p>
<p>
What follows from here is just a bunch of absolute nonsense I've written to dogfood the plugin itself. It includes every sensible typographic element I could think of, like
<strong>
Expand Down

0 comments on commit d1b895f

Please sign in to comment.