Vue component editor
', + handlerVue: 'return {}', + renderVarHtml: null, + ignoreMustache: true, + }, + inspector: [ + { + type: 'FormInput', + field: 'componentName', + config: { + label: 'Component Name', + helper: 'Name of the component', + }, + }, + { + type: EditorFieldInspector, + field: 'templateVue', + config: { + rows: 5, + label: 'Template Vue', + helper: 'The template vue component to display', + value: 'Vue component editor
', + language: 'html', + enablePopup: true, + openPopupLabel: 'Open in popup', + popupTitle: 'Edit template', + cancelPopupLabel: 'Cancel', + savePopupLabel: 'Save', + }, + }, + { + type: EditorFieldInspector, + field: 'handlerVue', + config: { + label: 'Handler Vue', + helper: 'The code vue component to display', + value: 'return {}', + language: 'javascript', + enablePopup: true, + openPopupLabel: 'Open in popup', + popupTitle: 'Edit script', + cancelPopupLabel: 'Cancel', + savePopupLabel: 'Save', + }, + }, + ], + }, +}; + export default [ { editorComponent: FormHtmlEditor, @@ -1292,5 +1358,6 @@ export default [ }, inspector: [], } - } + }, + VueComponentEditorConfig ]; diff --git a/src/stories/VueRender.stories.js b/src/stories/VueRender.stories.js new file mode 100644 index 000000000..569e4adfd --- /dev/null +++ b/src/stories/VueRender.stories.js @@ -0,0 +1,274 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import { expect, within, userEvent } from '@storybook/test'; +import '../bootstrap'; +import VueRenderTemplate from '../components/renderer/vueRender/VueRenderTemplate'; +import VueRenderEditor from '../components/renderer/vueRender/VueRenderEditor.vue'; +import VueRenderPreview from '../components/renderer/vueRender/VueRenderPreview.vue'; + +const defaultHandler = 'return {}'; + +export default { + title: 'Components/VueRender', + tags: ['autodocs'], + parameters: { + layout: 'padded', + }, +}; + +export const TemplateWithCustomMarkup = { + name: 'VueRenderTemplate / custom template', + render: () => ({ + components: { VueRenderTemplate }, + template: ` +Hello from templateVue
', + handlerVue: defaultHandler, + }; + }, + }), + play: async ({ canvasElement }) => { + const canvas = within(canvasElement); + await expect(canvas.getByTestId('vue-render-message')).toHaveTextContent('Hello from templateVue'); + }, +}; + +export const TemplateWithHandlerMethod = { + name: 'VueRenderTemplate / handlerVue methods', + render: () => ({ + components: { VueRenderTemplate }, + template: ` +Editor preview
', + handlerVue: defaultHandler, + validationData: { sample: 1 }, + }; + }, + }), + play: async ({ canvasElement }) => { + const canvas = within(canvasElement); + const root = canvas.getByTestId('vue-render-editor-root'); + await expect(root.querySelector('.form-group.pointer-events-none')).toBeTruthy(); + await expect(canvas.getByTestId('vue-render-editor-content')).toHaveTextContent('Editor preview'); + }, +}; + +export const EditorWithValidationError = { + name: 'VueRenderEditor / error state', + render: () => ({ + components: { VueRenderEditor }, + template: ` +Preview content
', + handlerVue: defaultHandler, + validationData: { field1: 'value' }, + }; + }, + }), + play: async ({ canvasElement }) => { + const canvas = within(canvasElement); + await expect(canvas.getByTestId('vue-render-preview-content')).toHaveTextContent('Preview content'); + }, +}; + +export const PreviewWithError = { + name: 'VueRenderPreview / error', + render: () => ({ + components: { VueRenderPreview }, + template: ` +