From 6b9297668f13403ec8bcd50b5225527e12022398 Mon Sep 17 00:00:00 2001 From: Korey Kassir Date: Thu, 16 Jan 2025 14:45:21 -0800 Subject: [PATCH] change test format --- .../__snapshots__/builder.test.ts.snap | 308 +++++++++--------- packages/core/src/__tests__/builder.test.ts | 17 +- 2 files changed, 166 insertions(+), 159 deletions(-) diff --git a/packages/core/src/__tests__/__snapshots__/builder.test.ts.snap b/packages/core/src/__tests__/__snapshots__/builder.test.ts.snap index 3c54c85a46..4697ed22ef 100644 --- a/packages/core/src/__tests__/__snapshots__/builder.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/builder.test.ts.snap @@ -4187,6 +4187,158 @@ export default function MyComponent(props) { `; exports[`Builder > localization 3`] = ` +{ + "data": { + "blocks": [ + { + "@type": "@builder.io/sdk:Element", + "actions": {}, + "bindings": {}, + "children": [ + { + "@type": "@builder.io/sdk:Element", + "bindings": {}, + "component": { + "name": "Text", + "options": { + "text": "

Time left: {{state.timeLeft}} seconds

", + }, + }, + "tagName": "span", + }, + ], + "code": { + "actions": {}, + "bindings": {}, + }, + "properties": {}, + "tagName": "div", + }, + { + "@type": "@builder.io/sdk:Element", + "actions": {}, + "bindings": {}, + "children": [ + { + "@type": "@builder.io/sdk:Element", + "bindings": {}, + "component": { + "name": "Text", + "options": { + "text": { + "@type": "@builder.io/core:LocalizedValue", + "Default": "

hello default

", + "es-AR": "

hello argentina

", + "fr-CA": "

hello france


", + }, + }, + }, + "tagName": "span", + }, + ], + "code": { + "actions": {}, + "bindings": {}, + }, + "properties": {}, + "tagName": "div", + }, + { + "@type": "@builder.io/sdk:Element", + "actions": {}, + "bindings": {}, + "children": [], + "code": { + "actions": {}, + "bindings": {}, + }, + "component": { + "name": "Image", + "options": { + "image": { + "@type": "@builder.io/core:LocalizedValue", + "Default": "https://cdn.builder.io/api/v1/image/placeholder?default", + "es-AR": "https://cdn.builder.io/api/v1/image/placeholder?es-ar", + "fr-CA": "https://cdn.builder.io/api/v1/image/placeholder?fr-ca", + }, + }, + }, + }, + { + "@type": "@builder.io/sdk:Element", + "actions": {}, + "bindings": {}, + "children": [], + "code": { + "actions": {}, + "bindings": {}, + }, + "component": { + "name": "CustomComponent", + "options": { + "title": { + "@type": "@builder.io/core:LocalizedValue", + "Default": "

hello default

", + "es-AR": "

hello argentina

", + "fr-CA": "

hello france


", + }, + }, + }, + }, + { + "@type": "@builder.io/sdk:Element", + "actions": {}, + "bindings": { + "component.options.scriptsClientOnly": "false", + }, + "children": [], + "code": { + "actions": {}, + "bindings": { + "component.options.scriptsClientOnly": "false", + }, + }, + "component": { + "name": "Custom Code", + "options": { + "builderTag": "a", + "code": "Link +", + "href": "http://builder.io", + "scriptsClientOnly": false, + }, + }, + "linkUrl": { + "@type": "@builder.io/core:LocalizedValue", + "Default": "http://builder.io", + }, + "properties": { + "href": { + "@type": "@builder.io/core:LocalizedValue", + "Default": "http://builder.io", + }, + }, + "responsiveStyles": { + "large": { + "boxSizing": "border-box", + "cursor": "pointer", + "display": "flex", + "flexDirection": "column", + "flexShrink": "0", + "marginTop": "20px", + "pointerEvents": "auto", + "position": "relative", + }, + }, + }, + ], + "jsCode": "", + "tsCode": "", + }, +} +`; + +exports[`Builder > localization preserve text blocks 1`] = ` { "@type": "@builder.io/mitosis/component", "children": [ @@ -4353,7 +4505,7 @@ exports[`Builder > localization 3`] = ` } `; -exports[`Builder > localization 4`] = ` +exports[`Builder > localization preserve text blocks 2`] = ` "import { Image, CustomComponent, CustomCode } from \\"@components\\"; export default function MyComponent(props) { @@ -4394,159 +4546,7 @@ export default function MyComponent(props) { " `; -exports[`Builder > localization 5`] = ` -{ - "data": { - "blocks": [ - { - "@type": "@builder.io/sdk:Element", - "actions": {}, - "bindings": {}, - "children": [ - { - "@type": "@builder.io/sdk:Element", - "bindings": {}, - "component": { - "name": "Text", - "options": { - "text": "

Time left: {{state.timeLeft}} seconds

", - }, - }, - "tagName": "span", - }, - ], - "code": { - "actions": {}, - "bindings": {}, - }, - "properties": {}, - "tagName": "div", - }, - { - "@type": "@builder.io/sdk:Element", - "actions": {}, - "bindings": {}, - "children": [ - { - "@type": "@builder.io/sdk:Element", - "bindings": {}, - "component": { - "name": "Text", - "options": { - "text": { - "@type": "@builder.io/core:LocalizedValue", - "Default": "

hello default

", - "es-AR": "

hello argentina

", - "fr-CA": "

hello france


", - }, - }, - }, - "tagName": "span", - }, - ], - "code": { - "actions": {}, - "bindings": {}, - }, - "properties": {}, - "tagName": "div", - }, - { - "@type": "@builder.io/sdk:Element", - "actions": {}, - "bindings": {}, - "children": [], - "code": { - "actions": {}, - "bindings": {}, - }, - "component": { - "name": "Image", - "options": { - "image": { - "@type": "@builder.io/core:LocalizedValue", - "Default": "https://cdn.builder.io/api/v1/image/placeholder?default", - "es-AR": "https://cdn.builder.io/api/v1/image/placeholder?es-ar", - "fr-CA": "https://cdn.builder.io/api/v1/image/placeholder?fr-ca", - }, - }, - }, - }, - { - "@type": "@builder.io/sdk:Element", - "actions": {}, - "bindings": {}, - "children": [], - "code": { - "actions": {}, - "bindings": {}, - }, - "component": { - "name": "CustomComponent", - "options": { - "title": { - "@type": "@builder.io/core:LocalizedValue", - "Default": "

hello default

", - "es-AR": "

hello argentina

", - "fr-CA": "

hello france


", - }, - }, - }, - }, - { - "@type": "@builder.io/sdk:Element", - "actions": {}, - "bindings": { - "component.options.scriptsClientOnly": "false", - }, - "children": [], - "code": { - "actions": {}, - "bindings": { - "component.options.scriptsClientOnly": "false", - }, - }, - "component": { - "name": "Custom Code", - "options": { - "builderTag": "a", - "code": "Link -", - "href": "http://builder.io", - "scriptsClientOnly": false, - }, - }, - "linkUrl": { - "@type": "@builder.io/core:LocalizedValue", - "Default": "http://builder.io", - }, - "properties": { - "href": { - "@type": "@builder.io/core:LocalizedValue", - "Default": "http://builder.io", - }, - }, - "responsiveStyles": { - "large": { - "boxSizing": "border-box", - "cursor": "pointer", - "display": "flex", - "flexDirection": "column", - "flexShrink": "0", - "marginTop": "20px", - "pointerEvents": "auto", - "position": "relative", - }, - }, - }, - ], - "jsCode": "", - "tsCode": "", - }, -} -`; - -exports[`Builder > localization 6`] = ` +exports[`Builder > localization preserve text blocks 3`] = ` { "data": { "blocks": [ diff --git a/packages/core/src/__tests__/builder.test.ts b/packages/core/src/__tests__/builder.test.ts index 8af02935bb..aba97725a2 100644 --- a/packages/core/src/__tests__/builder.test.ts +++ b/packages/core/src/__tests__/builder.test.ts @@ -477,23 +477,30 @@ describe('Builder', () => { test('localization', () => { const originalBuilder = JSON.parse(localization); const component = builderContentToMitosisComponent(originalBuilder); + const mitosisJsx = componentToMitosis()({ component }); + expect(component).toMatchSnapshot(); + expect(mitosisJsx).toMatchSnapshot(); + + const backToBuilder = componentToBuilder()({ component }); + expect(backToBuilder).toMatchSnapshot(); + }); + + test('localization preserve text blocks', () => { + const originalBuilder = JSON.parse(localization); const componentPreserveTextBlocks = builderContentToMitosisComponent(originalBuilder, { preserveTextBlocks: true, }); - const mitosisJsx = componentToMitosis()({ component }); const mitosisJsxPreserveTextBlocks = componentToMitosis()({ component: componentPreserveTextBlocks, }); - expect(component).toMatchSnapshot(); - expect(mitosisJsx).toMatchSnapshot(); + expect(componentPreserveTextBlocks).toMatchSnapshot(); expect(mitosisJsxPreserveTextBlocks).toMatchSnapshot(); - const backToBuilder = componentToBuilder()({ component }); const backToBuilderPreserveTextBlocks = componentToBuilder()({ component: componentPreserveTextBlocks, }); - expect(backToBuilder).toMatchSnapshot(); + expect(backToBuilderPreserveTextBlocks).toMatchSnapshot(); });