Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
istarkov committed Dec 2, 2024
1 parent 3fc366f commit 50b0116
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions packages/react-sdk/src/component-generator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1133,3 +1133,75 @@ test("variable names can be js identifiers", () => {
)
);
});

test("Renders nothing if only templates are present in block", () => {
const Bt = ws["block-template"];

expect(
generateWebstudioComponent({
classesMap: new Map(),
scope: createScope(),
name: "Page",
rootInstanceId: "body",
parameters: [],
dataSources: new Map(),
indexesWithinAncestors: new Map(),
...renderJsx(
<$.Body ws:id="body">
<ws.block ws:id="block">
<Bt>
<$.Box>Test</$.Box>
</Bt>
</ws.block>
</$.Body>
),
})
).toEqual(
validateJSX(
clear(`
const Page = () => {
return <Body>
</Body>
}
`)
)
);
});

test("Renders only block children", () => {
const Bt = ws["block-template"];

expect(
generateWebstudioComponent({
classesMap: new Map(),
scope: createScope(),
name: "Page",
rootInstanceId: "body",
parameters: [],
dataSources: new Map(),
indexesWithinAncestors: new Map(),
...renderJsx(
<$.Body ws:id="body">
<ws.block ws:id="block">
<Bt>
<$.Box>Test</$.Box>
</Bt>
<$.Box>Child0</$.Box>
</ws.block>
</$.Body>
),
})
).toEqual(
validateJSX(
clear(`
const Page = () => {
return <Body>
<Box>
{"Child0"}
</Box>
</Body>
}
`)
)
);
});

0 comments on commit 50b0116

Please sign in to comment.