Skip to content

Commit

Permalink
test: test transformProp helper
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Dec 11, 2023
1 parent ce8f22e commit 3039fe4
Showing 1 changed file with 76 additions and 1 deletion.
77 changes: 76 additions & 1 deletion packages/core/transforms/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { migrate } from "..";
import { migrate, transformProps } from "..";

jest.spyOn(console, "warn").mockImplementation(() => {});

Expand All @@ -10,3 +10,78 @@ describe("migrate method", () => {
});
});
});

describe("transformProps method", () => {
it("should migrate props for the root", () => {
expect(
transformProps(
{ content: [], root: { props: { title: "Hello, world" } } },
{
root: (props) => ({
updatedTitle: props.title,
}),
}
)
).toEqual({
content: [],
root: { props: { updatedTitle: "Hello, world" } },
zones: {},
});
});

it("should migrate props for a specified component", () => {
expect(
transformProps(
{
content: [
{
type: "HeadingBlock",
props: { title: "Hello, world", id: "123" },
},
],

root: { props: { title: "Hello, world" } },
zones: {
MyZone: [
{
type: "HeadingBlock",
props: { title: "Hello, other world", id: "456" },
},
],
},
},
{
HeadingBlock: (props) => ({
heading: props.title,
}),
}
)
).toMatchInlineSnapshot(`
{
"content": [
{
"props": {
"heading": "Hello, world",
},
"type": "HeadingBlock",
},
],
"root": {
"props": {
"title": "Hello, world",
},
},
"zones": {
"MyZone": [
{
"props": {
"heading": "Hello, other world",
},
"type": "HeadingBlock",
},
],
},
}
`);
});
});

0 comments on commit 3039fe4

Please sign in to comment.