From 3039fe4a0678d95b5ff1d2a21b6df690662d281a Mon Sep 17 00:00:00 2001 From: Chris Villa Date: Mon, 27 Nov 2023 18:51:17 +0000 Subject: [PATCH] test: test transformProp helper --- .../core/transforms/__tests__/index.spec.ts | 77 ++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/packages/core/transforms/__tests__/index.spec.ts b/packages/core/transforms/__tests__/index.spec.ts index 697793a904..03b1256588 100644 --- a/packages/core/transforms/__tests__/index.spec.ts +++ b/packages/core/transforms/__tests__/index.spec.ts @@ -1,4 +1,4 @@ -import { migrate } from ".."; +import { migrate, transformProps } from ".."; jest.spyOn(console, "warn").mockImplementation(() => {}); @@ -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", + }, + ], + }, + } + `); + }); +});