Skip to content

Commit 4089986

Browse files
committed
chore(#1): add poc DruxtLayoutBuilder component
1 parent e17bf1d commit 4089986

4 files changed

Lines changed: 114 additions & 109 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<template>
2+
<div class="layout_builder">
3+
<template v-for="(section, index) of sections">
4+
<component
5+
:is="componentIs(section.layout_id)"
6+
v-if="componentIs(section.layout_id) !== 'div'"
7+
:key="index"
8+
:section="section"
9+
>
10+
<template
11+
v-for="component of Object.values(section.components)"
12+
#[component.uuid]
13+
>
14+
<component
15+
:is="componentIs(component.configuration.id)"
16+
v-if="componentIs(component.configuration.id) !== 'div'"
17+
:key="component.uuid"
18+
:component="component"
19+
:entity="entity"
20+
/>
21+
22+
<DruxtDebug
23+
v-else
24+
:key="component.uuid"
25+
:summary="`${componentName(component.configuration.id)} missing`"
26+
>
27+
<pre><code>{{ JSON.stringify(component, null, ' ') }}</code></pre>
28+
</DruxtDebug>
29+
</template>
30+
</component>
31+
32+
<DruxtDebug
33+
v-else
34+
:key="index"
35+
:summary="`${componentName(section.layout_id)} missing`"
36+
>
37+
<pre><code>{{ JSON.stringify(section, null, ' ') }}</code></pre>
38+
</DruxtDebug>
39+
</template>
40+
</div>
41+
</template>
42+
43+
<script>
44+
import { pascalCase, upperFirst } from 'scule'
45+
46+
export default {
47+
name: 'DruxtLayoutBuilder',
48+
49+
props: {
50+
entity: {
51+
type: Object,
52+
required: true,
53+
}
54+
},
55+
56+
computed: {
57+
sections: ({ entity }) => entity.attributes.layout_builder__layout
58+
},
59+
60+
methods: {
61+
componentIs(id) {
62+
const name = this.componentName(id)
63+
return this.$nuxt.$options.components[name] ? name : 'div'
64+
},
65+
66+
componentName(id) {
67+
return `DruxtLayoutBuilder${pascalCase(id.split(':').map((s) => upperFirst(s)).join(''))}`
68+
},
69+
}
70+
}
71+
</script>

src/components/DruxtModuleComponent.vue

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import 'regenerator-runtime/runtime'
2+
import { createLocalVue, mount } from '@vue/test-utils'
3+
4+
import DruxtWrapper from 'druxt/dist/components/DruxtWrapper.vue'
5+
import DruxtLayoutBuilder from '../../src/components/DruxtLayoutBuilder.vue'
6+
7+
// Setup local vue instance.
8+
const localVue = createLocalVue()
9+
localVue.component('DruxtWrapper', DruxtWrapper)
10+
11+
// Mount the Vue component.
12+
const mountComponent = function() {
13+
return mount(
14+
DruxtLayoutBuilder,
15+
{
16+
localVue,
17+
mocks: {
18+
$fetchState: { pending: true },
19+
$route: { meta: { lang: undefined }},
20+
}
21+
}
22+
)
23+
}
24+
25+
describe('DruxtLayoutBuilder', () => {
26+
// test('Hello world', async () => {
27+
// // Mount the component.
28+
// const wrapper = mountComponent()
29+
30+
// // Simulate the Nuxt fetch hook.
31+
// await wrapper.vm.$options.fetch.call(wrapper.vm)
32+
33+
// // Assert data and props are as expected.
34+
// expect(wrapper.vm.foo).toBe('bar')
35+
// expect(wrapper.vm.component).toMatchSnapshot()
36+
37+
// // Assert slots.
38+
// const h = jest.fn()
39+
// const slots = wrapper.vm.$options.druxt.slots(h)
40+
// slots.default()
41+
// expect(h).toBeCalledWith('div', ['Hello world'])
42+
// })
43+
})

test/components/DruxtModuleComponent.test.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)