Skip to content

Commit 50b0116

Browse files
committed
Add tests
1 parent 3fc366f commit 50b0116

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

packages/react-sdk/src/component-generator.test.tsx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,3 +1133,75 @@ test("variable names can be js identifiers", () => {
11331133
)
11341134
);
11351135
});
1136+
1137+
test("Renders nothing if only templates are present in block", () => {
1138+
const Bt = ws["block-template"];
1139+
1140+
expect(
1141+
generateWebstudioComponent({
1142+
classesMap: new Map(),
1143+
scope: createScope(),
1144+
name: "Page",
1145+
rootInstanceId: "body",
1146+
parameters: [],
1147+
dataSources: new Map(),
1148+
indexesWithinAncestors: new Map(),
1149+
...renderJsx(
1150+
<$.Body ws:id="body">
1151+
<ws.block ws:id="block">
1152+
<Bt>
1153+
<$.Box>Test</$.Box>
1154+
</Bt>
1155+
</ws.block>
1156+
</$.Body>
1157+
),
1158+
})
1159+
).toEqual(
1160+
validateJSX(
1161+
clear(`
1162+
const Page = () => {
1163+
return <Body>
1164+
</Body>
1165+
}
1166+
`)
1167+
)
1168+
);
1169+
});
1170+
1171+
test("Renders only block children", () => {
1172+
const Bt = ws["block-template"];
1173+
1174+
expect(
1175+
generateWebstudioComponent({
1176+
classesMap: new Map(),
1177+
scope: createScope(),
1178+
name: "Page",
1179+
rootInstanceId: "body",
1180+
parameters: [],
1181+
dataSources: new Map(),
1182+
indexesWithinAncestors: new Map(),
1183+
...renderJsx(
1184+
<$.Body ws:id="body">
1185+
<ws.block ws:id="block">
1186+
<Bt>
1187+
<$.Box>Test</$.Box>
1188+
</Bt>
1189+
<$.Box>Child0</$.Box>
1190+
</ws.block>
1191+
</$.Body>
1192+
),
1193+
})
1194+
).toEqual(
1195+
validateJSX(
1196+
clear(`
1197+
const Page = () => {
1198+
return <Body>
1199+
<Box>
1200+
{"Child0"}
1201+
</Box>
1202+
</Body>
1203+
}
1204+
`)
1205+
)
1206+
);
1207+
});

0 commit comments

Comments
 (0)