Skip to content

Commit 2e04131

Browse files
committed
add round trip testing
1 parent d4c57b5 commit 2e04131

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

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

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ describe('Symbol Serialization', () => {
21362136
expect(symbolNode.bindings.symbol).toBeDefined();
21372137

21382138
// Verify symbol binding doesn't contain data anymore
2139-
const symbolBinding = JSON.parse(symbolNode.bindings.symbol.code);
2139+
const symbolBinding = JSON.parse(symbolNode.bindings.symbol!.code);
21402140
expect(symbolBinding.data).toBeUndefined();
21412141

21422142
expect(mitosis).toMatchSnapshot();
@@ -2163,13 +2163,22 @@ describe('Symbol Serialization', () => {
21632163
expect(mitosis).toMatchSnapshot();
21642164
});
21652165

2166-
test('Symbol roundtrip: Builder -> Mitosis -> Builder', () => {
2166+
test('Symbol roundtrip: Builder -> Mitosis -> JSX -> Mitosis -> Builder', () => {
21672167
const original = JSON.parse(symbolWithInputs) as BuilderContent;
2168+
2169+
// Step 1: Builder JSON -> Mitosis Component
21682170
const mitosisComponent = builderContentToMitosisComponent(original);
2169-
const backToBuilder = componentToBuilder()({ component: mitosisComponent });
21702171

2171-
// Verify the symbol structure is preserved
2172-
const originalSymbol = original.data?.blocks?.[0];
2172+
// Step 2: Mitosis Component -> Mitosis JSX string (what AI sees)
2173+
const jsxString = componentToMitosis()({ component: mitosisComponent });
2174+
2175+
// Step 3: Mitosis JSX string -> Mitosis Component (after AI edits)
2176+
const parsedComponent = parseJsx(jsxString);
2177+
2178+
// Step 4: Mitosis Component -> Builder JSON
2179+
const backToBuilder = componentToBuilder()({ component: parsedComponent });
2180+
2181+
// Verify the symbol structure is preserved through full roundtrip
21732182
const roundtripSymbol = backToBuilder.data?.blocks?.[0];
21742183

21752184
expect(roundtripSymbol?.component?.name).toBeDefined();
@@ -2183,8 +2192,14 @@ describe('Symbol Serialization', () => {
21832192
const mitosisComponent = builderContentToMitosisComponent(original);
21842193
expect(mitosisComponent.children[0].name).toBe('SymbolButtonComponent');
21852194

2186-
// Step 2: Mitosis -> Builder (should be "Symbol" not "SymbolButtonComponent")
2187-
const backToBuilder = componentToBuilder()({ component: mitosisComponent });
2195+
// Step 2: Mitosis -> JSX string (what AI sees)
2196+
const jsxString = componentToMitosis()({ component: mitosisComponent });
2197+
2198+
// Step 3: JSX string -> Mitosis (after AI edits)
2199+
const parsedComponent = parseJsx(jsxString);
2200+
2201+
// Step 4: Mitosis -> Builder (should be "Symbol" not "SymbolButtonComponent")
2202+
const backToBuilder = componentToBuilder()({ component: parsedComponent });
21882203
const roundtripSymbol = backToBuilder.data?.blocks?.[0];
21892204

21902205
// CRITICAL: Builder Editor requires component.name === "Symbol"
@@ -2227,12 +2242,18 @@ describe('Symbol Serialization', () => {
22272242
},
22282243
};
22292244

2230-
// Builder -> Mitosis: should use symbol.name for component name
2245+
// Step 1: Builder -> Mitosis: should use symbol.name for component name
22312246
const mitosisComponent = builderContentToMitosisComponent(builderWithSymbolName);
22322247
expect(mitosisComponent.children[0].name).toBe('SymbolCopyrightReserved');
22332248

2234-
// Mitosis -> Builder: should preserve name and use "Symbol" as component name
2235-
const backToBuilder = componentToBuilder()({ component: mitosisComponent });
2249+
// Step 2: Mitosis -> JSX string (what AI sees)
2250+
const jsxString = componentToMitosis()({ component: mitosisComponent });
2251+
2252+
// Step 3: JSX string -> Mitosis (after AI edits)
2253+
const parsedComponent = parseJsx(jsxString);
2254+
2255+
// Step 4: Mitosis -> Builder: should preserve name and use "Symbol" as component name
2256+
const backToBuilder = componentToBuilder()({ component: parsedComponent });
22362257
const symbol = backToBuilder.data?.blocks?.[0];
22372258

22382259
expect(symbol?.component?.name).toBe('Symbol');

packages/core/src/generators/builder/generator.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,12 @@ export const blockToBuilder = (
683683
}
684684
}
685685
}
686+
// Also check properties for inputs that became simple string props after JSX roundtrip
687+
for (const key of Object.keys(json.properties)) {
688+
if (!key.startsWith('$') && !key.startsWith('_') && !key.startsWith('data-')) {
689+
inputData[key] = json.properties[key];
690+
}
691+
}
686692
if (Object.keys(inputData).length > 0) {
687693
symbolOptions.data = { ...symbolOptions.data, ...inputData };
688694
}

0 commit comments

Comments
 (0)