Skip to content

Commit e227831

Browse files
committed
1 parent 0d37136 commit e227831

File tree

2 files changed

+84
-85
lines changed

2 files changed

+84
-85
lines changed

packages/core/src/__tests__/builder/builder.test.ts

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -911,91 +911,6 @@ describe('Builder', () => {
911911
);
912912
});
913913

914-
test('preserve bound media query styles when converting to mitosis', () => {
915-
const content = {
916-
data: {
917-
blocks: [
918-
{
919-
'@type': '@builder.io/sdk:Element' as const,
920-
bindings: {
921-
'responsiveStyles.small.left': 'state.left',
922-
'responsiveStyles.small.top': 'state.top',
923-
'responsiveStyles.large.color': 'state.color',
924-
'style.fontSize': 'state.fontSize',
925-
'style.background': '"red"',
926-
'responsiveStyles.large.background': '"green"',
927-
},
928-
},
929-
],
930-
},
931-
};
932-
933-
const mitosis = builderContentToMitosisComponent(content);
934-
expect(mitosis.children[0].bindings).toMatchInlineSnapshot(`
935-
{
936-
"style": {
937-
"bindingType": "expression",
938-
"code": "{ fontSize: state.fontSize, background: \\"red\\", \\"@media (max-width: 640px)\\": { left: state.left, top: state.top }, \\"@media (max-width: 1200px)\\": { color: state.color, background: \\"green\\" }, }",
939-
"type": "single",
940-
},
941-
}
942-
`);
943-
944-
const jsx = componentToMitosis()({ component: mitosis });
945-
expect(jsx).toMatchInlineSnapshot(`
946-
"export default function MyComponent(props) {
947-
return (
948-
<div
949-
style={{
950-
fontSize: state.fontSize,
951-
background: \\"red\\",
952-
\\"@media (max-width: 640px)\\": {
953-
left: state.left,
954-
top: state.top,
955-
},
956-
\\"@media (max-width: 1200px)\\": {
957-
color: state.color,
958-
background: \\"green\\",
959-
},
960-
}}
961-
/>
962-
);
963-
}
964-
"
965-
`);
966-
967-
const json = componentToBuilder()({ component: mitosis });
968-
expect(json).toMatchInlineSnapshot(`
969-
{
970-
"data": {
971-
"blocks": [
972-
{
973-
"@type": "@builder.io/sdk:Element",
974-
"actions": {},
975-
"bindings": {
976-
"responsiveStyles.large.background": "\\"green\\"",
977-
"responsiveStyles.large.color": "state.color",
978-
"responsiveStyles.small.left": "state.left",
979-
"responsiveStyles.small.top": "state.top",
980-
"style.background": "\\"red\\"",
981-
"style.fontSize": "state.fontSize",
982-
},
983-
"children": [],
984-
"code": {
985-
"actions": {},
986-
"bindings": {},
987-
},
988-
"properties": {},
989-
"tagName": "div",
990-
},
991-
],
992-
"jsCode": "",
993-
"tsCode": "",
994-
},
995-
}
996-
`);
997-
});
998-
999914
test('preserve bound call expressions for styles', () => {
1000915
const code = dedent`
1001916
import { useStore } from "@builder.io/mitosis";

packages/core/src/__tests__/builder/responsive-styles.test.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,90 @@ const options = {
99
};
1010

1111
describe('Responsive Styles', () => {
12+
test('preserve bound media query styles when converting to mitosis', () => {
13+
const content = {
14+
data: {
15+
blocks: [
16+
{
17+
'@type': '@builder.io/sdk:Element' as const,
18+
bindings: {
19+
'responsiveStyles.small.left': 'state.left',
20+
'responsiveStyles.small.top': 'state.top',
21+
'responsiveStyles.large.color': 'state.color',
22+
'style.fontSize': 'state.fontSize',
23+
'style.background': '"red"',
24+
'responsiveStyles.large.background': '"green"',
25+
},
26+
},
27+
],
28+
},
29+
};
30+
31+
const mitosis = builderContentToMitosisComponent(content);
32+
expect(mitosis.children[0].bindings).toMatchInlineSnapshot(`
33+
{
34+
"style": {
35+
"bindingType": "expression",
36+
"code": "{ fontSize: state.fontSize, background: \\"red\\", \\"@media (max-width: 640px)\\": { left: state.left, top: state.top }, \\"@media (max-width: 1200px)\\": { color: state.color, background: \\"green\\" }, }",
37+
"type": "single",
38+
},
39+
}
40+
`);
41+
42+
const jsx = componentToMitosis()({ component: mitosis });
43+
expect(jsx).toMatchInlineSnapshot(`
44+
"export default function MyComponent(props) {
45+
return (
46+
<div
47+
style={{
48+
fontSize: state.fontSize,
49+
background: \\"red\\",
50+
\\"@media (max-width: 640px)\\": {
51+
left: state.left,
52+
top: state.top,
53+
},
54+
\\"@media (max-width: 1200px)\\": {
55+
color: state.color,
56+
background: \\"green\\",
57+
},
58+
}}
59+
/>
60+
);
61+
}
62+
"
63+
`);
64+
65+
const json = componentToBuilder()({ component: mitosis });
66+
expect(json).toMatchInlineSnapshot(`
67+
{
68+
"data": {
69+
"blocks": [
70+
{
71+
"@type": "@builder.io/sdk:Element",
72+
"actions": {},
73+
"bindings": {
74+
"responsiveStyles.large.background": "\\"green\\"",
75+
"responsiveStyles.large.color": "state.color",
76+
"responsiveStyles.small.left": "state.left",
77+
"responsiveStyles.small.top": "state.top",
78+
"style.background": "\\"red\\"",
79+
"style.fontSize": "state.fontSize",
80+
},
81+
"children": [],
82+
"code": {
83+
"actions": {},
84+
"bindings": {},
85+
},
86+
"properties": {},
87+
"tagName": "div",
88+
},
89+
],
90+
"jsCode": "",
91+
"tsCode": "",
92+
},
93+
}
94+
`);
95+
});
1296
test('should handle component.options.responsiveStyles correctly', () => {
1397
const block: BuilderElement = {
1498
'@type': '@builder.io/sdk:Element',

0 commit comments

Comments
 (0)