Skip to content

Commit

Permalink
chore(#1): add poc DruxtLayoutBuilder component
Browse files Browse the repository at this point in the history
  • Loading branch information
Decipher committed Jul 25, 2022
1 parent e17bf1d commit 4089986
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 109 deletions.
71 changes: 71 additions & 0 deletions src/components/DruxtLayoutBuilder.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<template>
<div class="layout_builder">
<template v-for="(section, index) of sections">
<component
:is="componentIs(section.layout_id)"
v-if="componentIs(section.layout_id) !== 'div'"
:key="index"
:section="section"
>
<template
v-for="component of Object.values(section.components)"
#[component.uuid]
>
<component
:is="componentIs(component.configuration.id)"
v-if="componentIs(component.configuration.id) !== 'div'"
:key="component.uuid"
:component="component"
:entity="entity"
/>

<DruxtDebug
v-else
:key="component.uuid"
:summary="`${componentName(component.configuration.id)} missing`"
>
<pre><code>{{ JSON.stringify(component, null, ' ') }}</code></pre>
</DruxtDebug>
</template>
</component>

<DruxtDebug
v-else
:key="index"
:summary="`${componentName(section.layout_id)} missing`"
>
<pre><code>{{ JSON.stringify(section, null, ' ') }}</code></pre>
</DruxtDebug>
</template>
</div>
</template>

<script>
import { pascalCase, upperFirst } from 'scule'
export default {
name: 'DruxtLayoutBuilder',
props: {
entity: {
type: Object,
required: true,
}
},
computed: {
sections: ({ entity }) => entity.attributes.layout_builder__layout
},
methods: {
componentIs(id) {
const name = this.componentName(id)
return this.$nuxt.$options.components[name] ? name : 'div'
},
componentName(id) {
return `DruxtLayoutBuilder${pascalCase(id.split(':').map((s) => upperFirst(s)).join(''))}`
},
}
}
</script>
66 changes: 0 additions & 66 deletions src/components/DruxtModuleComponent.vue

This file was deleted.

43 changes: 43 additions & 0 deletions test/components/DruxtLayoutBuilder.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'regenerator-runtime/runtime'
import { createLocalVue, mount } from '@vue/test-utils'

import DruxtWrapper from 'druxt/dist/components/DruxtWrapper.vue'
import DruxtLayoutBuilder from '../../src/components/DruxtLayoutBuilder.vue'

// Setup local vue instance.
const localVue = createLocalVue()
localVue.component('DruxtWrapper', DruxtWrapper)

// Mount the Vue component.
const mountComponent = function() {
return mount(
DruxtLayoutBuilder,
{
localVue,
mocks: {
$fetchState: { pending: true },
$route: { meta: { lang: undefined }},
}
}
)
}

describe('DruxtLayoutBuilder', () => {
// test('Hello world', async () => {
// // Mount the component.
// const wrapper = mountComponent()

// // Simulate the Nuxt fetch hook.
// await wrapper.vm.$options.fetch.call(wrapper.vm)

// // Assert data and props are as expected.
// expect(wrapper.vm.foo).toBe('bar')
// expect(wrapper.vm.component).toMatchSnapshot()

// // Assert slots.
// const h = jest.fn()
// const slots = wrapper.vm.$options.druxt.slots(h)
// slots.default()
// expect(h).toBeCalledWith('div', ['Hello world'])
// })
})
43 changes: 0 additions & 43 deletions test/components/DruxtModuleComponent.test.js

This file was deleted.

0 comments on commit 4089986

Please sign in to comment.